Skip to content

Commit 57e5e69

Browse files
committed
Make response more user friendly and abstract
1 parent d057fda commit 57e5e69

34 files changed

+42
-34
lines changed

iyzipay/iyzipay_resource.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import warnings
88

99
import iyzipay
10-
10+
from iyzipay.iyzipay_response import IyzipayResponse
1111

1212
class IyzipayResource:
1313
def __init__(self):
@@ -31,7 +31,12 @@ def connect(self, method, url, options, request=None, pki=None):
3131
connection = http.client.HTTPSConnection(options['base_url'])
3232
request_json = json.dumps(request)
3333
connection.request(method, url, request_json, self.get_http_header(options, pki))
34-
return connection.getresponse()
34+
response = connection.getresponse()
35+
try:
36+
body = json.loads(response.read().decode('utf-8'))
37+
except:
38+
body = None
39+
return IyzipayResponse(response.status, body)
3540

3641
def get_http_header(self, options=None, pki_string=None):
3742
header = {"Accept": "application/json", "Content-type": "application/json"}

iyzipay/iyzipay_response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from collections import namedtuple
2+
3+
IyzipayResponse = namedtuple('IyzipayResponse', ('status', 'body'))

samples/api_test.py

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

99
api_test = iyzipay.ApiTest().retrieve(options)
1010

11-
print(api_test.read().decode('utf-8'))
11+
print(api_test.body)

samples/approve.py

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

1717
approval = iyzipay.Approval().create(request, options)
1818

19-
print(approval.read().decode('utf-8'))
19+
print(approval.body)

samples/cancel.py

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

2020
cancel = iyzipay.Cancel().create(request, options)
2121

22-
print(cancel.read().decode('utf-8'))
22+
print(cancel.body)

samples/create_card.py

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

2626
card = iyzipay.Card().create(request, options)
2727

28-
print(card.read().decode('utf-8'))
28+
print(card.body)

samples/create_limited_company_sub_merchant.py

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

2727
sub_merchant = iyzipay.SubMerchant().create(request, options)
2828

29-
print(sub_merchant.read().decode('utf-8'))
29+
print(sub_merchant.body)

samples/create_marketplace_payment.py

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

9494
payment = iyzipay.Payment().create(request, options)
9595

96-
print(payment.read().decode('utf-8'))
96+
print(payment.body)

samples/create_payment.py

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

8888
payment = iyzipay.Payment().create(request, options)
8989

90-
print(payment.read().decode('utf-8'))
90+
print(payment.body)

samples/create_payment_with_registered_card.py

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

8484
payment = iyzipay.Payment().create(request, options)
8585

86-
print(payment.read().decode('utf-8'))
86+
print(payment.body)

0 commit comments

Comments
 (0)