Skip to content

Commit 058b480

Browse files
authored
Merge pull request #218 from Vonage/improve-rest-calls
Improve rest calls and remove deprecated methods
2 parents cbcb1b3 + 8acffc9 commit 058b480

25 files changed

+649
-411
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.8.0
2+
current_version = 3.0.0
33
commit = True
44
tag = False
55

CHANGES.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
# 3.0.0 (Unreleased, WIP)
2-
- Removed automatic client creation when instantiating an `sms`, `voice` or `verify` object
3-
- Removed methods to call the Message Search API, which has been retired by Vonage
4-
- Added `get_all_countries_pricing` method to `Account` object
5-
- Added a `type` parameter for pricing calls, so `sms` or `voice` pricing can now be chosen
6-
- Removed deprecated voice and number insight methods from `voice.py` and `number_insight.py`
7-
- Removed deprecated methods from `client.py` that are now available in specific modules related to each of the available Vonage APIs
1+
# 3.0.0
2+
3+
Breaking changes:
4+
- Removed deprecated methods from `client.py` that are now available in specific modules related to each of the available Vonage APIs. E.g. to call the number insight API, the methods are now called in this way: `client.number_insight.get_basic_number_insight(...)`, or by instantiating the `NumberInsight` class directly: `ni = vonage.NumberInsight(client)`, `ni.get_basic_number_insight(...)` etc.
5+
- Removed automatic client creation when instantiating an `sms`, `voice` or `verify` object. You can now use these APIs from a client instance you create (e.g. `client.sms.send_message()`) or pass in a client to the API class to create it (e.g. `sms = vonage.Sms(client)`), as has been the case since v2.7.0 of the SDK.
6+
- Removed methods to call the Message Search API, which has been retired by Vonage.
7+
- Removed deprecated voice and number insight methods from `voice.py` (`initiate_call, initiate_tts_call and initiate_tts_prompt_call`) and `number_insight.py` (`request_number_insight`).
8+
- Deprecated the ApplicationV2 class and created an Application class with the same methods to bring the naming in line with other classes. This can be called from the client object with `client.application.create_application(...)` etc. or directly with `application = vonage.Application(client)`, `application.create_application(...)` etc.
9+
- Deprecated old Pricing API methods `get_sms_pricing` and `get_voice_pricing`.
10+
- Deprecated Redact class as it's a dev preview product that's unsupported in the SDK and will be removed in a later release.
11+
- Renamed the `Account.delete_secret()` method to `revoke_secret()` to bring it in line with what is described in our documentation.
12+
13+
Enhancements:
14+
- Added `get_all_countries_pricing` method to `Account` object.
15+
- Added a `type` parameter for pricing calls, so `sms` or `voice` pricing can now be chosen.
16+
- Added `max_retries`, `timeout`, `pool_connections` and `pool_maxsize` optional keyword arguments to the `Client` class, which can now be specified on instantiation and used in the API calls made with the client.
817

918
# 2.8.0
1019
- Added Messages API v1.0 support. Messages API can now be used by calling the `client.messages.send_message()` method.

