Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x #307

Merged
merged 99 commits into from
Nov 6, 2024
Merged

4.x #307

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
ef219d2
squash merge
maxkahan Feb 7, 2024
59c7f19
remove unused tests
maxkahan Feb 7, 2024
095fb7b
add NI v2, refactoring, new tests
maxkahan Feb 14, 2024
3f6d7bb
restructuring utils directory
maxkahan Feb 14, 2024
7736da0
preparing packages for release
maxkahan Feb 15, 2024
715e9f6
preparing for alpha release
maxkahan Feb 22, 2024
38843b4
add sms
maxkahan Mar 3, 2024
7d6eafd
add signature and error handling
maxkahan Mar 16, 2024
9788ca4
working on signing requests
maxkahan Mar 19, 2024
691835e
update signing and add tests
maxkahan Mar 20, 2024
52e94c4
fix mocks, signatures and sig auth, add tests
maxkahan Mar 21, 2024
01145a9
Sms structuring and tests
maxkahan Mar 22, 2024
b547a95
add conversion method, SMS tests, refactoring
maxkahan Mar 23, 2024
35e9fa9
linting
maxkahan Mar 23, 2024
b4657c0
update dependency versions
maxkahan Mar 23, 2024
14237bb
adding users api structure and list endpoint, refactoring and testing
maxkahan Mar 26, 2024
a4c6e5a
add new models, change structure, start implementing pagination
maxkahan Mar 27, 2024
4c9b303
add users api endpoints and tests
maxkahan Mar 27, 2024
ff65eac
finish Users API implementation
maxkahan Mar 28, 2024
2173273
finish Users API implementation
maxkahan Mar 28, 2024
b176787
start working on verify api
maxkahan Mar 29, 2024
dae7232
adding start verification methods and starting check_code
maxkahan Apr 3, 2024
8a22b14
add verify controls
maxkahan Apr 4, 2024
0843a15
add verify controls
maxkahan Apr 4, 2024
2b68284
finish verify implementation and prepare for release
maxkahan Apr 4, 2024
20051fd
start adding verify v2
maxkahan Apr 6, 2024
2e3ff3b
verify logic, models and tests
maxkahan Apr 8, 2024
10ae9b9
finish verify v2 and prepare for release
maxkahan Apr 8, 2024
f22d90b
create messages package
maxkahan Apr 9, 2024
989be78
create message models
maxkahan Apr 9, 2024
847df22
test message models
maxkahan Apr 10, 2024
c45389b
prepare for messages release
maxkahan Apr 10, 2024
5e7d13e
start adding voice api and ncco builder
maxkahan Apr 11, 2024
ff25ff3
finish adding NCCO actions and add tests
maxkahan Apr 17, 2024
5819ed3
finish ncco testing, start with voice endpoints
maxkahan Apr 18, 2024
016e34c
get list_calls working
maxkahan Apr 19, 2024
c8e2f69
add more voice methods
maxkahan Apr 22, 2024
2efdfaa
finish voice api, updating for release
maxkahan Apr 22, 2024
b304344
update readme for release
maxkahan Apr 23, 2024
8c5b806
start adding number insight
maxkahan Apr 24, 2024
61718d6
finish NI module
maxkahan Apr 25, 2024
5f6667d
update dependency versions, prep for NI release
maxkahan Apr 29, 2024
47ce0f8
start creating application package
maxkahan Apr 30, 2024
10113f0
creating more application models and refactoring common components
maxkahan May 1, 2024
ec0d9f2
finish create method, add list method and tests, refactoring
maxkahan May 2, 2024
7e1186a
add other applications endpoints
maxkahan May 2, 2024
87806b1
prepare for application api release
maxkahan May 9, 2024
27bcffa
add new dependency versions
maxkahan May 10, 2024
445cab8
start migration of jwt module
maxkahan May 14, 2024
a7a686c
refactor jwt package, get tests passing
maxkahan May 15, 2024
280ebf2
prepare for new release
maxkahan May 19, 2024
f65afe5
4.x gnp (#300)
maxkahan Jun 21, 2024
21ea88c
start adding account api
maxkahan Aug 5, 2024
1ae0990
add account api, prepare for new releases
maxkahan Aug 9, 2024
bfdbcd1
add new structure
maxkahan Aug 16, 2024
1bff284
add rcs message type, revoke rcs message, mark whatsapp as read
maxkahan Aug 21, 2024
0cde800
add RCS support, revoke RCS message, mark WhatsApp as read
maxkahan Aug 22, 2024
4a27754
fix conflict
maxkahan Aug 22, 2024
f5c8ca8
add subaccounts api
maxkahan Aug 30, 2024
8539ea8
update `vonage_subaccounts.ListSubaccountsResponse` for compatibility…
maxkahan Aug 30, 2024
102015e
add numbers api
maxkahan Sep 5, 2024
a29db3c
linting
maxkahan Sep 5, 2024
fdf6f6f
add video package and token methods
maxkahan Sep 16, 2024
8b3bb19
linting
maxkahan Sep 16, 2024
c5a93da
start adding video api
maxkahan Sep 23, 2024
8aef118
test streaming methods, add signaling
maxkahan Sep 24, 2024
29a1e49
add signaling and moderation endpoints, start live captions
maxkahan Sep 25, 2024
e5c31e1
add captioning, start audio connector
maxkahan Sep 26, 2024
0aa1ea1
finish adding audio connector
maxkahan Sep 27, 2024
68b2b41
start adding experience composer
maxkahan Sep 30, 2024
3123abe
finish adding experience composer, start adding archive models
maxkahan Oct 1, 2024
0935d8e
add archive methods and tests
maxkahan Oct 2, 2024
91e5dc4
start adding broadcast
maxkahan Oct 3, 2024
94e3dd6
finish broadcast, refactoring common code
maxkahan Oct 4, 2024
928295c
add sip endpoints
maxkahan Oct 7, 2024
c0af739
add SIP video endpoints, start release prep
maxkahan Oct 9, 2024
fd3fcb3
add docstrings to data models
maxkahan Oct 9, 2024
2718da3
add more docstrings for data models
maxkahan Oct 10, 2024
5ceb50a
finish docstrings for data models
maxkahan Oct 11, 2024
effabbf
Stop tracking _dev_scripts folder
maxkahan Oct 11, 2024
69bf1e2
update global readme
maxkahan Oct 12, 2024
05b2b94
prepare for alpha release
maxkahan Oct 12, 2024
766964d
support Python 3.9+ and use inbuilt types in type hints
maxkahan Oct 15, 2024
2e925b0
start adding number verification, remove network api beta, add to mai…
maxkahan Oct 15, 2024
315b6dc
add number verification to network auth
maxkahan Oct 16, 2024
cde28c2
prepare for beta release
maxkahan Oct 17, 2024
329d775
writing migration guides/readmes
maxkahan Oct 18, 2024
a3ba43c
prepare for v4 beta release
maxkahan Oct 21, 2024
62ef878
rename number insight methods
maxkahan Oct 21, 2024
67d53da
rename verify -> verify_legacy and verify_v2 -> verify
maxkahan Oct 22, 2024
7653fb7
add SimSwapCheckRequest for SimSwap.check method
maxkahan Oct 22, 2024
4616cb6
update migration guide
maxkahan Oct 23, 2024
06ddaa6
update application parameter name and make users models more easily a…
maxkahan Oct 25, 2024
5631faf
update pants version
maxkahan Oct 30, 2024
61e8abd
update jwt method, update dependency
maxkahan Oct 30, 2024
c34b9cb
update package versions
maxkahan Oct 30, 2024
4717e7d
add pricing methods
maxkahan Nov 5, 2024
4d53afa
add pricing api testing
maxkahan Nov 6, 2024
52ae54f
update readmes and versioning
maxkahan Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
start adding verify v2
  • Loading branch information
maxkahan committed Apr 6, 2024
commit 20051fdb723179f3552be042cab1f3fefd36f913
16 changes: 16 additions & 0 deletions verify_v2/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource(name='pyproject', source='pyproject.toml')
file(name='readme', source='README.md')

files(sources=['tests/data/*'])

python_distribution(
name='vonage-verify-v2',
dependencies=[
':pyproject',
':readme',
'verify_v2/src/vonage_verify_v2',
],
provides=python_artifact(),
generate_setup=False,
repositories=['@pypi'],
)
2 changes: 2 additions & 0 deletions verify_v2/CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 1.0.0
- Initial upload
64 changes: 64 additions & 0 deletions verify_v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Vonage Verify V2 Package

This package contains the code to use [Vonage's Verify v2 API](https://developer.vonage.com/en/verify/overview) in Python. This package includes methods for working with 2-factor authentication (2FA) messages sent via SMS, Voice, WhatsApp and Email. You can also make Silent Authentication requests with Verify v2 to give your end user a more seamless experience.

## Usage

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`.


######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

### Make a Verify Request

```python
from vonage_verify import VerifyRequest
params = {'number': '1234567890', 'brand': 'Acme Inc.'}
request = VerifyRequest(**params)
response = vonage_client.verify.start_verification(request)
```

### Make a PSD2 (Payment Services Directive v2) Request

```python
from vonage_verify import Psd2Request
params = {'number': '1234567890', 'payee': 'Acme Inc.', 'amount': 99.99}
request = VerifyRequest(**params)
response = vonage_client.verify.start_verification(request)
```

### Check a Verification Code

```python
vonage_client.verify.check_code(request_id='my_request_id', code='1234')
```

### Search Verification Requests

```python
# Search for single request
response = vonage_client.verify.search('my_request_id')

# Search for multiple requests
response = vonage_client.verify.search(['my_request_id_1', 'my_request_id_2'])
```

### Cancel a Verification

```python
response = vonage_client.verify.cancel_verification('my_request_id')
```

### Trigger the Next Workflow Event

```python
response = vonage_client.verify.trigger_next_event('my_request_id')
```

### Request a Network Unblock

Note: Network Unblock is switched off by default. Contact Sales to enable the Network Unblock API for your account.

```python
response = vonage_client.verify.request_network_unblock('23410')
```
29 changes: 29 additions & 0 deletions verify_v2/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[project]
name = 'vonage-verify-v2'
version = '1.0.0'
description = 'Vonage verify v2 package'
readme = "README.md"
authors = [{ name = "Vonage", email = "devrel@vonage.com" }]
requires-python = ">=3.8"
dependencies = [
"vonage-http-client>=1.2.0",
"vonage-utils>=1.0.1",
"pydantic>=2.6.1",
]
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
]

[project.urls]
homepage = "https://github.com/Vonage/vonage-python-sdk"

[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
1 change: 1 addition & 0 deletions verify_v2/src/vonage_verify_v2/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources()
28 changes: 28 additions & 0 deletions verify_v2/src/vonage_verify_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from .errors import VerifyError
from .enums import VerifyChannel, VerifyLocale
from .requests import (
VerifyRequest,
SilentAuthWorkflow,
SmsWorkflow,
WhatsappWorkflow,
VoiceWorkflow,
EmailWorkflow,
)
from .responses import (
StartVerificationResponse,
)
from .verify_v2 import Verify

__all__ = [
'Verify',
'VerifyError',
'VerifyChannel',
'VerifyLocale',
'VerifyRequest',
'SilentAuthWorkflow',
'SmsWorkflow',
'WhatsappWorkflow',
'VoiceWorkflow',
'EmailWorkflow',
'StartVerificationResponse',
]
25 changes: 25 additions & 0 deletions verify_v2/src/vonage_verify_v2/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from enum import Enum


class VerifyChannel(Enum):
SILENT_AUTH = 'silent_auth'
SMS = 'sms'
WHATSAPP = 'whatsapp'
VOICE = 'voice'
EMAIL = 'email'


class VerifyLocale(Enum):
EN_US = 'en-us'
EN_GB = 'en-gb'
ES_ES = 'es-es'
ES_MX = 'es-mx'
ES_US = 'es-us'
IT_IT = 'it-it'
FR_FR = 'fr-fr'
DE_DE = 'de-de'
RU_RU = 'ru-ru'
HI_IN = 'hi-in'
PT_BR = 'pt-br'
PT_PT = 'pt-pt'
ID_ID = 'id-id'
5 changes: 5 additions & 0 deletions verify_v2/src/vonage_verify_v2/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from vonage_utils.errors import VonageError


class VerifyError(VonageError):
"""Indicates an error when using the Vonage Verify API."""
81 changes: 81 additions & 0 deletions verify_v2/src/vonage_verify_v2/requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from typing import List, Optional, Union
from re import search

from pydantic import (
BaseModel,
Field,
field_validator,
model_validator,
)
from vonage_utils.types.phone_number import PhoneNumber

from .enums import VerifyChannel, VerifyLocale
from .errors import VerifyError


class Workflow(BaseModel):
channel: VerifyChannel
to: PhoneNumber


class SilentAuthWorkflow(Workflow):
redirect_url: Optional[str] = None
sandbox: Optional[bool] = None


class SmsWorkflow(Workflow):
from_: Optional[Union[PhoneNumber, str]] = Field(None, serialization_alias='from')
entity_id: Optional[str] = Field(None, pattern=r'^[0-9]{1,20}$')
content_id: Optional[str] = Field(None, pattern=r'^[0-9]{1,20}$')
app_hash: Optional[str] = Field(None, min_length=11, max_length=11)

@field_validator('from_')
@classmethod
def check_valid_from_field(cls, v):
if (
v is not None
and type(v) is not PhoneNumber
and not search(r'^[a-zA-Z0-9]{1,15}$', v)
):
raise VerifyError(f'You must specify a valid "from" value if included.')


class WhatsappWorkflow(Workflow):
from_: Union[PhoneNumber, str] = Field(..., serialization_alias='from')

@field_validator('from_')
@classmethod
def check_valid_sender(cls, v):
if type(v) is not PhoneNumber and not search(r'^[a-zA-Z0-9]{1,15}$', v):
raise VerifyError(f'You must specify a valid "from" value.')


class VoiceWorkflow(Workflow):
@model_validator(mode='after')
def remove_from_field_from_voice(self):
self.from_ = None
return self


class EmailWorkflow(Workflow):
to: str
from_: Optional[str] = Field(None, serialization_alias='from')


class VerifyRequest(BaseModel):
brand: str = Field(..., min_length=1, max_length=16)
workflow: List[Workflow]
locale: Optional[VerifyLocale] = None
channel_timeout: Optional[int] = Field(None, ge=60, le=900)
client_ref: Optional[str] = Field(None, min_length=1, max_length=16)
code_length: Optional[int] = Field(None, ge=4, le=10)
code: Optional[str] = Field(None, pattern=r'^[a-zA-Z0-9]{4,10}$')

@model_validator(mode='after')
def remove_fields_if_only_silent_auth(self):
if len(self.workflow) == 1 and isinstance(self.workflow[0], SilentAuthWorkflow):
self.locale = None
self.client_ref = None
self.code_length = None
self.code = None
return self
8 changes: 8 additions & 0 deletions verify_v2/src/vonage_verify_v2/responses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Optional

from pydantic import BaseModel


class StartVerificationResponse(BaseModel):
request_id: str
check_url: Optional[str] = None
121 changes: 121 additions & 0 deletions verify_v2/src/vonage_verify_v2/verify_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
from typing import List, Optional, Union

from pydantic import validate_call
from vonage_http_client.http_client import HttpClient

from .errors import VerifyError
from .requests import (
VerifyRequest,
SilentAuthWorkflow,
SmsWorkflow,
WhatsappWorkflow,
VoiceWorkflow,
EmailWorkflow,
)
from .responses import (
CheckCodeResponse,
StartVerificationResponse,
VerifyControlStatus,
VerifyStatus,
)


class Verify:
"""Calls Vonage's Verify V2 API."""

def __init__(self, http_client: HttpClient) -> None:
self._http_client = http_client

@validate_call
def start_verification(
self, verify_request: VerifyRequest
) -> StartVerificationResponse:
"""Start a verification process.

Args:
verify_request (VerifyRequest): The verification request object.

Returns:
StartVerificationResponse: The response object containing the `request_id`.
If requesting Silent Authentication, it will also contain a `check_url` field.
"""
response = self._http_client.post(
self._http_client.api_host,
'/v2/verify',
verify_request.model_dump(by_alias=True, exclude_none=True),
)

return StartVerificationResponse(**response)

####################################################################################################

####################################################################################################

####################################################################################################

####################################################################################################

@validate_call
def check_code(self, request_id: str, code: str) -> CheckCodeResponse:
"""Check a verification code.

Args:
request_id (str): The request ID.
code (str): The verification code.

Returns:
CheckCodeResponse: The response object containing the verification result.
"""
response = self._http_client.post(
self._http_client.api_host,
'/verify/check/json',
{'request_id': request_id, 'code': code},
self._auth_type,
self._sent_data_type,
)
self._check_for_error(response)
return CheckCodeResponse(**response)

@validate_call
def cancel_verification(self, request_id: str) -> VerifyControlStatus:
"""Cancel a verification request.

Args:
request_id (str): The request ID.

Returns:
VerifyControlStatus: The response object containing details of the submitted
verification control.
"""
response = self._http_client.post(
self._http_client.api_host,
'/verify/control/json',
{'request_id': request_id, 'cmd': 'cancel'},
self._auth_type,
self._sent_data_type,
)
self._check_for_error(response)

return VerifyControlStatus(**response)

@validate_call
def trigger_next_workflow(self, request_id: str) -> VerifyControlStatus:
"""Trigger the next workflow event in the verification process.

Args:
request_id (str): The request ID.

Returns:
VerifyControlStatus: The response object containing details of the submitted
verification control.
"""
response = self._http_client.post(
self._http_client.api_host,
'/verify/control/json',
{'request_id': request_id, 'cmd': 'trigger_next_event'},
self._auth_type,
self._sent_data_type,
)
self._check_for_error(response)

return VerifyControlStatus(**response)
Loading