-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from getyoti/release-2.11.0
Release 2.11.0
- Loading branch information
Showing
88 changed files
with
4,529 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ requests>=2.20.0 | |
urllib3>=1.24.2 | ||
deprecated==1.2.6 | ||
wheel==0.24.0 | ||
iso8601==0.1.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from .session.create.check.document_authenticity import ( | ||
RequestedDocumentAuthenticityCheckBuilder, | ||
) | ||
from .session.create.check.face_match import RequestedFaceMatchCheckBuilder | ||
from .session.create.check.liveness import RequestedLivenessCheckBuilder | ||
from .session.create.task.text_extraction import RequestedTextExtractionTaskBuilder | ||
from .session.create.notification_config import NotificationConfigBuilder | ||
from .session.create.sdk_config import SdkConfigBuilder | ||
from .session.create.session_spec import SessionSpecBuilder | ||
from .client import DocScanClient | ||
|
||
__all__ = [ | ||
RequestedDocumentAuthenticityCheckBuilder, | ||
RequestedLivenessCheckBuilder, | ||
RequestedFaceMatchCheckBuilder, | ||
RequestedTextExtractionTaskBuilder, | ||
SessionSpecBuilder, | ||
NotificationConfigBuilder, | ||
SdkConfigBuilder, | ||
DocScanClient, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import json | ||
|
||
import yoti_python_sdk | ||
from yoti_python_sdk.doc_scan.endpoint import Endpoint | ||
from yoti_python_sdk.doc_scan.session.retrieve.create_session_result import ( | ||
CreateSessionResult, | ||
) | ||
from yoti_python_sdk.doc_scan.session.retrieve.get_session_result import ( | ||
GetSessionResult, | ||
) | ||
from yoti_python_sdk.doc_scan.session.retrieve.media_value import MediaValue | ||
from yoti_python_sdk.http import SignedRequest | ||
from yoti_python_sdk.utils import YotiEncoder | ||
from .exception import DocScanException | ||
|
||
|
||
class DocScanClient(object): | ||
""" | ||
Client used for communication with the Yoti Doc Scan service where any | ||
signed request is required | ||
""" | ||
|
||
def __init__(self, sdk_id, key, api_url=None): | ||
self.__sdk_id = sdk_id | ||
self.__key = key | ||
if api_url is not None: | ||
self.__api_url = api_url | ||
else: | ||
self.__api_url = yoti_python_sdk.YOTI_DOC_SCAN_ENDPOINT | ||
|
||
def create_session(self, session_spec): | ||
""" | ||
Creates a Doc Scan session using the supplied session specification | ||
:param session_spec: the session specification | ||
:type session_spec: SessionSpec | ||
:return: the create session result | ||
:rtype: CreateSessionResult | ||
:raises DocScanException: if there was an error creating the session | ||
""" | ||
payload = json.dumps(session_spec, cls=YotiEncoder).encode("utf-8") | ||
|
||
request = ( | ||
SignedRequest.builder() | ||
.with_post() | ||
.with_pem_file(self.__key) | ||
.with_base_url(self.__api_url) | ||
.with_endpoint(Endpoint.create_docs_session_path()) | ||
.with_param("sdkId", self.__sdk_id) | ||
.with_payload(payload) | ||
.with_header("Content-Type", "application/json") | ||
.build() | ||
) | ||
response = request.execute() | ||
|
||
if response.status_code != 201: | ||
raise DocScanException("Failed to create session", response) | ||
|
||
data = json.loads(response.text) | ||
return CreateSessionResult(data) | ||
|
||
def get_session(self, session_id): | ||
""" | ||
Retrieves the state of a previously created Yoti Doc Scan session | ||
:param session_id: the session ID | ||
:type session_id: str | ||
:return: the session state | ||
:rtype: GetSessionResult | ||
:raises DocScanException: if there was an error retrieving the session | ||
""" | ||
request = ( | ||
SignedRequest.builder() | ||
.with_get() | ||
.with_pem_file(self.__key) | ||
.with_base_url(self.__api_url) | ||
.with_endpoint(Endpoint.retrieve_docs_session_path(session_id)) | ||
.with_param("sdkId", self.__sdk_id) | ||
.build() | ||
) | ||
response = request.execute() | ||
|
||
if response.status_code != 200: | ||
raise DocScanException("Failed to retrieve session", response) | ||
|
||
data = json.loads(response.text) | ||
return GetSessionResult(data) | ||
|
||
def delete_session(self, session_id): | ||
""" | ||
Deletes a previously created Yoti Doc Scan session and | ||
all of its related resources | ||
:param session_id: the session id to delete | ||
:type session_id: str | ||
:rtype: None | ||
:raises DocScanException: if there was an error deleting the session | ||
""" | ||
request = ( | ||
SignedRequest.builder() | ||
.with_http_method("DELETE") | ||
.with_pem_file(self.__key) | ||
.with_base_url(self.__api_url) | ||
.with_endpoint(Endpoint.delete_docs_session_path(session_id)) | ||
.with_param("sdkId", self.__sdk_id) | ||
.build() | ||
) | ||
response = request.execute() | ||
|
||
if response.status_code < 200 or response.status_code >= 300: | ||
raise DocScanException("Failed to delete session", response) | ||
|
||
def get_media_content(self, session_id, media_id): | ||
""" | ||
Retrieves media related to a Yoti Doc Scan session | ||
based on the supplied media ID | ||
:param session_id: the session ID | ||
:type session_id: str | ||
:param media_id: the media ID | ||
:type media_id: str | ||
:return: the media | ||
:rtype: MediaValue | ||
:raises DocScanException: if there was an error retrieving the media content | ||
""" | ||
request = ( | ||
SignedRequest.builder() | ||
.with_get() | ||
.with_pem_file(self.__key) | ||
.with_base_url(self.__api_url) | ||
.with_endpoint(Endpoint.get_media_content_path(session_id, media_id)) | ||
.with_param("sdkId", self.__sdk_id) | ||
.build() | ||
) | ||
response = request.execute() | ||
|
||
if response.status_code != 200: | ||
raise DocScanException("Failed to retrieve media content", response) | ||
|
||
media_mime_type = response.headers["Content-Type"] | ||
media_content = response.content | ||
return MediaValue(media_mime_type, media_content) | ||
|
||
def delete_media_content(self, session_id, media_id): | ||
""" | ||
Deletes media related to a Yoti Doc Scan session | ||
based on the supplied media ID | ||
:param session_id: the session ID | ||
:type session_id: str | ||
:param media_id: the media ID | ||
:type media_id: str | ||
:rtype: None | ||
:raises DocScanException: if there was an error deleting the media content | ||
""" | ||
request = ( | ||
SignedRequest.builder() | ||
.with_http_method("DELETE") | ||
.with_pem_file(self.__key) | ||
.with_base_url(self.__api_url) | ||
.with_endpoint(Endpoint.delete_media_path(session_id, media_id)) | ||
.with_param("sdkId", self.__sdk_id) | ||
.build() | ||
) | ||
|
||
response = request.execute() | ||
if response.status_code < 200 or response.status_code >= 300: | ||
raise DocScanException("Failed to delete media content", response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
ID_DOCUMENT_AUTHENTICITY = "ID_DOCUMENT_AUTHENTICITY" | ||
ID_DOCUMENT_TEXT_DATA_CHECK = "ID_DOCUMENT_TEXT_DATA_CHECK" | ||
ID_DOCUMENT_TEXT_DATA_EXTRACTION = "ID_DOCUMENT_TEXT_DATA_EXTRACTION" | ||
ID_DOCUMENT_FACE_MATCH = "ID_DOCUMENT_FACE_MATCH" | ||
LIVENESS = "LIVENESS" | ||
ZOOM = "ZOOM" | ||
|
||
CAMERA = "CAMERA" | ||
CAMERA_AND_UPLOAD = "CAMERA_AND_UPLOAD" | ||
|
||
RESOURCE_UPDATE = "RESOURCE_UPDATE" | ||
TASK_COMPLETION = "TASK_COMPLETION" | ||
CHECK_COMPLETION = "CHECK_COMPLETION" | ||
SESSION_COMPLETION = "SESSION_COMPLETION" | ||
|
||
ALWAYS = "ALWAYS" | ||
FALLBACK = "FALLBACK" | ||
NEVER = "NEVER" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Endpoint(object): | ||
@staticmethod | ||
def create_docs_session_path(): | ||
return "/sessions" | ||
|
||
@staticmethod | ||
def retrieve_docs_session_path(session_id): | ||
return "/sessions/{sessionId}".format(sessionId=session_id) | ||
|
||
@staticmethod | ||
def delete_docs_session_path(session_id): | ||
return Endpoint.retrieve_docs_session_path(session_id) | ||
|
||
@staticmethod | ||
def get_media_content_path(session_id, media_id): | ||
return "/sessions/{sessionId}/media/{mediaId}/content".format( | ||
sessionId=session_id, mediaId=media_id | ||
) | ||
|
||
@staticmethod | ||
def delete_media_path(session_id, media_id): | ||
return Endpoint.get_media_content_path(session_id, media_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .doc_scan_exception import DocScanException | ||
|
||
__all__ = [DocScanException] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class DocScanException(Exception): | ||
""" | ||
Exception thrown by the Yoti Doc Scan client | ||
when an error has occurred when communicating with the API | ||
""" | ||
|
||
def __init__(self, message, response): | ||
""" | ||
:param message: the exception message | ||
:type message: str | ||
:param response: the http response | ||
:type response: requests.Response | ||
""" | ||
Exception.__init__(self) | ||
|
||
self.__message = message | ||
self.__response = response | ||
|
||
@property | ||
def message(self): | ||
""" | ||
Get the specific exception message | ||
:return: the exception message | ||
:rtype: str | ||
""" | ||
return self.__message | ||
|
||
@property | ||
def status_code(self): | ||
""" | ||
Get the status code of the HTTP response | ||
:return: the status code | ||
:rtype: int or None | ||
""" | ||
return self.__response.status_code | ||
|
||
@property | ||
def text(self): | ||
""" | ||
Return the HTTP response body as text | ||
:return: the body as text | ||
:rtype: str | ||
""" | ||
return self.__response.text | ||
|
||
@property | ||
def content(self): | ||
""" | ||
Return the HTTP response body as bytes | ||
:return: the body as bytes | ||
:rtype: bytearray or None | ||
""" | ||
return self.__response.content | ||
|
||
def __str__(self): | ||
return self.__message |
Empty file.
Oops, something went wrong.