Skip to content

Commit bfdbcd1

Browse files
committed
add new structure
1 parent 1ae0990 commit bfdbcd1

File tree

17 files changed

+376
-2
lines changed

17 files changed

+376
-2
lines changed

pants.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[GLOBAL]
2-
pants_version = '2.21.0'
2+
pants_version = '2.21.1'
33

44
backend_packages = [
55
'pants.backend.python',
@@ -42,6 +42,7 @@ filter = [
4242
'number_insight/src',
4343
'number_insight_v2/src',
4444
'sms/src',
45+
'subaccounts/src',
4546
'users/src',
4647
'utils/src',
4748
'testutils',

subaccounts/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-subaccounts',
8+
dependencies=[
9+
':pyproject',
10+
':readme',
11+
'subaccounts/src/vonage_subaccounts',
12+
],
13+
provides=python_artifact(),
14+
generate_setup=False,
15+
repositories=['@pypi'],
16+
)

subaccounts/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

subaccounts/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Vonage Subaccount Package
2+
3+
This package contains the code to use Vonage's Subaccount API in Python.
4+
5+
It includes methods for managing Vonage subaccounts.
6+
7+
## 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+
12+
<!-- ### Get Account Balance
13+
14+
```python
15+
balance = vonage_client.account.get_balance()
16+
print(balance)
17+
```
18+
19+
### Top-Up Account
20+
21+
```python
22+
response = vonage_client.account.top_up(trx='1234567890')
23+
print(response)
24+
```
25+
26+
### Update the Default SMS Webhook
27+
28+
This will return a Pydantic object (`SettingsResponse`) containing multiple settings for your account.
29+
30+
```python
31+
settings: SettingsResponse = vonage_client.account.update_default_sms_webhook(
32+
mo_callback_url='https://example.com/inbound_sms_webhook',
33+
dr_callback_url='https://example.com/delivery_receipt_webhook',
34+
)
35+
36+
print(settings)
37+
```
38+
39+
### List Secrets Associated with the Account
40+
41+
```python
42+
response = vonage_client.account.list_secrets()
43+
print(response)
44+
```
45+
46+
### Create a New Account Secret
47+
48+
```python
49+
secret = vonage_client.account.create_secret('Mytestsecret12345')
50+
print(secret)
51+
```
52+
53+
### Get Information About One Secret
54+
55+
```python
56+
secret = vonage_client.account.get_secret(MY_SECRET_ID)
57+
print(secret)
58+
```
59+
60+
### Revoke a Secret
61+
62+
Note: it isn't possible to revoke all account secrets, there must always be one valid secret. Attempting to do so will give a 403 error.
63+
64+
```python
65+
client.account.revoke_secret(MY_SECRET_ID)
66+
``` -->

subaccounts/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-subaccounts'
3+
version = '1.0.0'
4+
description = 'Vonage Subaccounts API package'
5+
readme = "README.md"
6+
authors = [{ name = "Vonage", email = "[email protected]" }]
7+
requires-python = ">=3.8"
8+
dependencies = [
9+
"vonage-http-client>=1.4.0",
10+
"vonage-utils>=1.1.2",
11+
"pydantic>=2.7.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"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python_sources()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .subaccounts import Subaccounts
2+
3+
__all__ = [
4+
'Subaccounts',
5+
]
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 SubaccountsError(VonageError):
5+
"""Indicates an error with the Subaccounts API package."""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from datetime import datetime
2+
from typing import Optional
3+
4+
from pydantic import BaseModel, Field
5+
6+
7+
class VonageAccount(BaseModel):
8+
api_key: str
9+
name: str
10+
primary_account_api_key: str
11+
use_primary_account_balance: bool
12+
created_at: datetime
13+
suspended: bool
14+
balance: Optional[float]
15+
credit_limit: Optional[float]
16+
17+
18+
class PrimaryAccount(VonageAccount): ...
19+
20+
21+
class Subaccount(VonageAccount): ...
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import List, Union
2+
from pydantic import validate_call
3+
from vonage_http_client.http_client import HttpClient
4+
5+
# from .responses import Balance, SettingsResponse, TopUpResponse, VonageApiSecret
6+
7+
8+
class Subaccounts:
9+
"""Class containing methods to manage Vonage subaccounts."""
10+
11+
def __init__(self, http_client: HttpClient) -> None:
12+
self._http_client = http_client
13+
self._auth_type = 'basic'
14+
15+
@property
16+
def http_client(self) -> HttpClient:
17+
"""The HTTP client used to make requests to the Users API.
18+
19+
Returns:
20+
HttpClient: The HTTP client used to make requests to the Users API.
21+
"""
22+
return self._http_client
23+
24+
def list_subaccounts(self) -> Tuple[PrimaryAccount, List[Subaccount]]:
25+
"""List all subaccounts associated with the primary account.
26+
27+
Returns:
28+
List[Union[PrimaryAccount, Subaccount]]: List of PrimaryAccount and Subaccount objects.
29+
"""
30+
response = self._http_client.get(
31+
self._http_client.api_host,
32+
f'/accounts/{self._http_client.auth.api_key}/subaccounts',
33+
auth_type=self._auth_type,
34+
)
35+
accounts = []
36+
# accounts.append(PrimaryAccount(**response['_embedded']['account']))
37+
38+
# for element in response['_embedded']['accounts']:
39+
# if element['type'] == 'PRIMARY':
40+
# accounts.append(PrimaryAccount(**element))
41+
# else:
42+
# accounts.append(Subaccount(**element))
43+
44+
# return accounts

0 commit comments

Comments
 (0)