Skip to content

Commit de533ce

Browse files
committed
SDK-1076: Implement YotiResponse to standardise the response object used in the SDK:
1 parent 725a2a4 commit de533ce

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

yoti_python_sdk/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from yoti_python_sdk.activity_details import ActivityDetails
1010
from yoti_python_sdk.crypto import Crypto
1111
from yoti_python_sdk.endpoint import Endpoint
12-
from yoti_python_sdk.http import SignedRequest
12+
from yoti_python_sdk.http import SignedRequest, YotiResponse
1313
from yoti_python_sdk.protobuf import protobuf
1414

1515
NO_KEY_FILE_SPECIFIED_ERROR = (
@@ -53,6 +53,10 @@ def make_request(self, http_method, endpoint, body):
5353
)
5454

5555
response = signed_request.execute()
56+
57+
if not isinstance(response, YotiResponse):
58+
raise TypeError("Response must be of type YotiResponse")
59+
5660
return response
5761

5862
def get_activity_details(self, encrypted_request_token):
@@ -94,6 +98,9 @@ def perform_aml_check(self, aml_profile):
9498

9599
response = self.__make_aml_check_request(aml_profile)
96100

101+
if not isinstance(response, YotiResponse):
102+
raise TypeError("Response must be of type YotiResponse")
103+
97104
return aml.AmlResult(response.text)
98105

99106
@property
@@ -161,6 +168,8 @@ def __make_aml_check_request(self, aml_profile):
161168
)
162169

163170
response = signed_request.execute()
171+
if not isinstance(response, YotiResponse):
172+
raise TypeError("Response must be of type YotiResponse")
164173

165174
self.http_error_handler(
166175
response, {"default": "Unsuccessful Yoti API call: {} {}"}

yoti_python_sdk/http.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@
2525
HTTP_SUPPORTED_METHODS = ["POST", "PUT", "PATCH", "GET", "DELETE"]
2626

2727

28+
class YotiResponse(object):
29+
def __init__(self, status_code, text):
30+
self.status_code = status_code
31+
self.text = text
32+
33+
2834
class RequestHandler:
2935
"""
3036
Default request handler for signing requests using the requests library.
3137
This type can be inherited and the execute method overridden to use any
32-
preferred HTTP library.
38+
preferred HTTP library. Must return type YotiResponse for use in the SDK.
3339
"""
3440

3541
__metaclass__ = ABCMeta # Python 2 compatability
@@ -49,13 +55,15 @@ def execute(request):
4955
if not isinstance(request, SignedRequest):
5056
raise TypeError("RequestHandler expects instance of SignedRequest")
5157

52-
return requests.request(
58+
response = requests.request(
5359
url=request.url,
5460
method=request.method,
5561
data=request.data,
5662
headers=request.headers,
5763
)
5864

65+
return YotiResponse(status_code=response.status_code, text=response.text)
66+
5967

6068
class SignedRequest(object):
6169
def __init__(self, url, http_method, payload, headers, request_handler=None):

0 commit comments

Comments
 (0)