README.md

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ response = client.sms.send_message({
142142
client.sms.submit_sms_conversion(response['message-id'])
143143
```
144144

145+
### Update the default SMS webhook URLs for callbacks/delivery reciepts
146+
```python
147+
client.sms.update_default_sms_webhook({
148+
'moCallBackUrl': 'new.url.vonage.com', # Default inbound sms webhook url
149+
'drCallBackUrl': 'different.url.vonage.com' # Delivery receipt url
150+
}})
151+
```
152+
153+
The delivery receipt URL can be unset by sending an empty string.
154+
145155
## Messages API
146156

147157
The Messages API is an API that allows you to send messages via SMS, MMS, WhatsApp, Messenger and Viber. Call the API from your Python code by
@@ -458,6 +468,37 @@ client.number_insight.get_advanced_number_insight(number='447700900000')
458468

459469
Docs: [https://developer.nexmo.com/api/number-insight#getNumberInsightAdvanced](https://developer.nexmo.com/api/number-insight?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library#getNumberInsightAdvanced)
460470

471+
## Account API
472+
473+
### Get your account balance
474+
```python
475+
client.account.get_balance()
476+
```
477+
478+
### Top up your account
479+
This feature is only enabled when you enable auto-reload for your account in the dashboard.
480+
```python
481+
# trx is the reference from when auto-reload was enabled and money was added
482+
client.account.topup(trx=transaction_reference)
483+
```
484+
485+
## Pricing API
486+
487+
### Get pricing for a single country
488+
```python
489+
client.get_country_pricing(country_code='GB', type='sms') # Default type is sms
490+
```
491+
492+
### Get pricing for all countries
493+
```python
494+
client.get_all_countries_pricing(type='sms') # Default type is sms, can be voice
495+
```
496+
497+
### Get pricing for a specific dialling prefix
498+
```python
499+
client.get_country_pricing(prefix='44', type='sms')
500+
```
501+
461502
## Managing Secrets
462503

463504
An API is provided to allow you to rotate your API secrets. You can create a new secret (up to a maximum of two secrets) and delete the existing one once all applications have been updated.
@@ -468,6 +509,12 @@ An API is provided to allow you to rotate your API secrets. You can create a new
468509
secrets = client.account.list_secrets(API_KEY)
469510
```
470511

512+
### Get information about a specific secret
513+
514+
```python
515+
secrets = client.account.get_secret(API_KEY, secret_id)
516+
```
517+
471518
### Create A New Secret
472519

473520
Create a new secret (the created dates will help you know which is which):
@@ -481,47 +528,47 @@ client.account.create_secret(API_KEY, 'awes0meNewSekret!!;');
481528
Delete the old secret (any application still using these credentials will stop working):
482529

483530
```python
484-
client.account.delete_secret(API_KEY, 'my-secret-id')
531+
client.account.revoke_secret(API_KEY, 'my-secret-id')
485532
```
486533

487534
## Application API
488535

489536
### Create an application
490537

491538
```python
492-
response = client.application_v2.create_application({name='Example App', type='voice'})
539+
response = client.application.create_application({name='Example App', type='voice'})
493540
```
494541

495542
Docs: [https://developer.nexmo.com/api/application.v2#createApplication](https://developer.nexmo.com/api/application.v2#createApplication?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library#create-an-application)
496543

497544
### Retrieve a list of applications
498545

499546
```python
500-
response = client.application_v2.list_applications()
547+
response = client.application.list_applications()
501548
```
502549

503550
Docs: [https://developer.nexmo.com/api/application.v2#listApplication](https://developer.nexmo.com/api/application.v2#listApplication?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library#retrieve-your-applications)
504551

505552
### Retrieve a single application
506553

507554
```python
508-
response = client.application_v2.get_application(uuid)
555+
response = client.application.get_application(uuid)
509556
```
510557

511558
Docs: [https://developer.nexmo.com/api/application.v2#getApplication](https://developer.nexmo.com/api/application.v2#getApplication?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library#retrieve-an-application)
512559

513560
### Update an application
514561

515562
```python
516-
response = client.application_v2.update_application(uuid, answer_method='POST')
563+
response = client.application.update_application(uuid, answer_method='POST')
517564
```
518565

519566
Docs: [https://developer.nexmo.com/api/application.v2#updateApplication](https://developer.nexmo.com/api/application.v2#updateApplication?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library#update-an-application)
520567

521568
### Delete an application
522569

523570
```python
524-
response = client.application_v2.delete_application(uuid)
571+
response = client.application.delete_application(uuid)
525572
```
526573

527574
Docs: [https://developer.nexmo.com/api/application.v2#deleteApplication](https://developer.nexmo.com/api/application.v2#deleteApplication?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library#destroy-an-application)
@@ -608,7 +655,7 @@ The following is a list of Vonage APIs and whether the Python SDK provides suppo
608655
| Number Insight API | General Availability ||
609656
| Number Management API | General Availability ||
610657
| Pricing API | General Availability ||
611-
| Redact API | General Availability | |
658+
| Redact API | Developer Preview | |
612659
| Reports API | Beta ||
613660
| SMS API | General Availability ||
614661
| Verify API | General Availability ||

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
# built documents.
6767
#
6868
# The short X.Y version.
69-
version = "2.8.0"
69+
version = "3.0.0"
7070
# The full version, including alpha/beta/rc tags.
71-
release = "2.8.0"
71+
release = "3.0.0"
7272

7373
# The language for content autogenerated by Sphinx. Refer to documentation
7474
# for a list of supported languages.
@@ -143,7 +143,7 @@
143143
# The name for this set of Sphinx documents.
144144
# "<project> v<release> documentation" by default.
145145
#
146-
# html_title = u'Vonage v2.8.0'
146+
# html_title = u'Vonage v3.0.0'
147147

148148
# A shorter title for the navigation bar. Default is the same as html_title.
149149
#

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name="vonage",
14-
version="2.8.0",
14+
version="3.0.0",
1515
description="Vonage Server SDK for Python",
1616
long_description=long_description,
1717
long_description_content_type="text/markdown",

src/vonage/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .client import *
22

3-
__version__ = "2.8.0"
3+
__version__ = "3.0.0"

src/vonage/account.py

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,110 @@
11
from .errors import PricingTypeError
22

3+
from deprecated import deprecated
34
class Account:
5+
account_auth_type = 'params'
6+
pricing_auth_type = 'params'
7+
secrets_auth_type = 'header'
8+
49
allowed_pricing_types = {'sms', 'sms-transit', 'voice'}
510

611
def __init__(self, client):
712
self._client = client
813

914
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)
1116

1217
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+
)
1425

1526
def get_country_pricing(self, country_code: str, type: str = 'sms'):
1627
self._check_allowed_pricing_type(type)
1728
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
1933
)
2034

2135
def get_all_countries_pricing(self, type: str = 'sms'):
2236
self._check_allowed_pricing_type(type)
2337
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
2539
)
2640

2741
def get_prefix_pricing(self, prefix: str, type: str = 'sms'):
2842
self._check_allowed_pricing_type(type)
2943
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,
3148
)
3249

50+
@deprecated(version='3.0.0', reason='The "account/get-phone-pricing" endpoint is deprecated.')
3351
def get_sms_pricing(self, number: str):
3452
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,
3657
)
3758

59+
@deprecated(version='3.0.0', reason='The "account/get-phone-pricing" endpoint is deprecated.')
3860
def get_voice_pricing(self, number: str):
3961
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,
4166
)
4267

4368
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+
)
4576

4677
def list_secrets(self, api_key):
4778
return self._client.get(
4879
self._client.api_host(),
4980
f"/accounts/{api_key}/secrets",
50-
header_auth=True,
81+
auth_type=Account.secrets_auth_type,
5182
)
5283

5384
def get_secret(self, api_key, secret_id):
5485
return self._client.get(
5586
self._client.api_host(),
5687
f"/accounts/{api_key}/secrets/{secret_id}",
57-
header_auth=True,
88+
auth_type=Account.secrets_auth_type,
5889
)
5990

6091
def create_secret(self, api_key, secret):
6192
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,
6499
)
65100

66101
def revoke_secret(self, api_key, secret_id):
67102
return self._client.delete(
68103
self._client.api_host(),
69104
f"/accounts/{api_key}/secrets/{secret_id}",
70-
header_auth=True,
105+
auth_type=Account.secrets_auth_type,
71106
)
72107

73108
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:
75110
raise PricingTypeError('Invalid pricing type specified.')

0 commit comments

Comments
 (0)