Skip to content

Commit f3e286e

Browse files
committed
SDK-1458: Add support for multiple documents
1 parent c98bf4c commit f3e286e

33 files changed

Lines changed: 914 additions & 17 deletions

yoti_python_sdk/doc_scan/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from yoti_python_sdk.http import SignedRequest
1616
from yoti_python_sdk.utils import YotiEncoder
1717
from .exception import DocScanException
18+
from .support import SupportedDocumentsResponse
1819

1920

2021
class DocScanClient(object):
@@ -169,3 +170,26 @@ def delete_media_content(self, session_id, media_id):
169170
response = request.execute()
170171
if response.status_code < 200 or response.status_code >= 300:
171172
raise DocScanException("Failed to delete media content", response)
173+
174+
def get_supported_documents(self):
175+
"""
176+
Retrieves a list of all of the currently supported documents
177+
178+
:return: the supported documents response
179+
:rtype: SupportedDocumentsResponse
180+
"""
181+
request = (
182+
SignedRequest.builder()
183+
.with_http_method("GET")
184+
.with_pem_file(self.__key)
185+
.with_base_url(self.__api_url)
186+
.with_endpoint(Endpoint.get_supported_documents_path())
187+
.build()
188+
)
189+
190+
response = request.execute()
191+
if response.status_code < 200 or response.status_code >= 300:
192+
raise DocScanException("Failed to retrieve supported documents", response)
193+
194+
parsed = json.loads(response.text)
195+
return SupportedDocumentsResponse(parsed)

yoti_python_sdk/doc_scan/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
CHECK_COMPLETION = "CHECK_COMPLETION"
1717
SESSION_COMPLETION = "SESSION_COMPLETION"
1818

19+
ID_DOCUMENT = "ID_DOCUMENT"
20+
ORTHOGONAL_RESTRICTIONS = "ORTHOGONAL_RESTRICTIONS"
21+
DOCUMENT_RESTRICTIONS = "DOCUMENT_RESTRICTIONS"
22+
INCLUSION_WHITELIST = "WHITELIST"
23+
INCLUSION_BLACKLIST = "BLACKLIST"
24+
1925
ALWAYS = "ALWAYS"
2026
FALLBACK = "FALLBACK"
2127
NEVER = "NEVER"

