Skip to content

Commit ff65eac

Browse files
committed
finish Users API implementation
1 parent 4c9b303 commit ff65eac

File tree

24 files changed

+223
-91
lines changed

24 files changed

+223
-91
lines changed

http_client/CHANGES.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
# 1.0.0
2-
- Initial upload
1+
# 1.1.1
2+
- Add new Patch method
3+
- New input fields for different ways to pass data in a request
34

45
# 1.1.0
5-
- Add support for signature authentication
6+
- Add support for signature authentication
7+
8+
# 1.0.0
9+
- Initial upload

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

http_client/src/vonage_http_client/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from json import dumps, JSONDecodeError
1+
from json import JSONDecodeError, dumps
22

33
from requests import Response
44
from vonage_utils.errors import VonageError

http_client/src/vonage_http_client/http_client.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Literal, Optional, Union
55

66
from pydantic import BaseModel, Field, ValidationError, validate_call
7-
from requests import Response, delete
7+
from requests import Response
88
from requests.adapters import HTTPAdapter
99
from requests.sessions import Session
1010
from typing_extensions import Annotated
@@ -107,30 +107,34 @@ def post(
107107
request_path: str = '',
108108
params: dict = None,
109109
auth_type: Literal['jwt', 'basic', 'signature'] = 'jwt',
110-
body_type: Literal['json', 'data'] = 'json',
110+
sent_data_type: Literal['json', 'data'] = 'json',
111111
) -> Union[dict, None]:
112-
return self.make_request('POST', host, request_path, params, auth_type, body_type)
112+
return self.make_request(
113+
'POST', host, request_path, params, auth_type, sent_data_type
114+
)
113115

114116
def get(
115117
self,
116118
host: str,
117119
request_path: str = '',
118120
params: dict = None,
119121
auth_type: Literal['jwt', 'basic', 'signature'] = 'jwt',
120-
body_type: Literal['json', 'data'] = 'json',
122+
sent_data_type: Literal['json', 'form', 'query_params'] = 'json',
121123
) -> Union[dict, None]:
122-
return self.make_request('GET', host, request_path, params, auth_type, body_type)
124+
return self.make_request(
125+
'GET', host, request_path, params, auth_type, sent_data_type
126+
)
123127

124128
def patch(
125129
self,
126130
host: str,
127131
request_path: str = '',
128132
params: dict = None,
129133
auth_type: Literal['jwt', 'basic', 'signature'] = 'jwt',
130-
body_type: Literal['json', 'data'] = 'json',
134+
sent_data_type: Literal['json', 'form', 'query_params'] = 'json',
131135
) -> Union[dict, None]:
132136
return self.make_request(
133-
'PATCH', host, request_path, params, auth_type, body_type
137+
'PATCH', host, request_path, params, auth_type, sent_data_type
134138
)
135139

