From 4dd5b25c7e4520a20ad6429d3d68ad5074d8bd8c Mon Sep 17 00:00:00 2001 From: awilczek Date: Thu, 13 Jun 2019 17:26:07 +0200 Subject: [PATCH] Unify setEndpoint in SDKs --- README.md | 15 +++++++++++++++ setup.py | 2 +- voucherify/client.py | 11 ++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b0ec591f..86d0739d 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,20 @@ client = voucherifyClient( ) ``` +### API Endpoint + +Optionally, you can add `api_endpoint` to the client options if you want to use Voucherify running in a specific region. + +```python +from voucherify import Client as voucherifyClient + +client = voucherifyClient( + application_id='YOUR-APPLICATION-ID', + client_secret_key='YOUR-CLIENT-SECRET-KEY', + api_endpoint='https://.api.voucherify.io' +) +``` + ## API This SDK is consistent with restful API Voucherify provides. @@ -179,6 +193,7 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github ## Changelog +- **2019-06-19** - `2.1.0` Added support for custom API endpoint, that allows to connect to projects created in specific Voucherify region. - **2018-01-20** - `2.0.0` - Moved vouchers related methods to `client.vouchers.*` namespace - Moved redemptions related methods to `client.redemptions.*` namespace diff --git a/setup.py b/setup.py index 973071d3..4d546e9d 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'voucherify')) -__version__ = '2.0.0' +__version__ = '2.1.0' __pypi_username__ = 'voucherify' __pypi_packagename__ = 'voucherify' __github_username__ = 'voucherifyio' diff --git a/voucherify/client.py b/voucherify/client.py index a2dc8625..fc4de2f3 100644 --- a/voucherify/client.py +++ b/voucherify/client.py @@ -7,13 +7,14 @@ from urllib import urlencode from urllib import quote -ENDPOINT_URL = 'https://api.voucherify.io/v1' +ENDPOINT_URL = 'https://api.voucherify.io' TIMEOUT = 30 * 1000 class VoucherifyRequest(object): - def __init__(self, application_id, client_secret_key): + def __init__(self, application_id, client_secret_key, api_endpoint=None): self.timeout = TIMEOUT + self.url = (api_endpoint if api_endpoint else ENDPOINT_URL) + "/v1" self.headers = { 'X-App-Id': application_id, 'X-App-Token': client_secret_key, @@ -23,7 +24,7 @@ def __init__(self, application_id, client_secret_key): def request(self, path, method='GET', **kwargs): try: - url = ENDPOINT_URL + path + url = self.url + path response = requests.request( method=method, @@ -76,7 +77,7 @@ def create(self, voucher): data=json.dumps(voucher), method='POST' ) - + def update(self, voucher_update): path = '/vouchers/' + quote(voucher_update.get("code")) @@ -140,7 +141,7 @@ def list(self, query): path, params=query ) - + def rollback(self, redemption_id, reason=None): path = '/redemptions/' + redemption_id + '/rollback'