yoti_python_sdk/doc_scan/endpoint.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ def get_media_content_path(session_id, media_id):
2020
@staticmethod
2121
def delete_media_path(session_id, media_id):
2222
return Endpoint.get_media_content_path(session_id, media_id)
23+
24+
@staticmethod
25+
def get_supported_documents_path():
26+
return "/supported-documents"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from .document_restrictions_filter import (
2+
DocumentRestrictionBuilder,
3+
DocumentRestrictionsFilterBuilder,
4+
)
5+
from .orthogonal_restrictions_filter import OrthogonalRestrictionsFilterBuilder
6+
from .required_id_document import RequiredIdDocumentBuilder
7+
8+
__all__ = [
9+
DocumentRestrictionsFilterBuilder,
10+
DocumentRestrictionBuilder,
11+
OrthogonalRestrictionsFilterBuilder,
12+
RequiredIdDocumentBuilder,
13+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from abc import ABCMeta
2+
3+
from yoti_python_sdk.utils import YotiSerializable
4+
5+
6+
class DocumentFilter(YotiSerializable):
7+
__metaclass__ = ABCMeta
8+
9+
def __init__(self, filter_type):
10+
self.__filter_type = filter_type
11+
12+
@property
13+
def type(self):
14+
return self.__filter_type
15+
16+
def to_json(self):
17+
return {"type": self.type}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
from yoti_python_sdk.doc_scan.constants import (
2+
DOCUMENT_RESTRICTIONS,
3+
INCLUSION_BLACKLIST,
4+
INCLUSION_WHITELIST,
5+
)
6+
from yoti_python_sdk.utils import YotiSerializable
7+
from .document_filter import DocumentFilter
8+
9+
10+
class DocumentRestriction(YotiSerializable):
11+
def __init__(self, country_codes, document_types):
12+
self.__country_codes = country_codes
13+
self.__document_types = document_types
14+
15+
@property
16+
def country_codes(self):
17+
return self.__country_codes
18+
19+
@property
20+
def document_types(self):
21+
return self.__document_types
22+
23+
def to_json(self):
24+
return {
25+
"country_codes": self.country_codes,
26+
"document_types": self.document_types,
27+
}
28+
29+
30+
class DocumentRestrictionBuilder(object):
31+
def __init__(self):
32+
self.__country_codes = None
33+
self.__document_types = None
34+
35+
def with_country_codes(self, country_codes):
36+
"""
37+
Sets the list of country codes on the document restriction
38+
39+
:param country_codes: the list of country codes
40+
:type country_codes: list[str]
41+
:return: the builder
42+
:rtype: DocumentRestrictionBuilder
43+
"""
44+
self.__country_codes = country_codes
45+
return self
46+
47+
def with_document_types(self, document_types):
48+
"""
49+
Sets the list of document types on the document restriction
50+
51+
:param document_types: the list of document types
52+
:type document_types: list[str]
53+
:return: the builder
54+
:rtype: DocumentRestrictionBuilder
55+
"""
56+
self.__document_types = document_types
57+
return self
58+
59+
def build(self):
60+
"""
61+
Builds the document restriction using the values supplied to the builder
62+
63+
:return: the document restriction
64+
:rtype: DocumentRestriction
65+
"""
66+
return DocumentRestriction(self.__country_codes, self.__document_types)
67+
68+
69+
class DocumentRestrictionsFilter(DocumentFilter):
70+
def __init__(self, inclusion, documents):
71+
DocumentFilter.__init__(self, DOCUMENT_RESTRICTIONS)
72+
73+
self.__inclusion = inclusion
74+
self.__documents = documents
75+
76+
@property
77+
def inclusion(self):
78+
return self.__inclusion
79+
80+
@property
81+
def documents(self):
82+
return self.__documents
83+
84+
def to_json(self):
85+
parent = DocumentFilter.to_json(self)
86+
parent["inclusion"] = self.inclusion
87+
parent["documents"] = self.documents
88+
return parent
89+
90+
91+
class DocumentRestrictionsFilterBuilder(object):
92+
"""
93+
Builder used to create a document restrictions filter.
94+
95+
Example::
96+
97+
document_restriction = (DocumentRestrictionBuilder()
98+
.with_country_codes("GBR", "USA")
99+
.with_document_types("PASSPORT")
100+
.build())
101+
102+
filter = (DocumentRestrictionsFilterBuilder()
103+
.for_whitelist()
104+
.with_document_restriction(document_restriction)
105+
.build())
106+
"""
107+
108+
def __init__(self):
109+
self.__inclusion = None
110+
self.__documents = None
111+
112+
def for_whitelist(self):
113+
"""
114+
Sets the inclusion to whitelist the document restrictions
115+
116+
:return: the builder
117+
:rtype: DocumentRestrictionsFilterBuilder
118+
"""
119+
self.__inclusion = INCLUSION_WHITELIST
120+
return self
121+
122+
def for_blacklist(self):
123+
"""
124+
Sets the inclusion to blacklist the document restrictions
125+
126+
:return: the builder
127+
:rtype: DocumentRestrictionsFilterBuilder
128+
"""
129+
self.__inclusion = INCLUSION_BLACKLIST
130+
return self
131+
132+
def with_document_restriction(self, document_restriction):
133+
"""
134+
Adds a document restriction to the filter
135+
136+
:param document_restriction: the document restriction
137+
:type document_restriction: DocumentRestriction
138+
:return: the builder
139+
:rtype: DocumentRestrictionsFilterBuilder
140+
"""
141+
if self.__documents is None:
142+
self.__documents = []
143+
144+
self.__documents.append(document_restriction)
145+
return self
146+
147+
def build(self):
148+
"""
149+
Builds the document restrictions filter, using the supplied values
150+
151+
:return: the filter
152+
:rtype: DocumentRestrictionsFilter
153+
"""
154+
return DocumentRestrictionsFilter(self.__inclusion, self.__documents)

0 commit comments

Comments
 (0)