Skip to content

Commit 38843b4

Browse files
committed
add sms
1 parent 715e9f6 commit 38843b4

File tree

14 files changed

+255
-0
lines changed

14 files changed

+255
-0
lines changed

http_client/src/vonage_http_client/auth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def __init__(
2727
api_secret: Optional[str] = None,
2828
application_id: Optional[str] = None,
2929
private_key: Optional[str] = None,
30+
signature: Optional[str] = None,
31+
signature_method: Optional[str] = None,
3032
) -> None:
3133
self._validate_input_combinations(
3234
api_key, api_secret, application_id, private_key

sms/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource(name='pyproject', source='pyproject.toml')
2+
file(name='readme', source='README.md')
3+
4+
files(sources=['tests/data/*'])
5+
6+
python_distribution(
7+
name='vonage-sms',
8+
dependencies=[
9+
':pyproject',
10+
':readme',
11+
'sms/src/vonage_sms',
12+
],
13+
provides=python_artifact(),
14+
generate_setup=False,
15+
repositories=['@testpypi'],
16+
)

sms/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Vonage SMS Package
2+
3+
This package contains the code to use Vonage's SMS API with Python.
4+
5+
## Usage

sms/pyproject.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[project]
2+
name = 'vonage-sms'
3+
version = '0.1.0'
4+
description = 'Vonage SMS package'
5+
readme = "README.md"
6+
authors = [{ name = "Vonage", email = "[email protected]" }]
7+
requires-python = ">=3.8"
8+
dependencies = [
9+
"vonage-http-client>=1.0.0",
10+
"vonage-utils>=1.0.0",
11+
"pydantic>=2.6.1",
12+
]
13+
classifiers = [
14+
"Programming Language :: Python",
15+
"Programming Language :: Python :: 3",
16+
"Programming Language :: Python :: 3.8",
17+
"Programming Language :: Python :: 3.9",
18+
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
21+
"License :: OSI Approved :: Apache Software License",
22+
]
23+
24+
[project.urls]
25+
homepage = "https://github.com/Vonage/vonage-python-sdk"
26+
27+
[build-system]
28+
requires = ["setuptools>=61.0", "wheel"]
29+
build-backend = "setuptools.build_meta"

sms/src/vonage_sms/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python_sources()

sms/src/vonage_sms/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .sms import Sms
2+
3+
__all__ = [
4+
'Sms',
5+
]

sms/src/vonage_sms/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from vonage_utils.errors import VonageError
2+
3+
4+
class SmsError(VonageError):
5+
"""Indicates an error with the Vonage SMS Package."""

sms/src/vonage_sms/sms.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from copy import deepcopy
2+
from dataclasses import dataclass
3+
from typing import List, Literal, Optional, Union
4+
5+
from pydantic import BaseModel, Field, field_validator, validate_call
6+
from vonage_http_client.http_client import HttpClient
7+
from vonage_sms.errors import SmsError
8+
9+
10+
class SmsMessage(BaseModel):
11+
to: str
12+
from_: str = Field(..., alias="from")
13+
text: str
14+
type: Optional[str] = None
15+
sig: Optional[str] = Field(None, min_length=16, max_length=60)
16+
status_report_req: Optional[int] = Field(
17+
None,
18+
alias="status-report-req",
19+
description="Set to 1 to receive a Delivery Receipt",
20+
)
21+
client_ref: Optional[str] = Field(
22+
None, alias="client-ref", description="Your own reference. Up to 40 characters."
23+
)
24+
network_code: Optional[str] = Field(
25+
None,
26+
alias="network-code",
27+
description="A 4-5 digit number that represents the mobile carrier network code",
28+
)
29+
30+
31+
@dataclass
32+
class SmsResponse:
33+
id: str
34+
35+
36+
class Sms:
37+
"""Calls Vonage's SMS API."""
38+
39+
def __init__(self, http_client: HttpClient) -> None:
40+
self._http_client = deepcopy(http_client)
41+
self._auth_type = 'basic'
42+
43+
@validate_call
44+
def send(self, message: SmsMessage) -> SmsResponse:
45+
"""Send an SMS message."""
46+
response = self._http_client.post(
47+
self._http_client.api_host,
48+
'/v2/ni',
49+
message.model_dump(),
50+
self._auth_type,
51+
)

sms/tests/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python_tests(dependencies=['sms', 'testutils'])

sms/tests/data/default.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"request_id": "2c2f5d3f-93ac-42b1-9083-4b14f0d583d3",
3+
"type": "phone",
4+
"phone": {
5+
"phone": "1234567890",
6+
"carrier": "Verizon Wireless",
7+
"type": "MOBILE"
8+
},
9+
"fraud_score": {
10+
"risk_score": "0",
11+
"risk_recommendation": "allow",
12+
"label": "low",
13+
"status": "completed"
14+
},
15+
"sim_swap": {
16+
"status": "completed",
17+
"swapped": false
18+
}
19+
}

0 commit comments

Comments
 (0)