Skip to content

Commit 9ffcb31

Browse files
authored
Merge pull request #219 from Vonage/v3-release
V3 release
2 parents 5f98d04 + 058b480 commit 9ffcb31

39 files changed

+860
-1969
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

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ repos:
33
rev: v2.5.4
44
hooks:
55
- id: trailing-whitespace
6-
language_version: python3.6
6+
language_version: python3.7
77
- repo: https://github.com/ambv/black
88
rev: 18.6b4
99
hooks:
1010
- id: black
11-
language_version: python3.6
11+
language_version: python3.7

CHANGES.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
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.
17+
118
# 2.8.0
2-
- Added Messages API v1.0 support. Messages API can now be used by calling the client.messages.send_message() method.
19+
- Added Messages API v1.0 support. Messages API can now be used by calling the `client.messages.send_message()` method.
320

421
# 2.7.0
522
- Moved some client methods into their own classes: `account.py, application.py,

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
.PHONY: clean test build coverage install requirements release
22

3-
clean:
4-
rm -rf dist build
5-
63
coverage:
74
pytest -v --cov
85
coverage html
96

107
test:
118
pytest -v
129

10+
clean:
11+
rm -rf dist build
12+
1313
build:
1414
python -m build
1515

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
#

requirements.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ pytest==7.1.1
33
pytest-cov==3.0.0
44
responses==0.20.0
55
coveralls
6-
glom==22.1.0
6+
glom==22.1.0
7+
8+
bump2version
9+
build
10+
twine

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: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,110 @@
1+
from .errors import PricingTypeError
2+
3+
from deprecated import deprecated
14
class Account:
5+
account_auth_type = 'params'
6+
pricing_auth_type = 'params'
7+
secrets_auth_type = 'header'
8+
9+
allowed_pricing_types = {'sms', 'sms-transit', 'voice'}
10+
211
def __init__(self, client):
312
self._client = client
413

514
def get_balance(self):
6-
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)
716

817
def topup(self, params=None, **kwargs):
9-
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+
)
25+
26+
def get_country_pricing(self, country_code: str, type: str = 'sms'):
27+
self._check_allowed_pricing_type(type)
28+
return self._client.get(
29+
self._client.host(),
30+
f"/account/get-pricing/outbound/{type}",
31+
{"country": country_code},
32+
auth_type=Account.pricing_auth_type
33+
)
1034

11-
def get_country_pricing(self, country_code):
35+
def get_all_countries_pricing(self, type: str = 'sms'):
36+
self._check_allowed_pricing_type(type)
1237
return self._client.get(
13-
self._client.host(), "/account/get-pricing/outbound", {"country": country_code}
38+
self._client.host(), f"/account/get-full-pricing/outbound/{type}", auth_type=Account.pricing_auth_type
1439
)
1540

16-
def get_prefix_pricing(self, prefix):
41+
def get_prefix_pricing(self, prefix: str, type: str = 'sms'):
42+
self._check_allowed_pricing_type(type)
1743
return self._client.get(
18-
self._client.host(), "/account/get-prefix-pricing/outbound", {"prefix": prefix}
44+
self._client.host(),
45+
f"/account/get-prefix-pricing/outbound/{type}",
46+
{"prefix": prefix},
47+
auth_type=Account.pricing_auth_type,
1948
)
2049

21-
def get_sms_pricing(self, number):
50+
@deprecated(version='3.0.0', reason='The "account/get-phone-pricing" endpoint is deprecated.')
51+
def get_sms_pricing(self, number: str):
2252
return self._client.get(
23-
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,
2457
)
2558

26-
def get_voice_pricing(self, number):
59+
@deprecated(version='3.0.0', reason='The "account/get-phone-pricing" endpoint is deprecated.')
60+
def get_voice_pricing(self, number: str):
2761
return self._client.get(
28-
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,
2966
)
3067

3168
def update_default_sms_webhook(self, params=None, **kwargs):
32-
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+
)
3376

3477
def list_secrets(self, api_key):
3578
return self._client.get(
3679
self._client.api_host(),
3780
f"/accounts/{api_key}/secrets",
38-
header_auth=True,
81+
auth_type=Account.secrets_auth_type,
3982
)
4083

4184
def get_secret(self, api_key, secret_id):
4285
return self._client.get(
4386
self._client.api_host(),
4487
f"/accounts/{api_key}/secrets/{secret_id}",
45-
header_auth=True,
88+
auth_type=Account.secrets_auth_type,
4689
)
4790

4891
def create_secret(self, api_key, secret):
4992
body = {"secret": secret}
50-
return self._client._post_json(
51-
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,
5299
)
53100

54101
def revoke_secret(self, api_key, secret_id):
55102
return self._client.delete(
56103
self._client.api_host(),
57104
f"/accounts/{api_key}/secrets/{secret_id}",
58-
header_auth=True,
105+
auth_type=Account.secrets_auth_type,
59106
)
107+
108+
def _check_allowed_pricing_type(self, type):
109+
if type not in Account.allowed_pricing_types:
110+
raise PricingTypeError('Invalid pricing type specified.')

0 commit comments

Comments
 (0)