Skip to content

Commit 715e9f6

Browse files
committed
preparing for alpha release
1 parent 7736da0 commit 715e9f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+244
-80
lines changed

http_client/BUILD

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
resource(name='pyproject', source='pyproject.toml')
2+
file(name='readme', source='README.md')
23

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

56
python_distribution(
67
name='vonage-http-client',
7-
dependencies=[':pyproject', 'http_client/src/http_client', 'utils/src/utils'],
8+
dependencies=[
9+
':pyproject',
10+
':readme',
11+
'http_client/src/vonage_http_client:http_client',
12+
],
813
provides=python_artifact(),
914
generate_setup=False,
10-
repositories=['https://test.pypi.org/legacy/'],
15+
repositories=['@pypi'],
1116
)

http_client/README.md

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
1-
# Need to redo this to be about the client!
1+
# Vonage HTTP Client Package
22

3-
Vonage Authentication Package
3+
This Python package provides a synchronous HTTP client for sending authenticated requests to Vonage APIs.
44

5-
`vonage-auth` provides a convenient way to handle authentication related to Vonage APIs in your Python projects. This package includes an `Auth` class that allows you to manage API key- and secret-based authentication as well as JSON Web Token (JWT) authentication.
5+
This package (`vonage-http-client`) is used by the `vonage` Python package and SDK so doesn't require manual installation or config unless you're using this package independently of a SDK.
66

7-
This package (`vonage-auth`) is used by the `vonage` Python package so doesn't require manual installation unless you're not using that.
7+
The `HttpClient` class is initialized with an instance of the `Auth` class for credentials, an optional class of HTTP client options, and an optional SDK version (this is provided automatically when using this module via an SDK).
8+
9+
The `HttpClientOptions` class defines the options for the HTTP client, including the API and REST hosts, timeout, pool connections, pool max size, and max retries.
10+
11+
This package also includes an `Auth` class that allows you to manage API key- and secret-based authentication as well as JSON Web Token (JWT) authentication.
812

