-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
861 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
from .errors import InvalidSecretError | ||
from .requests import ( | ||
ListTransfersFilter, | ||
ModifySubaccountOptions, | ||
SubaccountOptions, | ||
TransferNumberRequest, | ||
TransferRequest, | ||
) | ||
from .responses import ( | ||
ListSubaccountsResponse, | ||
NewSubaccount, | ||
PrimaryAccount, | ||
Subaccount, | ||
Transfer, | ||
TransferNumberResponse, | ||
VonageAccount, | ||
) | ||
from .subaccounts import Subaccounts | ||
|
||
__all__ = [ | ||
'Subaccounts', | ||
'InvalidSecretError', | ||
'ListTransfersFilter', | ||
'SubaccountOptions', | ||
'ModifySubaccountOptions', | ||
'TransferNumberRequest', | ||
'TransferRequest', | ||
'VonageAccount', | ||
'PrimaryAccount', | ||
'Subaccount', | ||
'ListSubaccountsResponse', | ||
'NewSubaccount', | ||
'Transfer', | ||
'TransferNumberResponse', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from vonage_utils.errors import VonageError | ||
|
||
|
||
class SubaccountsError(VonageError): | ||
"""Indicates an error with the Subaccounts API package.""" | ||
class InvalidSecretError(VonageError): | ||
"""Indicates that the secret provided was invalid.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import re | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field, field_validator | ||
from vonage_subaccounts.errors import InvalidSecretError | ||
|
||
|
||
class SubaccountOptions(BaseModel): | ||
name: str = Field(..., min_length=1, max_length=80) | ||
secret: Optional[str] = None | ||
use_primary_account_balance: Optional[bool] = None | ||
|
||
@field_validator('secret') | ||
@classmethod | ||
def check_valid_secret(cls, v): | ||
if not _is_valid_secret(v): | ||
raise InvalidSecretError( | ||
'Secret must be 8-25 characters long and contain at least one uppercase ' | ||
'letter, one lowercase letter, and one digit.' | ||
) | ||
return v | ||
|
||
|
||
def _is_valid_secret(secret: str) -> bool: | ||
if len(secret) < 8 or len(secret) > 25: | ||
return False | ||
if not re.search(r'[a-z]', secret): | ||
return False | ||
if not re.search(r'[A-Z]', secret): | ||
return False | ||
if not re.search(r'\d', secret): | ||
return False | ||
return True | ||
|
||
|
||
class ModifySubaccountOptions(BaseModel): | ||
suspended: Optional[bool] = None | ||
use_primary_account_balance: Optional[bool] = None | ||
name: Optional[str] = None | ||
|
||
|
||
class ListTransfersFilter(BaseModel): | ||
start_date: str | ||
end_date: Optional[str] = None | ||
subaccount: Optional[str] = None | ||
|
||
|
||
class TransferRequest(BaseModel): | ||
from_: str = Field(..., serialization_alias='from') | ||
to: str | ||
amount: float | ||
reference: Optional[str] = None | ||
|
||
|
||
class TransferNumberRequest(BaseModel): | ||
from_: str = Field(..., serialization_alias='from') | ||
to: str | ||
number: str | ||
country: Optional[str] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
from typing import Optional, Union | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class VonageAccount(BaseModel): | ||
api_key: str | ||
name: str | ||
primary_account_api_key: str | ||
use_primary_account_balance: bool | ||
created_at: datetime | ||
created_at: str | ||
suspended: bool | ||
balance: Optional[float] | ||
credit_limit: Optional[float] | ||
credit_limit: Optional[Union[int, float]] | ||
|
||
|
||
class PrimaryAccount(VonageAccount): | ||
... | ||
|
||
|
||
class Subaccount(VonageAccount): | ||
primary_account_api_key: str | ||
use_primary_account_balance: bool | ||
|
||
|
||
class ListSubaccountsResponse(BaseModel): | ||
primary_account: PrimaryAccount | ||
subaccounts: list[Subaccount] | ||
total_balance: float | ||
total_credit_limit: Union[int, float] | ||
|
||
|
||
class NewSubaccount(Subaccount): | ||
secret: str | ||
|
||
|
||
class PrimaryAccount(VonageAccount): ... | ||
class Transfer(BaseModel): | ||
id: str | ||
amount: float | ||
from_: str = Field(..., validation_alias='from') | ||
to: str | ||
created_at: str | ||
reference: Optional[str] = None | ||
|
||
|
||
class Subaccount(VonageAccount): ... | ||
class TransferNumberResponse(BaseModel): | ||
number: str | ||
country: str | ||
from_: str = Field(..., validation_alias='from') | ||
to: str |
Oops, something went wrong.