Skip to content

Commit 10ae9b9

Browse files
committed
finish verify v2 and prepare for release
1 parent 2e3ff3b commit 10ae9b9

File tree

18 files changed

+129
-84
lines changed

18 files changed

+129
-84
lines changed

http_client/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 1.2.1
2+
- Expose classes and errors at the package level
3+
14
# 1.2.0
25
- Add `last_request` and `last_response` properties
36
- Add new `Forbidden` error

http_client/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,17 @@ The `HttpClient` class automatically handles JWT and basic authentication based
6969
```python
7070
# Use basic authentication for this request
7171
response = client.get(host='api.nexmo.com', request_path='/v1/messages', auth_type='basic')
72+
```
73+
74+
### Catching errors
75+
76+
Error objects are exposed in the package scope, so you can catch errors like this:
77+
78+
```python
79+
from vonage_http_client import HttpRequestError
80+
81+
try:
82+
client.post(...)
83+
except HttpRequestError:
84+
...
7285
```

http_client/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "vonage-http-client"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
description = "An HTTP client for making requests to Vonage APIs."
55
readme = "README.md"
66
authors = [{ name = "Vonage", email = "devrel@vonage.com" }]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from .auth import Auth
2+
from .errors import (
3+
AuthenticationError,
4+
ForbiddenError,
5+
HttpRequestError,
6+
InvalidAuthError,
7+
InvalidHttpClientOptionsError,
8+
JWTGenerationError,
9+
NotFoundError,
10+
RateLimitedError,
11+
ServerError,
12+
)
13+
from .http_client import HttpClient, HttpClientOptions
14+
15+
__all__ = [
16+
'Auth',
17+
'AuthenticationError',
18+
'ForbiddenError',
19+
'HttpRequestError',
20+
'InvalidAuthError',
21+
'InvalidHttpClientOptionsError',
22+
'JWTGenerationError',
23+
'NotFoundError',
24+
'RateLimitedError',
25+
'ServerError',
26+
'HttpClient',
27+
'HttpClientOptions',
28+
]

verify/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# 1.0.1
2+
- Internal refactoring
3+
14
# 1.0.0
25
- Initial upload

verify/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[project]
22
name = 'vonage-verify'
3-
version = '1.0.0'
3+
version = '1.0.1'
44
description = 'Vonage verify package'
55
readme = "README.md"
66
authors = [{ name = "Vonage", email = "devrel@vonage.com" }]
77
requires-python = ">=3.8"
88
dependencies = [
9-
"vonage-http-client>=1.2.0",
9+
"vonage-http-client>=1.2.1",
1010
"vonage-utils>=1.0.1",
1111
"pydantic>=2.6.1",
1212
]

