Skip to content

Commit f11467c

Browse files
additional namespace changes
1 parent 3d0b330 commit f11467c

File tree

3 files changed

+87
-48
lines changed

3 files changed

+87
-48
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Then construct a client object with your key and secret:
5252
client = vonage.Client(key=api_key, secret=api_secret)
5353
```
5454

55-
For production, you can specify the `NEXMO_API_KEY` and `NEXMO_API_SECRET`
55+
For production, you can specify the `VONAGE_API_KEY` and `VONAGE_API_SECRET`
5656
environment variables instead of specifying the key and secret explicitly.
5757

5858
For newer endpoints that support JWT authentication such as the Voice API,
@@ -63,7 +63,7 @@ client = vonage.Client(application_id=application_id, private_key=private_key)
6363
```
6464

6565
To check signatures for incoming webhook requests, you'll also need
66-
to specify the `signature_secret` argument (or the `NEXMO_SIGNATURE_SECRET`
66+
to specify the `signature_secret` argument (or the `VONAGE_SIGNATURE_SECRET`
6767
environment variable).
6868

6969
## SMS API
@@ -91,20 +91,20 @@ import vonage #then you can use vonage.Sms() to create an instance
9191

9292
```python
9393
#Option 1 - pass key and secret to the constructor
94-
sms = Sms(key=NEXMO_API_KEY, secret=NEXMO_API_SECRET)
94+
sms = Sms(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
9595

9696
#Option 2 - Create a client instance and then pass the client to the Sms instance
97-
client = Client(key=NEXMO_API_KEY, secret=NEXMO_API_SECRET)
97+
client = Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
9898
sms = Sms(client)
9999
```
100100

101101
### Send an SMS
102102

103103
```python
104104
from vonage import Sms
105-
sms = Sms(key=NEXMO_API_KEY, secret=NEXMO_API_SECRET)
105+
sms = Sms(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
106106
sms.send_message({
107-
"from": NEXMO_BRAND_NAME,
107+
"from": VONAGE_BRAND_NAME,
108108
"to": TO_NUMBER,
109109
"text": "A text message sent using the Vonage SMS API",
110110
})
@@ -114,7 +114,7 @@ sms.send_message({
114114

115115
```python
116116
sms.send_message({
117-
'from': NEXMO_BRAND_NAME,
117+
'from': VONAGE_BRAND_NAME,
118118
'to': TO_NUMBER,
119119
'text': 'こんにちは世界',
120120
'type': 'unicode',
@@ -125,10 +125,10 @@ sms.send_message({
125125

126126
```python
127127
from vonage import Client, Sms
128-
client = Client(key=NEXMO_API_KEY, secret=NEXMO_SECRET)
128+
client = Client(key=VONAGE_API_KEY, secret=VONAGE_SECRET)
129129
sms = Sms(client)
130130
response = sms.send_message({
131-
'from': NEXMO_BRAND_NAME,
131+
'from': VONAGE_BRAND_NAME,
132132
'to': TO_NUMBER,
133133
'text': 'Hi from Vonage'
134134
})
@@ -289,10 +289,10 @@ import vonage #then you can use vonage.Verify() to create an instance
289289

290290
```python
291291
#First way - pass key and secret to the constructor
292-
verify = Verify(key=NEXMO_API_KEY, secret=NEXMO_API_SECRET)
292+
verify = Verify(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
293293
294294
#Second way - Create a client instance and then pass the client to the Verify contructor
295-
client = Client(key=NEXMO_API_KEY, secret=NEXMO_API_SECRET)
295+
client = Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
296296
verify = Verify(client)
297297
```
298298

docs/quickstart.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Then construct a client object with your key and secret:
4646
4747
client = vonage.Client(key=api_key, secret=api_secret)
4848
49-
For production, you can specify the ``NEXMO_API_KEY`` and
50-
``NEXMO_API_SECRET`` environment variables instead of specifying the key
49+
For production, you can specify the ``VONAGE_API_KEY`` and
50+
``VONAGE_API_SECRET`` environment variables instead of specifying the key
5151
and secret explicitly.
5252

5353
For newer endpoints that support JWT authentication such as the Voice
@@ -60,7 +60,7 @@ arguments:
6060
6161
In order to check signatures for incoming webhook requests, you'll also
6262
need to specify the ``signature_secret`` argument (or the
63-
``NEXMO_SIGNATURE_SECRET`` environment variable).
63+
``VONAGE_SIGNATURE_SECRET`` environment variable).
6464

6565
If the argument ``signature_method`` is omitted, it will default to the md5 hash
6666
algorithm. Otherwise, it will use the selected method as in md5, sha1, sha256 or

src/vonage/__init__.py

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ def __init__(
7777
app_name=None,
7878
app_version=None,
7979
):
80-
self.api_key = key or os.environ.get("NEXMO_API_KEY", None)
80+
self.api_key = key or os.environ.get("VONAGE_API_KEY", None)
8181

82-
self.api_secret = secret or os.environ.get("NEXMO_API_SECRET", None)
82+
self.api_secret = secret or os.environ.get("VONAGE_API_SECRET", None)
8383

8484
self.signature_secret = signature_secret or os.environ.get(
85-
"NEXMO_SIGNATURE_SECRET", None
85+
"VONAGE_SIGNATURE_SECRET", None
8686
)
8787

8888
self.signature_method = signature_method or os.environ.get(
89-
"NEXMO_SIGNATURE_METHOD", None
89+
"VONAGE_SIGNATURE_METHOD", None
9090
)
9191

9292
if self.signature_method in {"md5", "sha1", "sha256", "sha512"}:
@@ -99,8 +99,8 @@ def __init__(
9999
if isinstance(self.private_key, string_types) and "\n" not in self.private_key:
100100
with open(self.private_key, "rb") as key_file:
101101
self.private_key = key_file.read()
102-
103-
self.__host_pattern = '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$'
102+
103+
self.__host_pattern = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$"
104104

105105
self.__host = "rest.nexmo.com"
106106

@@ -128,37 +128,39 @@ def __init__(
128128
self.application_v2 = ApplicationV2(api_server)
129129

130130
self.session = requests.Session()
131-
131+
132132
# Get and Set __host attribute
133133
def host(self, value=None):
134134
if value is None:
135135
return self.__host
136-
elif not re.match(self.__host_pattern,value):
137-
raise Exception('Error: Invalid format for host')
136+
elif not re.match(self.__host_pattern, value):
137+
raise Exception("Error: Invalid format for host")
138138
else:
139139
self.__host = value
140-
140+
141141
# Gets And sets __api_host attribute
142142
def api_host(self, value=None):
143143
if value is None:
144144
return self.__api_host
145-
elif not re.match(self.__host_pattern,value):
146-
raise Exception('Error: Invalid format for api_host')
145+
elif not re.match(self.__host_pattern, value):
146+
raise Exception("Error: Invalid format for api_host")
147147
else:
148148
self.__api_host = value
149149

150150
def auth(self, params=None, **kwargs):
151151
self.auth_params = params or kwargs
152152

153-
@deprecated(reason="vonage.Client#send_message is deprecated. Use Sms#send_message instead")
153+
@deprecated(
154+
reason="vonage.Client#send_message is deprecated. Use Sms#send_message instead"
155+
)
154156
def send_message(self, params):
155157
"""
156158
Send an SMS message.
157159
Requires a client initialized with `key` and either `secret` or `signature_secret`.
158160
::
159161
client.send_message({
160162
"to": MY_CELLPHONE,
161-
"from": MY_NEXMO_NUMBER,
163+
"from": MY_VONAGE_NUMBER,
162164
"text": "Hello From Nexmo!",
163165
})
164166
:param dict params: A dict of values described at `Send an SMS <https://developer.nexmo.com/api/sms#send-an-sms>`_
@@ -257,7 +259,9 @@ def get_event_alert_numbers(self):
257259
return self.get(self.host(), "/sc/us/alert/opt-in/query/json")
258260

259261
def resubscribe_event_alert_number(self, params=None, **kwargs):
260-
return self.post(self.host(), "/sc/us/alert/opt-in/manage/json", params or kwargs)
262+
return self.post(
263+
self.host(), "/sc/us/alert/opt-in/manage/json", params or kwargs
264+
)
261265

262266
def initiate_call(self, params=None, **kwargs):
263267
return self.post(self.host(), "/call/json", params or kwargs)
@@ -268,7 +272,9 @@ def initiate_tts_call(self, params=None, **kwargs):
268272
def initiate_tts_prompt_call(self, params=None, **kwargs):
269273
return self.post(self.api_host(), "/tts-prompt/json", params or kwargs)
270274

271-
@deprecated(reason="vonage.Client#start_verification is deprecated. Use Verify#start_verification instead")
275+
@deprecated(
276+
reason="vonage.Client#start_verification is deprecated. Use Verify#start_verification instead"
277+
)
272278
def start_verification(self, params=None, **kwargs):
273279
return self.post(self.api_host(), "/verify/json", params or kwargs)
274280

@@ -281,7 +287,9 @@ def send_verification_request(self, params=None, **kwargs):
281287

282288
return self.post(self.api_host(), "/verify/json", params or kwargs)
283289

284-
@deprecated(reason="vonage.Client#check_verification is deprecated. Use Verify#check instead")
290+
@deprecated(
291+
reason="vonage.Client#check_verification is deprecated. Use Verify#check instead"
292+
)
285293
def check_verification(self, request_id, params=None, **kwargs):
286294
return self.post(
287295
self.api_host(),
@@ -297,12 +305,16 @@ def check_verification_request(self, params=None, **kwargs):
297305
)
298306

299307
return self.post(self.api_host(), "/verify/check/json", params or kwargs)
300-
301-
@deprecated(reason="vonage.Client#start_psd2_verification_request is deprecated. Use Verify#psd2 instead")
308+
309+
@deprecated(
310+
reason="vonage.Client#start_psd2_verification_request is deprecated. Use Verify#psd2 instead"
311+
)
302312
def start_psd2_verification_request(self, params=None, **kwargs):
303313
return self.post(self.api_host(), "/verify/psd2/json", params or kwargs)
304314

305-
@deprecated(reason="vonage.Client#get_verification is deprecated. Use Verify#search instead")
315+
@deprecated(
316+
reason="vonage.Client#get_verification is deprecated. Use Verify#search instead"
317+
)
306318
def get_verification(self, request_id):
307319
return self.get(
308320
self.api_host(), "/verify/search/json", {"request_id": request_id}
@@ -319,15 +331,19 @@ def get_verification_request(self, request_id):
319331
self.api_host(), "/verify/search/json", {"request_id": request_id}
320332
)
321333

322-
@deprecated(reason="vonage.Client#cancel_verification is deprecated. Use Verify#cancel instead")
334+
@deprecated(
335+
reason="vonage.Client#cancel_verification is deprecated. Use Verify#cancel instead"
336+
)
323337
def cancel_verification(self, request_id):
324338
return self.post(
325339
self.api_host(),
326340
"/verify/control/json",
327341
{"request_id": request_id, "cmd": "cancel"},
328342
)
329343

330-
@deprecated(reason="vonage.Client#trigger_next_verification_event is deprecated. Use Verify#trigger_next_event instead")
344+
@deprecated(
345+
reason="vonage.Client#trigger_next_verification_event is deprecated. Use Verify#trigger_next_event instead"
346+
)
331347
def trigger_next_verification_event(self, request_id):
332348
return self.post(
333349
self.api_host(),
@@ -362,9 +378,13 @@ def get_number_insight(self, params=None, **kwargs):
362378
def get_async_advanced_number_insight(self, params=None, **kwargs):
363379
argoparams = params or kwargs
364380
if "callback" in argoparams:
365-
return self.get(self.api_host(), "/ni/advanced/async/json", params or kwargs)
381+
return self.get(
382+
self.api_host(), "/ni/advanced/async/json", params or kwargs
383+
)
366384
else:
367-
raise ClientError("Error: Callback needed for async advanced number insight")
385+
raise ClientError(
386+
"Error: Callback needed for async advanced number insight"
387+
)
368388

369389
def get_advanced_number_insight(self, params=None, **kwargs):
370390
return self.get(self.api_host(), "/ni/advanced/json", params or kwargs)
@@ -422,45 +442,63 @@ def delete_application(self, application_id):
422442
"/v1/applications/{application_id}".format(application_id=application_id),
423443
)
424444

425-
@deprecated(reason="vonage.Client#create_call is deprecated. Use Voice#create_call instead")
445+
@deprecated(
446+
reason="vonage.Client#create_call is deprecated. Use Voice#create_call instead"
447+
)
426448
def create_call(self, params=None, **kwargs):
427449
return self._jwt_signed_post("/v1/calls", params or kwargs)
428450

429-
@deprecated(reason="vonage.Client#get_calls is deprecated. Use Voice#get_calls instead")
451+
@deprecated(
452+
reason="vonage.Client#get_calls is deprecated. Use Voice#get_calls instead"
453+
)
430454
def get_calls(self, params=None, **kwargs):
431455
return self._jwt_signed_get("/v1/calls", params or kwargs)
432456

433-
@deprecated(reason="vonage.Client#get_call is deprecated. Use Voice#get_call instead")
457+
@deprecated(
458+
reason="vonage.Client#get_call is deprecated. Use Voice#get_call instead"
459+
)
434460
def get_call(self, uuid):
435461
return self._jwt_signed_get("/v1/calls/{uuid}".format(uuid=uuid))
436462

437-
@deprecated(reason="vonage.Client#update_call is deprecated. Use Voice#update_call instead")
463+
@deprecated(
464+
reason="vonage.Client#update_call is deprecated. Use Voice#update_call instead"
465+
)
438466
def update_call(self, uuid, params=None, **kwargs):
439467
return self._jwt_signed_put(
440468
"/v1/calls/{uuid}".format(uuid=uuid), params or kwargs
441469
)
442470

443-
@deprecated(reason="vonage.Client#send_audio is deprecated. Use Voice#send_audio instead")
471+
@deprecated(
472+
reason="vonage.Client#send_audio is deprecated. Use Voice#send_audio instead"
473+
)
444474
def send_audio(self, uuid, params=None, **kwargs):
445475
return self._jwt_signed_put(
446476
"/v1/calls/{uuid}/stream".format(uuid=uuid), params or kwargs
447477
)
448478

449-
@deprecated(reason="vonage.Client#stop_audio is deprecated. Use Voice#stop_audio instead")
479+
@deprecated(
480+
reason="vonage.Client#stop_audio is deprecated. Use Voice#stop_audio instead"
481+
)
450482
def stop_audio(self, uuid):
451483
return self._jwt_signed_delete("/v1/calls/{uuid}/stream".format(uuid=uuid))
452484

453-
@deprecated(reason="vonage.Client#send_speech is deprecated. Use Voice#send_speech instead")
485+
@deprecated(
486+
reason="vonage.Client#send_speech is deprecated. Use Voice#send_speech instead"
487+
)
454488
def send_speech(self, uuid, params=None, **kwargs):
455489
return self._jwt_signed_put(
456490
"/v1/calls/{uuid}/talk".format(uuid=uuid), params or kwargs
457491
)
458492

459-
@deprecated(reason="vonage.Client#stop_speech is deprecated. Use Voice#stop_speech instead")
493+
@deprecated(
494+
reason="vonage.Client#stop_speech is deprecated. Use Voice#stop_speech instead"
495+
)
460496
def stop_speech(self, uuid):
461497
return self._jwt_signed_delete("/v1/calls/{uuid}/talk".format(uuid=uuid))
462498

463-
@deprecated(reason="vonage.Client#send_dtmf is deprecated. Use Voice#send_dtmf instead")
499+
@deprecated(
500+
reason="vonage.Client#send_dtmf is deprecated. Use Voice#send_dtmf instead"
501+
)
464502
def send_dtmf(self, uuid, params=None, **kwargs):
465503
return self._jwt_signed_put(
466504
"/v1/calls/{uuid}/dtmf".format(uuid=uuid), params or kwargs
@@ -716,7 +754,8 @@ def _jwt_signed_post(self, request_uri, params):
716754
)
717755

718756
return self.parse(
719-
self.api_host(), self.session.post(uri, json=params, headers=self._headers())
757+
self.api_host(),
758+
self.session.post(uri, json=params, headers=self._headers()),
720759
)
721760

722761
def _jwt_signed_put(self, request_uri, params):

0 commit comments

Comments
 (0)