913
For full API documentation refer to the [Vonage Developer documentation](https://developer.vonage.com).
1014

11-
## Installation
15+
## Installation (if not using via an SDK)
1216

1317
You can install the package using pip:
1418

1519
```bash
16-
pip install vonage-auth
20+
pip install vonage-http-client
1721
```
22+
23+
## Usage
24+
25+
```python
26+
from vonage_http_client import HttpClient, HttpClientOptions
27+
from vonage_http_client.auth import Auth
28+
29+
# Create an Auth instance
30+
auth = Auth(api_key='your_api_key', api_secret='your_api_secret')
31+
32+
# Create HttpClientOptions instance
33+
options = HttpClientOptions(api_host='api.nexmo.com', timeout=30)
34+
35+
# Create a HttpClient instance
36+
client = HttpClient(auth=auth, http_client_options=options)
37+
38+
# Make a GET request
39+
response = client.get(host='api.nexmo.com', request_path='/v1/messages')
40+
41+
# Make a POST request
42+
response = client.post(host='api.nexmo.com', request_path='/v1/messages', params={'key': 'value'})
43+
```
44+
45+
### Appending to the User-Agent Header
46+
47+
The HttpClient class also supports appending additional information to the User-Agent header via the append_to_user_agent method:
48+
49+
```python
50+
client.append_to_user_agent('additional_info')
51+
```
52+
53+
### Changing the Authentication Method Used
54+
55+
The `HttpClient` class automatically handles JWT and basic authentication based on the Auth instance provided. It uses JWT authentication by default, but you can specify the authentication type when making a request:
56+
57+
```python
58+
# Use basic authentication for this request
59+
response = client.get(host='api.nexmo.com', request_path='/v1/messages', auth_type='basic')
60+
```

http_client/pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[project]
2-
name = 'vonage-http-client'
3-
version = '0.1.0'
4-
description = 'An HTTP client for making requests to Vonage APIs.'
2+
name = "vonage-http-client"
3+
version = "1.0.0"
4+
description = "An HTTP client for making requests to Vonage APIs."
55
readme = "README.md"
66
authors = [{ name = "Vonage", email = "devrel@vonage.com" }]
77
requires-python = ">=3.8"
88
dependencies = [
9-
"vonage-utils>=0.1.0",
9+
"vonage-utils>=1.0.0",
1010
"vonage-jwt>=1.1.0",
11-
"requests==2.*",
11+
"requests>=2.27.0",
1212
"pydantic>=2.6.1",
1313
"typing_extensions>=4.9.0",
1414
]
@@ -24,7 +24,7 @@ classifiers = [
2424
]
2525

2626
[project.urls]
27-
homepage = "https://github.com/Vonage/vonage-python-sdk"
27+
Homepage = "https://github.com/Vonage/vonage-python-sdk"
2828

2929
[build-system]
3030
requires = ["setuptools>=61.0", "wheel"]

http_client/src/http_client/errors.py renamed to http_client/src/vonage_http_client/errors.py

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

33
from requests import Response
4-
from utils.errors import VonageError
4+
from vonage_utils.errors import VonageError
55

66

77
class JWTGenerationError(VonageError):

http_client/src/http_client/http_client.py renamed to http_client/src/vonage_http_client/http_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
from platform import python_version
33
from typing import Literal, Optional, Union
44

5-
from http_client.auth import Auth
6-
from http_client.errors import (
5+
from pydantic import BaseModel, Field, ValidationError, validate_call
6+
from requests import Response
7+
from requests.adapters import HTTPAdapter
8+
from requests.sessions import Session
9+
from typing_extensions import Annotated
10+
from vonage_http_client.auth import Auth
11+
from vonage_http_client.errors import (
712
AuthenticationError,
813
HttpRequestError,
914
InvalidHttpClientOptionsError,
1015
RateLimitedError,
1116
ServerError,
1217
)
13-
from pydantic import BaseModel, Field, ValidationError, validate_call
14-
from requests import Response
15-
from requests.adapters import HTTPAdapter
16-
from requests.sessions import Session
17-
from typing_extensions import Annotated
1818

1919
logger = getLogger('vonage')
2020

http_client/tests/test_auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from os.path import dirname, join
22
from unittest.mock import patch
33

4-
from http_client.auth import Auth
5-
from http_client.errors import InvalidAuthError, JWTGenerationError
64
from pydantic import ValidationError
75
from pytest import raises
6+
from vonage_http_client.auth import Auth
7+
from vonage_http_client.errors import InvalidAuthError, JWTGenerationError
88
from vonage_jwt.jwt import JwtClient
99

1010

@@ -81,14 +81,14 @@ def vonage_jwt_mock(self):
8181

8282
def test_generate_application_jwt():
8383
auth = Auth(application_id=application_id, private_key=private_key)
84-
with patch('http_client.auth.Auth.generate_application_jwt', vonage_jwt_mock):
84+
with patch('vonage_http_client.auth.Auth.generate_application_jwt', vonage_jwt_mock):
8585
jwt = auth.generate_application_jwt()
8686
assert jwt == test_jwt
8787

8888

8989
def test_create_jwt_auth_string():
9090
auth = Auth(application_id=application_id, private_key=private_key)
91-
with patch('http_client.auth.Auth.generate_application_jwt', vonage_jwt_mock):
91+
with patch('vonage_http_client.auth.Auth.generate_application_jwt', vonage_jwt_mock):
9292
header_auth_string = auth.create_jwt_auth_string()
9393
assert header_auth_string == b'Bearer ' + test_jwt
9494

http_client/tests/test_http_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
from os.path import abspath, dirname, join
33

44
import responses
5-
from http_client.auth import Auth
6-
from http_client.errors import (
5+
from pytest import raises
6+
from requests import Response
7+
from vonage_http_client.auth import Auth
8+
from vonage_http_client.errors import (
79
AuthenticationError,
810
HttpRequestError,
911
InvalidHttpClientOptionsError,
1012
RateLimitedError,
1113
ServerError,
1214
)
13-
from pytest import raises
14-
from requests import Response
15+
from vonage_http_client.http_client import HttpClient
1516

16-
from http_client.http_client import HttpClient
17-
from testing_utils import build_response
17+
from testutils import build_response
1818

1919
path = abspath(__file__)
2020

0 commit comments

Comments
 (0)