136140
def delete(
@@ -139,10 +143,10 @@ def delete(
139143
request_path: str = '',
140144
params: dict = None,
141145
auth_type: Literal['jwt', 'basic', 'signature'] = 'jwt',
142-
body_type: Literal['json', 'data'] = 'json',
146+
sent_data_type: Literal['json', 'form', 'query_params'] = 'json',
143147
) -> Union[dict, None]:
144148
return self.make_request(
145-
'DELETE', host, request_path, params, auth_type, body_type
149+
'DELETE', host, request_path, params, auth_type, sent_data_type
146150
)
147151

148152
@validate_call
@@ -153,7 +157,7 @@ def make_request(
153157
request_path: str = '',
154158
params: Optional[dict] = None,
155159
auth_type: Literal['jwt', 'basic', 'signature'] = 'jwt',
156-
body_type: Literal['json', 'data'] = 'json',
160+
sent_data_type: Literal['json', 'form', 'query_params'] = 'json',
157161
):
158162
url = f'https://{host}{request_path}'
159163
logger.debug(
@@ -174,10 +178,12 @@ def make_request(
174178
'timeout': self._timeout,
175179
}
176180

177-
if body_type == 'json':
181+
if sent_data_type == 'json':
178182
self._headers['Content-Type'] = 'application/json'
179183
request_params['json'] = params
180-
else:
184+
elif sent_data_type == 'query_params':
185+
request_params['params'] = params
186+
elif sent_data_type == 'form':
181187
request_params['data'] = params
182188

183189
with self._session.request(**request_params) as response:

http_client/tests/test_http_client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@ def test_create_http_client_invalid_options_error():
5656

5757
@responses.activate
5858
def test_make_get_request():
59-
build_response(path, 'GET', 'https://example.com/get_json', 'example_get.json')
59+
build_response(
60+
path, 'GET', 'https://example.com/get_json?key=value', 'example_get.json'
61+
)
6062
client = HttpClient(
6163
Auth(application_id=application_id, private_key=private_key),
6264
http_client_options={'api_host': 'example.com'},
6365
)
64-
res = client.get(host='example.com', request_path='/get_json')
66+
res = client.get(
67+
host='example.com',
68+
request_path='/get_json',
69+
params={'key': 'value'},
70+
sent_data_type='query_params',
71+
)
6572

6673
assert res['hello'] == 'world'
6774
assert responses.calls[0].request.headers['User-Agent'] == client._user_agent
@@ -131,7 +138,7 @@ def test_make_post_request_with_signature():
131138
request_path='/post_signed_params',
132139
params=params,
133140
auth_type='signature',
134-
body_type='data',
141+
sent_data_type='form',
135142
)
136143
assert res['hello'] == 'world!'
137144

number_insight_v2/tests/test_number_insight_v2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import responses
55
from pydantic import ValidationError
66
from pytest import raises
7-
from vonage_http_client.auth import Auth
87
from vonage_http_client.http_client import HttpClient
98
from vonage_number_insight_v2.number_insight_v2 import (
109
FraudCheckRequest,
@@ -14,11 +13,11 @@
1413
from vonage_utils.errors import InvalidPhoneNumberError
1514
from vonage_utils.utils import remove_none_values
1615

17-
from testutils import build_response
16+
from testutils import build_response, get_mock_api_key_auth
1817

1918
path = abspath(__file__)
2019

21-
ni2 = NumberInsightV2(HttpClient(Auth('key', 'secret')))
20+
ni2 = NumberInsightV2(HttpClient(get_mock_api_key_auth()))
2221

2322

2423
def test_fraud_check_request_defaults():

sms/CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
# 1.0.2
2+
- Internal refactoring
3+
4+
# 1.0.1
5+
- Internal refactoring
6+
17
# 1.0.0
28
- Initial upload

sms/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-sms'
3-
version = '1.0.1'
3+
version = '1.0.2'
44
description = 'Vonage SMS package'
55
readme = "README.md"
66
authors = [{ name = "Vonage", email = "[email protected]" }]
77
requires-python = ">=3.8"
88
dependencies = [
9-
"vonage-http-client>=1.1.0",
9+
"vonage-http-client>=1.1.1",
1010
"vonage-utils>=1.0.0",
1111
"pydantic>=2.6.1",
1212
]

sms/src/vonage_sms/sms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Sms:
1313

1414
def __init__(self, http_client: HttpClient) -> None:
1515
self._http_client = http_client
16-
self._body_type = 'data'
16+
self._sent_data_type = 'form'
1717
if self._http_client._auth._signature_secret:
1818
self._auth_type = 'signature'
1919
else:
@@ -27,7 +27,7 @@ def send(self, message: SmsMessage) -> SmsResponse:
2727
'/sms/json',
2828
message.model_dump(by_alias=True),
2929
self._auth_type,
30-
self._body_type,
30+
self._sent_data_type,
3131
)
3232

3333
if int(response['message-count']) > 1:
@@ -78,9 +78,10 @@ def submit_sms_conversion(
7878
'%Y-%m-%d %H:%M:%S'
7979
),
8080
}
81-
self._http_client.get(
81+
self._http_client.post(
8282
self._http_client.api_host,
8383
'/conversions/sms',
8484
params,
8585
self._auth_type,
86+
self._sent_data_type,
8687
)

sms/tests/test_sms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_send_message_error():
150150
def test_submit_sms_conversion():
151151
build_response(
152152
path,
153-
'GET',
153+
'POST',
154154
'https://api.nexmo.com/conversions/sms',
155155
'null',
156156
)
@@ -162,7 +162,7 @@ def test_submit_sms_conversion():
162162
def test_submit_sms_conversion_402():
163163
build_response(
164164
path,
165-
'GET',
165+
'POST',
166166
'https://api.nexmo.com/conversions/sms',
167167
'conversion_not_enabled.html',
168168
status_code=402,

0 commit comments

Comments
 (0)