Skip to content

Commit 37f4fed

Browse files
committed
Add some more clearly named methods for the Verify API
1 parent c469c15 commit 37f4fed

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

nexmo/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,30 @@ def initiate_tts_call(self, params=None, **kwargs):
112112
def initiate_tts_prompt_call(self, params=None, **kwargs):
113113
return self.post(self.api_host, '/tts-prompt/json', params or kwargs)
114114

115+
def start_verification(self, params=None, **kwargs):
116+
return self.post(self.api_host, '/verify/json', params or kwargs)
117+
115118
def send_verification_request(self, params=None, **kwargs):
116119
return self.post(self.api_host, '/verify/json', params or kwargs)
117120

121+
def check_verification(self, request_id, params=None, **kwargs):
122+
return self.post(self.api_host, '/verify/check/json', dict(params or kwargs, request_id=request_id))
123+
118124
def check_verification_request(self, params=None, **kwargs):
119125
return self.post(self.api_host, '/verify/check/json', params or kwargs)
120126

127+
def get_verification(self, request_id):
128+
return self.get(self.api_host, '/verify/search/json', {'request_id': request_id})
129+
121130
def get_verification_request(self, request_id):
122131
return self.get(self.api_host, '/verify/search/json', {'request_id': request_id})
123132

133+
def cancel_verification(self, request_id):
134+
return self.post(self.api_host, '/verify/control/json', {'request_id': request_id, 'cmd': 'cancel'})
135+
136+
def trigger_next_verification_event(self, request_id):
137+
return self.post(self.api_host, '/verify/control/json', {'request_id': request_id, 'cmd': 'trigger_next_event'})
138+
124139
def control_verification_request(self, params=None, **kwargs):
125140
return self.post(self.api_host, '/verify/control/json', params or kwargs)
126141

test_nexmo.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ def test_initiate_tts_prompt_call(self):
260260
self.assertOK(self.client.initiate_tts_prompt_call(params))
261261
self.assertRequestBodyIncludes(params)
262262

263+
@responses.activate
264+
def test_start_verification(self):
265+
self.stub(responses.POST, 'https://api.nexmo.com/verify/json')
266+
267+
params = {'number': '447525856424', 'brand': 'MyApp'}
268+
269+
self.assertOK(self.client.start_verification(params))
270+
self.assertRequestBodyIncludes(params)
271+
263272
@responses.activate
264273
def test_send_verification_request(self):
265274
self.stub(responses.POST, 'https://api.nexmo.com/verify/json')
@@ -269,6 +278,13 @@ def test_send_verification_request(self):
269278
self.assertOK(self.client.send_verification_request(params))
270279
self.assertRequestBodyIncludes(params)
271280

281+
@responses.activate
282+
def test_check_verification(self):
283+
self.stub(responses.POST, 'https://api.nexmo.com/verify/check/json')
284+
285+
self.assertOK(self.client.check_verification('8g88g88eg8g8gg9g90', code='123445'))
286+
self.assertRequestBodyIncludes({'code': '123445', 'request_id': '8g88g88eg8g8gg9g90'})
287+
272288
@responses.activate
273289
def test_check_verification_request(self):
274290
self.stub(responses.POST, 'https://api.nexmo.com/verify/check/json')
@@ -278,13 +294,34 @@ def test_check_verification_request(self):
278294
self.assertOK(self.client.check_verification_request(params))
279295
self.assertRequestBodyIncludes(params)
280296

297+
@responses.activate
298+
def test_get_verification(self):
299+
self.stub(responses.GET, 'https://api.nexmo.com/verify/search/json')
300+
301+
self.assertOK(self.client.get_verification('xxx'))
302+
self.assertRequestQueryIncludes('request_id=xxx')
303+
281304
@responses.activate
282305
def test_get_verification_request(self):
283306
self.stub(responses.GET, 'https://api.nexmo.com/verify/search/json')
284307

285308
self.assertOK(self.client.get_verification_request('xxx'))
286309
self.assertRequestQueryIncludes('request_id=xxx')
287310

311+
@responses.activate
312+
def test_cancel_verification(self):
313+
self.stub(responses.POST, 'https://api.nexmo.com/verify/control/json')
314+
315+
self.assertOK(self.client.cancel_verification('8g88g88eg8g8gg9g90'))
316+
self.assertRequestBodyIncludes({'cmd': 'cancel', 'request_id': '8g88g88eg8g8gg9g90'})
317+
318+
@responses.activate
319+
def test_trigger_next_verification_event(self):
320+
self.stub(responses.POST, 'https://api.nexmo.com/verify/control/json')
321+
322+
self.assertOK(self.client.trigger_next_verification_event('8g88g88eg8g8gg9g90'))
323+
self.assertRequestBodyIncludes({'cmd': 'trigger_next_event', 'request_id': '8g88g88eg8g8gg9g90'})
324+
288325
@responses.activate
289326
def test_control_verification_request(self):
290327
self.stub(responses.POST, 'https://api.nexmo.com/verify/control/json')

0 commit comments

Comments
 (0)