Skip to content

Commit 3245d14

Browse files
authored
DEVEXP-464 update verification API with backwards compat (#36)
1 parent f054a88 commit 3245d14

9 files changed

+470
-83
lines changed

sinch/domains/verification/__init__.py

+175-26
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,40 @@
55
from sinch.domains.verification.endpoints.report_verification_using_id import (
66
ReportVerificationByIdEndpoint
77
)
8-
from sinch.domains.verification.endpoints.get_verification_by_id import (
9-
GetVerificationStatusByIdEndpoint
10-
)
118
from sinch.domains.verification.endpoints.get_verification_by_identity import (
129
GetVerificationStatusByIdentityEndpoint
1310
)
1411
from sinch.domains.verification.endpoints.get_verification_by_reference import (
1512
GetVerificationStatusByReferenceEndpoint
1613
)
14+
from sinch.domains.verification.endpoints.get_verification_by_id import (
15+
GetVerificationStatusByIdEndpoint
16+
)
1717
from sinch.domains.verification.models.responses import (
1818
StartVerificationResponse,
1919
ReportVerificationByIdentityResponse,
2020
ReportVerificationByIdResponse,
2121
GetVerificationStatusByIdentityResponse,
22-
GetVerificationStatusByIdResponse,
23-
GetVerificationStatusByReferenceResponse
22+
GetVerificationStatusByReferenceResponse,
23+
GetVerificationStatusByIdResponse
2424
)
2525
from sinch.domains.verification.models.requests import (
2626
StartSMSVerificationRequest,
2727
StartFlashCallVerificationRequest,
28+
StartPhoneCallVerificationRequest,
2829
StartCalloutVerificationRequest,
29-
StartSeamlessVerificationRequest,
30-
ReportVerificationByIdentityRequest,
31-
ReportVerificationByIdRequest,
32-
GetVerificationStatusByIdRequest,
30+
StartDataVerificationRequest,
31+
ReportVerificationByIdentityRequestLegacy,
32+
ReportVerificationByIdRequestLegacy,
33+
ReportVerificationByIdentityAndSMSRequest,
34+
ReportVerificationByIdentityAndFlashCallRequest,
35+
ReportVerificationByIdentityAndPhoneCallRequest,
36+
ReportVerificationByIdAndSMSRequest,
37+
ReportVerificationByIdAndFlashCallRequest,
38+
ReportVerificationByIdAndPhoneCallRequest,
3339
GetVerificationStatusByIdentityRequest,
34-
GetVerificationStatusByReferenceRequest
40+
GetVerificationStatusByReferenceRequest,
41+
GetVerificationStatusByIdRequest
3542
)
3643
from sinch.domains.verification.models import VerificationIdentity
3744

@@ -66,16 +73,32 @@ def start_flash_call(
6673
self,
6774
identity: VerificationIdentity,
6875
reference: str = None,
69-
custom: str = None,
70-
dial_timeout: int = None
76+
dial_timeout: int = None,
77+
custom: str = None
7178
) -> StartVerificationResponse:
7279
return self._sinch.configuration.transport.request(
7380
StartVerificationEndpoint(
7481
request_data=StartFlashCallVerificationRequest(
7582
identity=identity,
7683
reference=reference,
77-
custom=custom,
78-
dial_timeout=dial_timeout
84+
dial_timeout=dial_timeout,
85+
custom=custom
86+
)
87+
)
88+
)
89+
90+
def start_phone_call(
91+
self,
92+
identity: VerificationIdentity,
93+
reference: str = None,
94+
custom: str = None
95+
) -> StartVerificationResponse:
96+
return self._sinch.configuration.transport.request(
97+
StartVerificationEndpoint(
98+
request_data=StartPhoneCallVerificationRequest(
99+
identity=identity,
100+
reference=reference,
101+
custom=custom
79102
)
80103
)
81104
)
@@ -87,6 +110,11 @@ def start_callout(
87110
custom: str = None,
88111
speech_locale: str = None
89112
) -> StartVerificationResponse:
113+
"""
114+
This method is not supported anymore.
115+
It should be used only for backward compatibility reasons.
116+
Use start_phone_call method instead.
117+
"""
90118
return self._sinch.configuration.transport.request(
91119
StartVerificationEndpoint(
92120
request_data=StartCalloutVerificationRequest(
@@ -103,25 +131,138 @@ def start_seamless(
103131
identity: VerificationIdentity,
104132
reference: str = None,
105133
custom: str = None
134+
) -> StartVerificationResponse:
135+
"""
136+
This method is not supported anymore.
137+
It should be used only for backward compatibility reasons.
138+
Use start_data method instead.
139+
"""
140+
return self._sinch.configuration.transport.request(
141+
StartVerificationEndpoint(
142+
request_data=StartDataVerificationRequest(
143+
identity=identity,
144+
reference=reference,
145+
custom=custom
146+
)
147+
)
148+
)
149+
150+
def start_data(
151+
self,
152+
identity: VerificationIdentity,
153+
reference: str = None,
154+
custom: str = None
106155
) -> StartVerificationResponse:
107156
return self._sinch.configuration.transport.request(
108157
StartVerificationEndpoint(
109-
request_data=StartSeamlessVerificationRequest(
158+
request_data=StartDataVerificationRequest(
110159
identity=identity,
111160
reference=reference,
112161
custom=custom
113162
)
114163
)
115164
)
116165

166+
def report_sms_by_id(
167+
self,
168+
id: str,
169+
code: str,
170+
cli: str = None
171+
) -> ReportVerificationByIdResponse:
172+
return self._sinch.configuration.transport.request(
173+
ReportVerificationByIdEndpoint(
174+
request_data=ReportVerificationByIdAndSMSRequest(
175+
id,
176+
code,
177+
cli
178+
)
179+
)
180+
)
181+
182+
def report_flash_call_by_id(
183+
self,
184+
id: str,
185+
cli: str
186+
) -> ReportVerificationByIdResponse:
187+
return self._sinch.configuration.transport.request(
188+
ReportVerificationByIdEndpoint(
189+
request_data=ReportVerificationByIdAndFlashCallRequest(
190+
id,
191+
cli
192+
)
193+
)
194+
)
195+
196+
def report_phone_call_by_id(
197+
self,
198+
id: str,
199+
code: str = None
200+
) -> ReportVerificationByIdResponse:
201+
return self._sinch.configuration.transport.request(
202+
ReportVerificationByIdEndpoint(
203+
request_data=ReportVerificationByIdAndPhoneCallRequest(
204+
id,
205+
code
206+
)
207+
)
208+
)
209+
210+
def report_sms_by_identity(
211+
self,
212+
endpoint: str,
213+
code: str,
214+
cli: str = None
215+
) -> ReportVerificationByIdentityResponse:
216+
return self._sinch.configuration.transport.request(
217+
ReportVerificationByIdentityEndpoint(
218+
request_data=ReportVerificationByIdentityAndSMSRequest(
219+
endpoint,
220+
code,
221+
cli
222+
)
223+
)
224+
)
225+
226+
def report_flash_call_by_identity(
227+
self,
228+
endpoint: str,
229+
cli: str = None
230+
) -> ReportVerificationByIdentityResponse:
231+
return self._sinch.configuration.transport.request(
232+
ReportVerificationByIdentityEndpoint(
233+
request_data=ReportVerificationByIdentityAndFlashCallRequest(
234+
endpoint,
235+
cli
236+
)
237+
)
238+
)
239+
240+
def report_phone_call_by_identity(
241+
self,
242+
endpoint: str,
243+
code: str
244+
) -> ReportVerificationByIdentityResponse:
245+
return self._sinch.configuration.transport.request(
246+
ReportVerificationByIdentityEndpoint(
247+
request_data=ReportVerificationByIdentityAndPhoneCallRequest(
248+
endpoint,
249+
code
250+
)
251+
)
252+
)
253+
117254
def report_by_id(
118255
self,
119256
id: str,
120257
verification_report_request: dict
121258
) -> ReportVerificationByIdResponse:
259+
"""
260+
This method is not supported anymore.
261+
It should be used only for backward compatibility reasons.
262+
"""
122263
return self._sinch.configuration.transport.request(
123264
ReportVerificationByIdEndpoint(
124-
request_data=ReportVerificationByIdRequest(
265+
request_data=ReportVerificationByIdRequestLegacy(
125266
id,
126267
verification_report_request
127268
)
@@ -133,9 +274,13 @@ def report_by_identity(
133274
endpoint,
134275
verification_report_request
135276
) -> ReportVerificationByIdentityResponse:
277+
"""
278+
This method is not supported anymore.
279+
It should be used only for backward compatibility reasons.
280+
"""
136281
return self._sinch.configuration.transport.request(
137282
ReportVerificationByIdentityEndpoint(
138-
request_data=ReportVerificationByIdentityRequest(
283+
request_data=ReportVerificationByIdentityRequestLegacy(
139284
endpoint,
140285
verification_report_request
141286
)
@@ -147,25 +292,29 @@ class VerificationStatus:
147292
def __init__(self, sinch):
148293
self._sinch = sinch
149294

150-
def get_by_reference(self, reference) -> GetVerificationStatusByReferenceResponse:
295+
def get_by_id(self, id: str) -> GetVerificationStatusByIdResponse:
151296
return self._sinch.configuration.transport.request(
152-
GetVerificationStatusByReferenceEndpoint(
153-
request_data=GetVerificationStatusByReferenceRequest(
154-
reference=reference
297+
GetVerificationStatusByIdEndpoint(
298+
request_data=GetVerificationStatusByIdRequest(
299+
id=id
155300
)
156301
)
157302
)
158303

159-
def get_by_id(self, id) -> GetVerificationStatusByIdResponse:
304+
def get_by_reference(self, reference: str) -> GetVerificationStatusByReferenceResponse:
160305
return self._sinch.configuration.transport.request(
161-
GetVerificationStatusByIdEndpoint(
162-
request_data=GetVerificationStatusByIdRequest(
163-
id=id
306+
GetVerificationStatusByReferenceEndpoint(
307+
request_data=GetVerificationStatusByReferenceRequest(
308+
reference=reference
164309
)
165310
)
166311
)
167312

168-
def get_by_identity(self, endpoint, method) -> GetVerificationStatusByIdentityResponse:
313+
def get_by_identity(
314+
self,
315+
endpoint: str,
316+
method: str
317+
) -> GetVerificationStatusByIdentityResponse:
169318
return self._sinch.configuration.transport.request(
170319
GetVerificationStatusByIdentityEndpoint(
171320
request_data=GetVerificationStatusByIdentityRequest(

sinch/domains/verification/endpoints/report_verification_using_id.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
from sinch.core.models.http_response import HTTPResponse
32
from sinch.domains.verification.endpoints.verification_endpoint import VerificationEndpoint
43
from sinch.core.enums import HTTPAuthentication, HTTPMethods
@@ -21,7 +20,7 @@ def build_url(self, sinch):
2120
)
2221

2322
def request_body(self):
24-
return json.dumps(self.request_data.verification_report_request)
23+
return self.request_data.as_json()
2524

2625
def handle_response(self, response: HTTPResponse) -> ReportVerificationByIdResponse:
2726
super().handle_response(response)

sinch/domains/verification/endpoints/report_verification_using_identity.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
from sinch.core.models.http_response import HTTPResponse
32
from sinch.domains.verification.endpoints.verification_endpoint import VerificationEndpoint
43
from sinch.core.enums import HTTPAuthentication, HTTPMethods
@@ -21,7 +20,7 @@ def build_url(self, sinch):
2120
)
2221

2322
def request_body(self):
24-
return json.dumps(self.request_data.verification_report_request)
23+
return self.request_data.as_json()
2524

2625
def handle_response(self, response: HTTPResponse) -> ReportVerificationByIdentityResponse:
2726
super().handle_response(response)

sinch/domains/verification/endpoints/start_verification.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
SMSResponse,
99
DataResponse,
1010
StartVerificationResponse,
11-
StartSMSInitiateVerificationResponse,
12-
StartDataInitiateVerificationResponse,
13-
StartCalloutInitiateVerificationResponse,
14-
StartFlashCallInitiateVerificationResponse
11+
StartSMSVerificationResponse,
12+
StartDataVerificationResponse,
13+
StartPhoneCallVerificationResponse,
14+
StartFlashCallVerificationResponse
1515
)
1616

1717

@@ -35,7 +35,7 @@ def handle_response(self, response: HTTPResponse) -> StartVerificationResponse:
3535
super().handle_response(response)
3636
if self.request_data.method == VerificationMethod.SMS.value:
3737
sms_response = response.body.get("sms")
38-
return StartSMSInitiateVerificationResponse(
38+
return StartSMSVerificationResponse(
3939
id=response.body.get("id"),
4040
method=response.body.get("method"),
4141
_links=response.body.get("_links"),
@@ -46,7 +46,7 @@ def handle_response(self, response: HTTPResponse) -> StartVerificationResponse:
4646
)
4747
elif self.request_data.method == VerificationMethod.FLASH_CALL.value:
4848
flash_call_response = response.body.get("flashCall")
49-
return StartFlashCallInitiateVerificationResponse(
49+
return StartFlashCallVerificationResponse(
5050
id=response.body.get("id"),
5151
method=response.body.get("method"),
5252
_links=response.body.get("_links"),
@@ -58,14 +58,14 @@ def handle_response(self, response: HTTPResponse) -> StartVerificationResponse:
5858
) if flash_call_response else None
5959
)
6060
elif self.request_data.method == VerificationMethod.CALLOUT.value:
61-
return StartCalloutInitiateVerificationResponse(
61+
return StartPhoneCallVerificationResponse(
6262
id=response.body.get("id"),
6363
method=response.body.get("method"),
6464
_links=response.body.get("_links")
6565
)
6666
elif self.request_data.method == VerificationMethod.SEAMLESS.value:
6767
seamless_response = response.body.get("seamless")
68-
return StartDataInitiateVerificationResponse(
68+
return StartDataVerificationResponse(
6969
id=response.body.get("id"),
7070
method=response.body.get("method"),
7171
_links=response.body.get("_links"),

0 commit comments

Comments
 (0)