|
1 | 1 | from .errors import PricingTypeError
|
2 | 2 |
|
| 3 | +from deprecated import deprecated |
3 | 4 | class Account:
|
| 5 | + account_auth_type = 'params' |
| 6 | + pricing_auth_type = 'params' |
| 7 | + secrets_auth_type = 'header' |
| 8 | + |
4 | 9 | allowed_pricing_types = {'sms', 'sms-transit', 'voice'}
|
5 | 10 |
|
6 | 11 | def __init__(self, client):
|
7 | 12 | self._client = client
|
8 | 13 |
|
9 | 14 | def get_balance(self):
|
10 |
| - return self._client.get(self._client.host(), "/account/get-balance") |
| 15 | + return self._client.get(self._client.host(), "/account/get-balance", auth_type=Account.account_auth_type) |
11 | 16 |
|
12 | 17 | def topup(self, params=None, **kwargs):
|
13 |
| - return self._client.post(self._client.host(), "/account/top-up", params or kwargs) |
| 18 | + return self._client.post( |
| 19 | + self._client.host(), |
| 20 | + "/account/top-up", |
| 21 | + params or kwargs, |
| 22 | + auth_type=Account.account_auth_type, |
| 23 | + body_is_json=False, |
| 24 | + ) |
14 | 25 |
|
15 | 26 | def get_country_pricing(self, country_code: str, type: str = 'sms'):
|
16 | 27 | self._check_allowed_pricing_type(type)
|
17 | 28 | return self._client.get(
|
18 |
| - self._client.host(), f"/account/get-pricing/outbound/{type}", {"country": country_code} |
| 29 | + self._client.host(), |
| 30 | + f"/account/get-pricing/outbound/{type}", |
| 31 | + {"country": country_code}, |
| 32 | + auth_type=Account.pricing_auth_type |
19 | 33 | )
|
20 | 34 |
|
21 | 35 | def get_all_countries_pricing(self, type: str = 'sms'):
|
22 | 36 | self._check_allowed_pricing_type(type)
|
23 | 37 | return self._client.get(
|
24 |
| - self._client.host(), f"/account/get-full-pricing/outbound/{type}" |
| 38 | + self._client.host(), f"/account/get-full-pricing/outbound/{type}", auth_type=Account.pricing_auth_type |
25 | 39 | )
|
26 | 40 |
|
27 | 41 | def get_prefix_pricing(self, prefix: str, type: str = 'sms'):
|
28 | 42 | self._check_allowed_pricing_type(type)
|
29 | 43 | return self._client.get(
|
30 |
| - self._client.host(), f"/account/get-prefix-pricing/outbound/{type}", {"prefix": prefix} |
| 44 | + self._client.host(), |
| 45 | + f"/account/get-prefix-pricing/outbound/{type}", |
| 46 | + {"prefix": prefix}, |
| 47 | + auth_type=Account.pricing_auth_type, |
31 | 48 | )
|
32 | 49 |
|
| 50 | + @deprecated(version='3.0.0', reason='The "account/get-phone-pricing" endpoint is deprecated.') |
33 | 51 | def get_sms_pricing(self, number: str):
|
34 | 52 | return self._client.get(
|
35 |
| - self._client.host(), "/account/get-phone-pricing/outbound/sms", {"phone": number} |
| 53 | + self._client.host(), |
| 54 | + "/account/get-phone-pricing/outbound/sms", |
| 55 | + {"phone": number}, |
| 56 | + auth_type=Account.pricing_auth_type, |
36 | 57 | )
|
37 | 58 |
|
| 59 | + @deprecated(version='3.0.0', reason='The "account/get-phone-pricing" endpoint is deprecated.') |
38 | 60 | def get_voice_pricing(self, number: str):
|
39 | 61 | return self._client.get(
|
40 |
| - self._client.host(), "/account/get-phone-pricing/outbound/voice", {"phone": number} |
| 62 | + self._client.host(), |
| 63 | + "/account/get-phone-pricing/outbound/voice", |
| 64 | + {"phone": number}, |
| 65 | + auth_type=Account.pricing_auth_type, |
41 | 66 | )
|
42 | 67 |
|
43 | 68 | def update_default_sms_webhook(self, params=None, **kwargs):
|
44 |
| - return self._client.post(self._client.host(), "/account/settings", params or kwargs) |
| 69 | + return self._client.post( |
| 70 | + self._client.host(), |
| 71 | + "/account/settings", |
| 72 | + params or kwargs, |
| 73 | + auth_type=Account.account_auth_type, |
| 74 | + body_is_json=False, |
| 75 | + ) |
45 | 76 |
|
46 | 77 | def list_secrets(self, api_key):
|
47 | 78 | return self._client.get(
|
48 | 79 | self._client.api_host(),
|
49 | 80 | f"/accounts/{api_key}/secrets",
|
50 |
| - header_auth=True, |
| 81 | + auth_type=Account.secrets_auth_type, |
51 | 82 | )
|
52 | 83 |
|
53 | 84 | def get_secret(self, api_key, secret_id):
|
54 | 85 | return self._client.get(
|
55 | 86 | self._client.api_host(),
|
56 | 87 | f"/accounts/{api_key}/secrets/{secret_id}",
|
57 |
| - header_auth=True, |
| 88 | + auth_type=Account.secrets_auth_type, |
58 | 89 | )
|
59 | 90 |
|
60 | 91 | def create_secret(self, api_key, secret):
|
61 | 92 | body = {"secret": secret}
|
62 |
| - return self._client._post_json( |
63 |
| - self._client.api_host(), f"/accounts/{api_key}/secrets", body |
| 93 | + return self._client.post( |
| 94 | + self._client.api_host(), |
| 95 | + f"/accounts/{api_key}/secrets", |
| 96 | + body, |
| 97 | + auth_type=Account.secrets_auth_type, |
| 98 | + body_is_json=False, |
64 | 99 | )
|
65 | 100 |
|
66 | 101 | def revoke_secret(self, api_key, secret_id):
|
67 | 102 | return self._client.delete(
|
68 | 103 | self._client.api_host(),
|
69 | 104 | f"/accounts/{api_key}/secrets/{secret_id}",
|
70 |
| - header_auth=True, |
| 105 | + auth_type=Account.secrets_auth_type, |
71 | 106 | )
|
72 | 107 |
|
73 | 108 | def _check_allowed_pricing_type(self, type):
|
74 |
| - if type not in self.allowed_pricing_types: |
| 109 | + if type not in Account.allowed_pricing_types: |
75 | 110 | raise PricingTypeError('Invalid pricing type specified.')
|
0 commit comments