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