Skip to content

Commit b547a95

Browse files
committed
add conversion method, SMS tests, refactoring
1 parent 01145a9 commit b547a95

24 files changed

+251
-66
lines changed

http_client/CHANGES.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
# 0.1.0
2-
- Initial upload
1+
# 1.0.0
2+
- Initial upload
3+
4+
# 1.1.0
5+
- Add support for signature authentication

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.0.0"
3+
version = "1.1.0"
44
description = "An HTTP client for making requests to Vonage APIs."
55
readme = "README.md"
66
authors = [{ name = "Vonage", email = "devrel@vonage.com" }]

http_client/src/vonage_http_client/auth.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import hashlib
22
import hmac
33
from base64 import b64encode
4-
54
from time import time
65
from typing import Literal, Optional
76

@@ -111,8 +110,7 @@ def sign_params(self, params: dict) -> str:
111110

112111
@validate_call
113112
def check_signature(self, params: dict) -> bool:
114-
"""
115-
Checks the signature hash of the given parameters.
113+
"""Checks the signature hash of the given parameters.
116114
117115
Args:
118116
params (dict): The parameters to check the signature for.

http_client/src/vonage_http_client/http_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from json import JSONDecodeError
12
from logging import getLogger
23
from platform import python_version
34
from typing import Literal, Optional, Union
@@ -167,7 +168,10 @@ def _parse_response(self, response: Response) -> Union[dict, None]:
167168
if 200 <= response.status_code < 300:
168169
if response.status_code == 204:
169170
return None
170-
return response.json()
171+
try:
172+
return response.json()
173+
except JSONDecodeError:
174+
return None
171175
if response.status_code >= 400:
172176
logger.warning(
173177
f'Http Response Error! Status code: {response.status_code}; content: {repr(response.text)}; from url: {response.url}'

number_insight_v2/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ It includes classes for making fraud check requests and handling the responses.
88
First, import the necessary classes and create an instance of the `NumberInsightV2` class:
99

1010
```python
11-
from vonage_http_client.http_client import HttpClient
11+
from vonage_http_client.http_client import HttpClient, Auth
1212
from number_insight_v2 import NumberInsightV2, FraudCheckRequest
1313

14-
http_client = HttpClient(api_host='your_api_host', api_key='your_api_key', api_secret='your_api_secret')
14+
http_client = HttpClient(Auth(api_key='your_api_key', api_secret='your_api_secret'))
1515
number_insight = NumberInsightV2(http_client)
1616
```
1717

pants.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ backend_packages = [
1212
"pants.backend.experimental.python",
1313
]
1414

15+
pants_ignore.add = ['!_test_scripts/']
16+
1517
[anonymous-telemetry]
1618
enabled = false
1719

sms/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ python_distribution(
1212
],
1313
provides=python_artifact(),
1414
generate_setup=False,
15-
repositories=['@testpypi'],
15+
repositories=['@pypi'],
1616
)

sms/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 1.0.0
2+
- Initial upload

sms/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Vonage SMS Package
22

3-
This package contains the code to use Vonage's SMS API with Python.
3+
This package contains the code to use Vonage's SMS API in Python.
4+
5+
It includes a method for sending SMS messages and returns an `SmsResponse` class to handle the response.
46

57
## Usage
8+
9+
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`.
10+
11+
### Send an SMS
12+
13+
Create an `SmsMessage` object, then pass into the `Sms.send` method.
14+
15+
```python
16+
from vonage_sms import SmsMessage, SmsResponse
17+
18+
message = SmsMessage(to='1234567890', from_='Acme Inc.', text='Hello, World!')
19+
response: SmsResponse = vonage_client.sms.send(message)
20+
21+
print(response.model_dump(exclude_unset=True))
22+
```
23+
24+

sms/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-sms'
3-
version = '0.1.0'
3+
version = '1.0.0'
44
description = 'Vonage SMS package'
55
readme = "README.md"
66
authors = [{ name = "Vonage", email = "devrel@vonage.com" }]

0 commit comments

Comments
 (0)