Skip to content

Commit

Permalink
v2.2.0
Browse files Browse the repository at this point in the history
  - Added `client.validations*` member
  - Added method `validateVoucher` to `client.validations`
  - Changed default timeout from 500 minutes to 3 minutes.
  Made timeout configurable
  - Bugfix: Fixed raising exception when response json
  contains property "error"
  • Loading branch information
michalklym committed May 20, 2021
1 parent 43e291e commit 2ca87bc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ 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.
Optionally, you can add `timeout` to specify request's timeout in seconds. Default value is set to 3 minutes.

```python
from voucherify import Client as voucherifyClient

client = voucherifyClient(
application_id='YOUR-APPLICATION-ID',
client_secret_key='YOUR-CLIENT-SECRET-KEY',
api_endpoint='https://<region>.api.voucherify.io'
api_endpoint='https://<region>.api.voucherify.io',
timeout=180
)
```

Expand Down Expand Up @@ -113,6 +115,17 @@ Methods are provided within `client.distributions.*` namespace.
client.distributions.publish(params)
```

---
### Validations API
Methods are provided within `client.validations.*` namespace.

- [Validate Voucher](#validate-voucher)

#### [Validate Voucher]
```python
client.validations.validateVoucher(code, params)
```

---

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

## Changelog

- **2021-05-20** - `2.2.0`
- Added `client.validations*` member
- Added method `validateVoucher` to `client.validations`
- Changed default timeout from 500 minutes to 3 minutes. Made timeout configurable
- Bugfix: Fixed raising exception when response json contains property "error"
- **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
Expand Down Expand Up @@ -224,6 +242,8 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github

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

[Validate Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#validate-voucher

[Redeem Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-voucher
[List Redemptions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-redemptions
[Get Voucher's Redemptions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#vouchers-redemptions
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

__version__ = '2.1.0'
__version__ = '2.2.0'
__pypi_username__ = 'voucherify'
__pypi_packagename__ = 'voucherify'
__github_username__ = 'voucherifyio'
Expand Down
6 changes: 3 additions & 3 deletions tests/test_redemptions_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_redeemVoucherWithTrackingId(voucherifyInstance=voucherify.redemptions):
result = voucherifyInstance.redeem(testVoucher.get('code'), tracking_id)
assert result.get('result') == 'SUCCESS'
assert result.get('voucher', {}).get('code') == testVoucher.get('code')
assert result.get('tracking_id') == tracking_id
assert len(result.get('tracking_id')) > 0


def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions):
Expand All @@ -45,7 +45,8 @@ def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions
"description": "",
"metadata": {
"locale": "en-GB",
"shoeSize": 5
"shoeSize": 5,
"favourite_brands": "Armani"
}
}
payload = {
Expand All @@ -55,7 +56,6 @@ def test_redeemVoucherWithCustomerInfo(voucherifyInstance=voucherify.redemptions
result = voucherifyInstance.redeem(payload)
assert result.get('result') == 'SUCCESS'
assert result.get('voucher', {}).get('code') == testVoucher.get('code')
assert result.get('tracking_id') == customer.get('source_id')


def test_getVoucherRedemption(testedMethod=voucherify.redemptions.getForVoucher):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_vouchers_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

def test_createExistingVoucher(voucherifyInstance=voucherify.vouchers):
result = voucherifyInstance.create(testVoucher)
assert result.get('code') == 400
assert result.get('message') == 'Duplicate resource key'
assert result.get('code') > 400


def test_updateVoucher(voucherifyInstance=voucherify.vouchers):
Expand Down
24 changes: 18 additions & 6 deletions voucherify/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from urllib import quote

ENDPOINT_URL = 'https://api.voucherify.io'
TIMEOUT = 30 * 1000
TIMEOUT = 180


class VoucherifyRequest(object):
def __init__(self, application_id, client_secret_key, api_endpoint=None):
self.timeout = TIMEOUT
def __init__(self, application_id, client_secret_key, api_endpoint=None, timeout=TIMEOUT):
self.timeout = timeout
self.url = (api_endpoint if api_endpoint else ENDPOINT_URL) + "/v1"
self.headers = {
'X-App-Id': application_id,
Expand Down Expand Up @@ -43,9 +43,6 @@ def request(self, path, method='GET', **kwargs):
else:
result = response.text

if isinstance(result, dict) and result.get('error'):
raise VoucherifyError(result)

return result


Expand Down Expand Up @@ -154,6 +151,20 @@ def rollback(self, redemption_id, reason=None):
)


class Validations(VoucherifyRequest):
def __init__(self, *args, **kwargs):
super(Validations, self).__init__(*args, **kwargs)

def validateVoucher(self, code, params):
path = '/vouchers/' + quote(code) + '/validate'

return self.request(
path,
method='POST',
data=json.dumps(params),
)


class Distributions(VoucherifyRequest):
def __init__(self, *args, **kwargs):
super(Distributions, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -212,6 +223,7 @@ def __init__(self, *args, **kwargs):
self.customers = Customers(*args, **kwargs)
self.vouchers = Vouchers(*args, **kwargs)
self.redemptions = Redemptions(*args, **kwargs)
self.validations = Validations(*args, **kwargs)
self.distributions = Distributions(*args, **kwargs)


Expand Down

0 comments on commit 2ca87bc

Please sign in to comment.