Skip to content

Commit 6c39f5b

Browse files
committed
SDK-1299: Remove MediaReponse, add content property to YotiResponse containing raw bytes from response
1 parent 261ffb7 commit 6c39f5b

4 files changed

Lines changed: 7 additions & 28 deletions

File tree

yoti_python_sdk/doc_scan/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
GetSessionResult,
1313
)
1414
from yoti_python_sdk.doc_scan.session.retrieve.media_value import MediaValue
15-
from yoti_python_sdk.http import MediaRequestHandler
1615
from yoti_python_sdk.http import SignedRequest
1716
from yoti_python_sdk.utils import YotiEncoder
1817
from .exception import DocScanException
@@ -129,7 +128,6 @@ def get_media_content(self, session_id, media_id):
129128
"""
130129
request = (
131130
SignedRequest.builder()
132-
.with_request_handler(MediaRequestHandler)
133131
.with_get()
134132
.with_pem_file(self.__key)
135133
.with_base_url(self.__api_url)

yoti_python_sdk/http.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424

2525

2626
class YotiResponse(object):
27-
def __init__(self, status_code, text, headers=None):
27+
def __init__(self, status_code, text, headers=None, content=None):
2828
if headers is None:
2929
headers = {}
3030

3131
self.status_code = status_code
3232
self.text = text
33+
self.content = content
3334
self.headers = headers
3435

3536

@@ -89,27 +90,10 @@ def execute(request):
8990
status_code=response.status_code,
9091
text=response.text,
9192
headers=response.headers,
93+
content=response.content,
9294
)
9395

9496

95-
class MediaRequestHandler(RequestHandler):
96-
@staticmethod
97-
def execute(request):
98-
"""
99-
Execute the HTTP request supplied
100-
"""
101-
if not isinstance(request, SignedRequest):
102-
raise TypeError("RequestHandler expects instance of SignedRequest")
103-
104-
response = requests.request(
105-
url=request.url,
106-
method=request.method,
107-
data=request.data,
108-
headers=request.headers,
109-
)
110-
return MediaResponse(response)
111-
112-
11397
class SignedRequest(object):
11498
def __init__(self, url, http_method, payload, headers, request_handler=None):
11599
self.__url = url

yoti_python_sdk/tests/doc_scan/mocks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def mocked_request_failed_session_retrieval():
3232
def mocked_request_media_content():
3333
return MockResponse(
3434
status_code=200,
35-
text=b"someContent",
35+
text="someContent",
36+
content=b"someContent",
3637
headers={"Content-Type": "application/json"},
3738
)
3839

yoti_python_sdk/tests/mocks.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77

88

99
class MockResponse(YotiResponse):
10-
def __init__(self, status_code, text, headers=None):
10+
def __init__(self, status_code, text, headers=None, content=None):
1111
if headers is None:
1212
headers = dict()
1313

14-
super(MockResponse, self).__init__(status_code, text, headers)
15-
16-
@property
17-
def content(self):
18-
return self.text
14+
super(MockResponse, self).__init__(status_code, text, headers, content)
1915

2016

2117
class MockRequestHandler(RequestHandler):

0 commit comments

Comments
 (0)