|
| 1 | +from pydantic import validate_call |
| 2 | +from vonage_http_client.http_client import HttpClient |
| 3 | + |
| 4 | +from .requests import Balance |
| 5 | +from .responses import SettingsResponse, TopUpResponse |
| 6 | + |
| 7 | + |
| 8 | +class Account: |
| 9 | + """Class containing methods for management of a Vonage account.""" |
| 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 | + @validate_call |
| 25 | + def get_balance(self) -> Balance: |
| 26 | + """Get the balance of the account. |
| 27 | +
|
| 28 | + Returns: |
| 29 | + Balance: Object containing the account balance and whether auto-reload is |
| 30 | + enabled for the account. |
| 31 | + """ |
| 32 | + |
| 33 | + response = self._http_client.get( |
| 34 | + self._http_client.rest_host, |
| 35 | + '/account/get-balance', |
| 36 | + auth_type=self._auth_type, |
| 37 | + ) |
| 38 | + return Balance(**response) |
| 39 | + |
| 40 | + @validate_call |
| 41 | + def top_up(self, trx: str) -> TopUpResponse: |
| 42 | + """Top-up the account balance. |
| 43 | +
|
| 44 | + Args: |
| 45 | + trx (str): The transaction reference of the transaction when auto-reload |
| 46 | + was enabled on your account. |
| 47 | +
|
| 48 | + Returns: |
| 49 | + TopUpResponse: Object containing the top-up response. |
| 50 | + """ |
| 51 | + |
| 52 | + response = self._http_client.post( |
| 53 | + self._http_client.rest_host, |
| 54 | + '/account/top-up', |
| 55 | + params={'trx': trx}, |
| 56 | + auth_type=self._auth_type, |
| 57 | + sent_data_type='form', |
| 58 | + ) |
| 59 | + return TopUpResponse(**response) |
| 60 | + |
| 61 | + @validate_call |
| 62 | + def update_default_sms_webhook( |
| 63 | + self, mo_callback_url: str = None, dr_callback_url: str = None |
| 64 | + ) -> SettingsResponse: |
| 65 | + """Update the default SMS webhook URLs for the account. |
| 66 | + In order to unset any default value, pass an empty string as the value. |
| 67 | +
|
| 68 | + Args: |
| 69 | + mo_callback_url (str, optional): The URL to which inbound SMS messages will be |
| 70 | + sent. |
| 71 | + dr_callback_url (str, optional): The URL to which delivery receipts will be sent. |
| 72 | +
|
| 73 | + Returns: |
| 74 | + SettingsResponse: Object containing the response to the settings update. |
| 75 | + """ |
| 76 | + |
| 77 | + params = {} |
| 78 | + if mo_callback_url is not None: |
| 79 | + params['moCallbackUrl'] = mo_callback_url |
| 80 | + if dr_callback_url is not None: |
| 81 | + params['drCallbackUrl'] = dr_callback_url |
| 82 | + |
| 83 | + response = self._http_client.post( |
| 84 | + self._http_client.rest_host, |
| 85 | + '/account/settings', |
| 86 | + params=params, |
| 87 | + auth_type=self._auth_type, |
| 88 | + sent_data_type='form', |
| 89 | + ) |
| 90 | + return SettingsResponse(**response) |
| 91 | + |
| 92 | + def list_secrets(self) -> SecretList: |
| 93 | + """List all secrets associated with the account. |
| 94 | +
|
| 95 | + Returns: |
| 96 | + SecretList: List of Secret objects. |
| 97 | + """ |
| 98 | + pass |
0 commit comments