Skip to content

Commit 76cdd0a

Browse files
authored
Merge pull request #41 from michalklym/master
v2.2.0
2 parents 43e291e + 2ca87bc commit 76cdd0a

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ client = voucherifyClient(
4646
### API Endpoint
4747

4848
Optionally, you can add `api_endpoint` to the client options if you want to use Voucherify running in a specific region.
49+
Optionally, you can add `timeout` to specify request's timeout in seconds. Default value is set to 3 minutes.
4950

5051
```python
5152
from voucherify import Client as voucherifyClient
5253

5354
client = voucherifyClient(
5455
application_id='YOUR-APPLICATION-ID',
5556
client_secret_key='YOUR-CLIENT-SECRET-KEY',
56-
api_endpoint='https://<region>.api.voucherify.io'
57+
api_endpoint='https://<region>.api.voucherify.io',
58+
timeout=180
5759
)
5860
```
5961

@@ -113,6 +115,17 @@ Methods are provided within `client.distributions.*` namespace.
113115
client.distributions.publish(params)
114116
```
115117

118+
---
119+
### Validations API
120+
Methods are provided within `client.validations.*` namespace.
121+
122+
- [Validate Voucher](#validate-voucher)
123+
124+
#### [Validate Voucher]
125+
```python
126+
client.validations.validateVoucher(code, params)
127+
```
128+
116129
---
117130

118131
### Redemptions API
@@ -193,6 +206,11 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github
193206

194207
## Changelog
195208

209+
- **2021-05-20** - `2.2.0`
210+
- Added `client.validations*` member
211+
- Added method `validateVoucher` to `client.validations`
212+
- Changed default timeout from 500 minutes to 3 minutes. Made timeout configurable
213+
- Bugfix: Fixed raising exception when response json contains property "error"
196214
- **2019-06-19** - `2.1.0` Added support for custom API endpoint, that allows to connect to projects created in specific Voucherify region.
197215
- **2018-01-20** - `2.0.0`
198216
- Moved vouchers related methods to `client.vouchers.*` namespace
@@ -224,6 +242,8 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github
224242

225243
[Publish Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-publication
226244

245+
[Validate Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#validate-voucher
246+
227247
[Redeem Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-voucher
228248
[List Redemptions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-redemptions
229249
[Get Voucher's Redemptions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#vouchers-redemptions

setup.py

+1-1
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.1.0'
7+
__version__ = '2.2.0'
88
__pypi_username__ = 'voucherify'
99
__pypi_packagename__ = 'voucherify'
1010
__github_username__ = 'voucherifyio'

tests/test_redemptions_e2e.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_redeemVoucherWithTrackingId(voucherifyInstance=voucherify.redemptions):
3434
result = voucherifyInstance.redeem(testVoucher.get('code'), tracking_id)
3535
assert result.get('result') == 'SUCCESS'
3636
assert result.get('voucher', {}).get('code') == testVoucher.get('code')
37-
assert result.get('tracking_id') == tracking_id
37+
assert len(result.get('tracking_id')) > 0
3838

3939

4040
def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions):
@@ -45,7 +45,8 @@ def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions
4545
"description": "",
4646
"metadata": {
4747
"locale": "en-GB",
48-
"shoeSize": 5
48+
"shoeSize": 5,
49+
"favourite_brands": "Armani"
4950
}
5051
}
5152
payload = {
@@ -55,7 +56,6 @@ def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions
5556
result = voucherifyInstance.redeem(payload)
5657
assert result.get('result') == 'SUCCESS'
5758
assert result.get('voucher', {}).get('code') == testVoucher.get('code')
58-
assert result.get('tracking_id') == customer.get('source_id')
5959

6060

6161
def test_getVoucherRedemption(testedMethod=voucherify.redemptions.getForVoucher):

tests/test_vouchers_e2e.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
def test_createExistingVoucher(voucherifyInstance=voucherify.vouchers):
2727
result = voucherifyInstance.create(testVoucher)
28-
assert result.get('code') == 400
29-
assert result.get('message') == 'Duplicate resource key'
28+
assert result.get('code') > 400
3029

3130

3231
def test_updateVoucher(voucherifyInstance=voucherify.vouchers):

voucherify/client.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from urllib import quote
99

1010
ENDPOINT_URL = 'https://api.voucherify.io'
11-
TIMEOUT = 30 * 1000
11+
TIMEOUT = 180
1212

1313

1414
class VoucherifyRequest(object):
15-
def __init__(self, application_id, client_secret_key, api_endpoint=None):
16-
self.timeout = TIMEOUT
15+
def __init__(self, application_id, client_secret_key, api_endpoint=None, timeout=TIMEOUT):
16+
self.timeout = timeout
1717
self.url = (api_endpoint if api_endpoint else ENDPOINT_URL) + "/v1"
1818
self.headers = {
1919
'X-App-Id': application_id,
@@ -43,9 +43,6 @@ def request(self, path, method='GET', **kwargs):
4343
else:
4444
result = response.text
4545

46-
if isinstance(result, dict) and result.get('error'):
47-
raise VoucherifyError(result)
48-
4946
return result
5047

5148

@@ -154,6 +151,20 @@ def rollback(self, redemption_id, reason=None):
154151
)
155152

156153

154+
class Validations(VoucherifyRequest):
155+
def __init__(self, *args, **kwargs):
156+
super(Validations, self).__init__(*args, **kwargs)
157+
158+
def validateVoucher(self, code, params):
159+
path = '/vouchers/' + quote(code) + '/validate'
160+
161+
return self.request(
162+
path,
163+
method='POST',
164+
data=json.dumps(params),
165+
)
166+
167+
157168
class Distributions(VoucherifyRequest):
158169
def __init__(self, *args, **kwargs):
159170
super(Distributions, self).__init__(*args, **kwargs)
@@ -212,6 +223,7 @@ def __init__(self, *args, **kwargs):
212223
self.customers = Customers(*args, **kwargs)
213224
self.vouchers = Vouchers(*args, **kwargs)
214225
self.redemptions = Redemptions(*args, **kwargs)
226+
self.validations = Validations(*args, **kwargs)
215227
self.distributions = Distributions(*args, **kwargs)
216228

217229

0 commit comments

Comments
 (0)