verify_v2/README.md

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,49 @@ This package contains the code to use [Vonage's Verify v2 API](https://developer
66

77
It is recommended to use this as part of the main `vonage` package. The examples below assume you've created an instance of the `vonage.Vonage` class called `vonage_client`.
88

9-
10-
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
11-
129
### Make a Verify Request
1310

1411
```python
15-
from vonage_verify import VerifyRequest
16-
params = {'number': '1234567890', 'brand': 'Acme Inc.'}
17-
request = VerifyRequest(**params)
18-
response = vonage_client.verify.start_verification(request)
12+
from vonage_verify_v2 import VerifyRequest, SmsChannel
13+
# All channels have associated models
14+
sms_channel = SmsChannel(to='1234567890')
15+
params = {
16+
'brand': 'Vonage',
17+
'workflow': [sms_channel],
18+
}
19+
verify_request = VerifyRequest(**params)
20+
21+
response = vonage_client.verify_v2.start_verification(verify_request)
1922
```
2023

21-
### Make a PSD2 (Payment Services Directive v2) Request
24+
If using silent authentication, the response will include a `check_url` field with a url that should be accessed on the user's device to proceed with silent authentication. If used, silent auth must be the first element in the `workflow` list.
2225

2326
```python
24-
from vonage_verify import Psd2Request
25-
params = {'number': '1234567890', 'payee': 'Acme Inc.', 'amount': 99.99}
26-
request = VerifyRequest(**params)
27-
response = vonage_client.verify.start_verification(request)
27+
silent_auth_channel = SilentAuthChannel(channel=ChannelType.SILENT_AUTH, to='1234567890')
28+
sms_channel = SmsChannel(to='1234567890')
29+
params = {
30+
'brand': 'Vonage',
31+
'workflow': [silent_auth_channel, sms_channel],
32+
}
33+
verify_request = VerifyRequest(**params)
34+
35+
response = vonage_client.verify_v2.start_verification(verify_request)
2836
```
2937

3038
### Check a Verification Code
3139

3240
```python
33-
vonage_client.verify.check_code(request_id='my_request_id', code='1234')
34-
```
35-
36-
### Search Verification Requests
37-
38-
```python
39-
# Search for single request
40-
response = vonage_client.verify.search('my_request_id')
41-
42-
# Search for multiple requests
43-
response = vonage_client.verify.search(['my_request_id_1', 'my_request_id_2'])
41+
vonage_client.verify_v2.check_code(request_id='my_request_id', code='1234')
4442
```
4543

4644
### Cancel a Verification
4745

4846
```python
49-
response = vonage_client.verify.cancel_verification('my_request_id')
47+
vonage_client.verify_v2.cancel_verification('my_request_id')
5048
```
5149

5250
### Trigger the Next Workflow Event
5351

5452
```python
55-
response = vonage_client.verify.trigger_next_event('my_request_id')
56-
```
57-
58-
### Request a Network Unblock
59-
60-
Note: Network Unblock is switched off by default. Contact Sales to enable the Network Unblock API for your account.
61-
62-
```python
63-
response = vonage_client.verify.request_network_unblock('23410')
64-
```
53+
vonage_client.verify_v2.trigger_next_workflow('my_request_id')
54+
```

verify_v2/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ readme = "README.md"
66
authors = [{ name = "Vonage", email = "devrel@vonage.com" }]
77
requires-python = ">=3.8"
88
dependencies = [
9-
"vonage-http-client>=1.2.0",
9+
"vonage-http-client>=1.2.1",
1010
"vonage-utils>=1.0.1",
1111
"pydantic>=2.6.1",
1212
]

verify_v2/src/vonage_verify_v2/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
VoiceChannel,
99
WhatsappChannel,
1010
)
11-
from .responses import StartVerificationResponse
11+
from .responses import CheckCodeResponse, StartVerificationResponse
1212
from .verify_v2 import VerifyV2
1313

1414
__all__ = [
1515
'VerifyV2',
1616
'VerifyError',
1717
'ChannelType',
18+
'CheckCodeResponse',
1819
'Locale',
1920
'VerifyRequest',
2021
'SilentAuthChannel',

verify_v2/src/vonage_verify_v2/requests.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def check_valid_from_field(cls, v):
3131
if (
3232
v is not None
3333
and type(v) is not PhoneNumber
34-
and not search(r'^[a-zA-Z0-9]{1,15}$', v)
34+
and not search(r'^[a-zA-Z0-9]{3,11}$', v)
3535
):
3636
raise VerifyError(
3737
'You must specify a valid "from_" value if included. '
38-
'It must be a valid phone number without the leading +, or a string of 1-15 alphanumeric characters. '
38+
'It must be a valid phone number without the leading +, or a string of 3-11 alphanumeric characters. '
3939
f'You set "from_": "{v}".'
4040
)
4141
return v
@@ -48,10 +48,10 @@ class WhatsappChannel(Channel):
4848
@field_validator('from_')
4949
@classmethod
5050
def check_valid_sender(cls, v):
51-
if type(v) is not PhoneNumber and not search(r'^[a-zA-Z0-9]{1,15}$', v):
51+
if type(v) is not PhoneNumber and not search(r'^[a-zA-Z0-9]{3,11}$', v):
5252
raise VerifyError(
5353
f'You must specify a valid "from_" value. '
54-
'It must be a valid phone number without the leading +, or a string of 1-15 alphanumeric characters. '
54+
'It must be a valid phone number without the leading +, or a string of 3-11 alphanumeric characters. '
5555
f'You set "from_": "{v}".'
5656
)
5757
return v
@@ -84,14 +84,6 @@ class VerifyRequest(BaseModel):
8484
code_length: Optional[int] = Field(None, ge=4, le=10)
8585
code: Optional[str] = Field(None, pattern=r'^[a-zA-Z0-9]{4,10}$')
8686

87-
@model_validator(mode='after')
88-
def remove_fields_if_only_silent_auth(self):
89-
if len(self.workflow) == 1 and isinstance(self.workflow[0], SilentAuthChannel):
90-
self.locale = None
91-
self.code_length = None
92-
self.code = None
93-
return self
94-
9587
@model_validator(mode='after')
9688
def check_silent_auth_first_if_present(self):
9789
if len(self.workflow) > 1:

0 commit comments

Comments
 (0)