Skip to content

Commit 7d8deb4

Browse files
authored
Merge pull request #34 from voucherifyio/aw/unify-set-endpoint
Add support for custom API Endpoint
2 parents e271a8c + 4dd5b25 commit 7d8deb4

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ client = voucherifyClient(
4343
)
4444
```
4545

46+
### API Endpoint
47+
48+
Optionally, you can add `api_endpoint` to the client options if you want to use Voucherify running in a specific region.
49+
50+
```python
51+
from voucherify import Client as voucherifyClient
52+
53+
client = voucherifyClient(
54+
application_id='YOUR-APPLICATION-ID',
55+
client_secret_key='YOUR-CLIENT-SECRET-KEY',
56+
api_endpoint='https://<region>.api.voucherify.io'
57+
)
58+
```
59+
4660
## API
4761

4862
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
179193

180194
## Changelog
181195

196+
- **2019-06-19** - `2.1.0` Added support for custom API endpoint, that allows to connect to projects created in specific Voucherify region.
182197
- **2018-01-20** - `2.0.0`
183198
- Moved vouchers related methods to `client.vouchers.*` namespace
184199
- Moved redemptions related methods to `client.redemptions.*` namespace

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'voucherify'))
66

7-
__version__ = '2.0.0'
7+
__version__ = '2.1.0'
88
__pypi_username__ = 'voucherify'
99
__pypi_packagename__ = 'voucherify'
1010
__github_username__ = 'voucherifyio'

voucherify/client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
from urllib import urlencode
88
from urllib import quote
99

10-
ENDPOINT_URL = 'https://api.voucherify.io/v1'
10+
ENDPOINT_URL = 'https://api.voucherify.io'
1111
TIMEOUT = 30 * 1000
1212

1313

1414
class VoucherifyRequest(object):
15-
def __init__(self, application_id, client_secret_key):
15+
def __init__(self, application_id, client_secret_key, api_endpoint=None):
1616
self.timeout = TIMEOUT
17+
self.url = (api_endpoint if api_endpoint else ENDPOINT_URL) + "/v1"
1718
self.headers = {
1819
'X-App-Id': application_id,
1920
'X-App-Token': client_secret_key,
@@ -23,7 +24,7 @@ def __init__(self, application_id, client_secret_key):
2324

2425
def request(self, path, method='GET', **kwargs):
2526
try:
26-
url = ENDPOINT_URL + path
27+
url = self.url + path
2728

2829
response = requests.request(
2930
method=method,
@@ -76,7 +77,7 @@ def create(self, voucher):
7677
data=json.dumps(voucher),
7778
method='POST'
7879
)
79-
80+
8081
def update(self, voucher_update):
8182
path = '/vouchers/' + quote(voucher_update.get("code"))
8283

@@ -140,7 +141,7 @@ def list(self, query):
140141
path,
141142
params=query
142143
)
143-
144+
144145
def rollback(self, redemption_id, reason=None):
145146
path = '/redemptions/' + redemption_id + '/rollback'
146147

0 commit comments

Comments
 (0)