Skip to content

Commit f69f10c

Browse files
author
Jakub Reczko
committed
Improved quality of examples
1 parent e83379d commit f69f10c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

examples/voucherify_test.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
tracking_id = "PythonTestUser"
1515
voucher = {
16-
"code": "PythonTestVoucher",
16+
"code": "PythonVoucherTest",
1717
"discount": {
1818
"type": "AMOUNT",
1919
"amount_off": 12436
@@ -66,14 +66,15 @@
6666
Enable Voucher
6767
"""
6868
pprint.pprint("=== Enable Voucher ===")
69-
result = voucherify.disable(voucher["code"])
69+
result = voucherify.enable(voucher["code"])
7070
pprint.pprint(result)
7171

7272
"""
7373
Redeem Voucher
7474
"""
7575
pprint.pprint("=== Redeem Voucher ===")
7676
result = voucherify.redeem(voucher["code"])
77+
redemption_id = result['id']
7778
pprint.pprint(result)
7879

7980
pprint.pprint("=== Redeem Voucher with Tracking ID ===")
@@ -124,19 +125,26 @@
124125
Rollback Voucher
125126
"""
126127
pprint.pprint("=== Rollback Redemption ===")
127-
pprint.pprint(result)
128-
redemption_id = ""
129128
rollback_reason = "Wrong Customer"
130129
result = voucherify.rollback(redemption_id, rollback_reason)
131130
pprint.pprint(result)
132131

133132
"""
134133
Publish Voucher
135134
"""
136-
pprint.pprint("=== Publish Campaign ===")
135+
pprint.pprint("=== Publish Campaign with Campaign Name ===")
137136
result = voucherify.publish("PythonTestCampaignName")
138137
pprint.pprint(result)
139138

139+
pprint.pprint("=== Publish Campaign with Campaign Details ===")
140+
payload = {
141+
"campaign": "PythonTestCampaignName",
142+
"channel": "Email",
143+
"customer": "[email protected]"
144+
}
145+
result = voucherify.publish(payload)
146+
pprint.pprint(result)
147+
140148
"""
141149
Utils
142150
"""

voucherify/client.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import requests
22
import json
3-
import pprint
43

54
try:
65
from urllib.parse import urlencode, quote
@@ -142,8 +141,13 @@ def rollback(self, redemption_id, reason=None):
142141
method='POST'
143142
)
144143

145-
def publish(self, campaign_name):
146-
path = '/vouchers/publish?' + urlencode({'campaign': campaign_name})
144+
def publish(self, campaign_name=""):
145+
path = '/vouchers/publish'
146+
147+
if campaign_name and isinstance(campaign_name, dict):
148+
path = path + '?' + urlencode(campaign_name)
149+
else:
150+
path = path + '?' + urlencode({'campaign': campaign_name})
147151

148152
return self.request(
149153
path,

0 commit comments

Comments
 (0)