Skip to content

Commit 602ad6c

Browse files
committed
Deploy
1 parent f3d3766 commit 602ad6c

File tree

145 files changed

+9105
-197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+9105
-197
lines changed

README.md

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +0,0 @@
1-
# Bandwidth Python SDK
2-
3-
Bandwidth's API docs can be found at https://dev.bandwidth.com
4-
5-
Python specific docs can be found at https://dev.bandwidth.com/sdks/python.html
6-
7-
# Python SDK
8-
9-
## Download & Install
10-
11-
```
12-
pip install bandwidth-sdk
13-
```
14-
15-
## Initialize Bandwidth Client
16-
17-
```python
18-
from bandwidth.bandwidth_client import BandwidthClient
19-
20-
from bandwidth.messaging.models.message_request import MessageRequest
21-
from bandwidth.messaging.exceptions.generic_client_exception import GenericClientException
22-
from bandwidth.messaging.exceptions.path_client_exception import PathClientException
23-
24-
from bandwidth.voice.models.api_create_call_request import ApiCreateCallRequest
25-
from bandwidth.voice.models.modify_call_recording_state import ModifyCallRecordingState
26-
from bandwidth.voice.exceptions.error_response_exception import ErrorResponseException
27-
from bandwidth.voice.bxml.response import Response
28-
from bandwidth.voice.bxml.verbs import *
29-
30-
##Initialize client
31-
voice_basic_auth_user_name = 'username'
32-
voice_basic_auth_password = 'password'
33-
messaging_basic_auth_user_name = 'token'
34-
messaging_basic_auth_password = 'secret'
35-
36-
bandwidth_client = BandwidthClient(
37-
voice_basic_auth_user_name=voice_basic_auth_user_name,
38-
voice_basic_auth_password=voice_basic_auth_password,
39-
messaging_basic_auth_user_name=messaging_basic_auth_user_name,
40-
messaging_basic_auth_password=messaging_basic_auth_password)
41-
```
42-
43-
## Create Phone Call
44-
45-
```python
46-
voice_client = bandwidth_client.voice_client.client
47-
account_id = "1"
48-
49-
##Create phone call
50-
body = ApiCreateCallRequest()
51-
body.mfrom = "+17777777777"
52-
body.to = "+16666666666"
53-
body.application_id = "3-d-4-b-5"
54-
body.answer_url = "https://test.com"
55-
56-
try:
57-
response = voice_client.create_call(account_id, body=body)
58-
print(response.body.call_id) #c-3f758f24-a59bb21e-4f23-4d62-afe9-53o2ls3o4saio4l
59-
print(response.status_code) #201
60-
except ErrorResponseException as e:
61-
print(e.description) #Invalid from: must be an E164 telephone number
62-
print(e.response_code) #400
63-
```
64-
65-
## Generate BXML
66-
67-
```python
68-
response = Response()
69-
speak_sentence = SpeakSentence(
70-
sentence="Test",
71-
voice="susan",
72-
locale="en_US",
73-
gender="female"
74-
)
75-
76-
response.add_verb(speak_sentence)
77-
print(response.to_bxml())
78-
```
79-
80-
## Send Text Message
81-
82-
```python
83-
messaging_client = bandwidth_client.messaging_client.client
84-
account_id = "1"
85-
86-
body = MessageRequest()
87-
body.application_id = "1-d-b"
88-
body.to = ["+17777777777"]
89-
body.mfrom = "+18888888888"
90-
body.text = "Greetings!"
91-
92-
try:
93-
response = messaging_client.create_message(account_id, body=body)
94-
print(response.body.id) #1570819529611mexbyfr7ugrouuxy
95-
print(response.status_code) #202
96-
except GenericClientException as e:
97-
print(e.description) #Your request could not be accepted.
98-
print(e.response_code) #400
99-
except PathClientException as e:
100-
print(e.message) #Access is denied
101-
print(e.response_code) #403
102-
```

bandwidth/api_helper.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def serialize_array(key, array, formatting="indexed"):
139139
return tuples
140140

141141
@staticmethod
142-
def append_url_with_template_parameters(url, parameters, encode=True):
142+
def append_url_with_template_parameters(url, parameters):
143143
"""Replaces template parameters in the given url.
144144
145145
Args:
@@ -158,16 +158,17 @@ def append_url_with_template_parameters(url, parameters, encode=True):
158158

159159
# Iterate and replace parameters
160160
for key in parameters:
161-
element = parameters[key]
161+
value = parameters[key]['value']
162+
encode = parameters[key]['encode']
162163
replace_value = ''
163164

164165
# Load parameter value
165-
if element is None:
166+
if value is None:
166167
replace_value = ''
167-
elif isinstance(element, list):
168-
replace_value = "/".join((quote(str(x), safe='') if encode else str(x)) for x in element)
168+
elif isinstance(value, list):
169+
replace_value = "/".join((quote(str(x), safe='') if encode else str(x)) for x in value)
169170
else:
170-
replace_value = quote(str(element), safe='') if encode else str(element)
171+
replace_value = quote(str(value), safe='') if encode else str(value)
171172

172173
url = url.replace('{{{0}}}'.format(key), str(replace_value))
173174

bandwidth/controllers/base_controller.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ class BaseController(object):
2626
2727
"""
2828

29-
global_headers = {
30-
'user-agent': 'python-sdk-refs/tags/python6.8.0'
31-
}
29+
def global_headers(self):
30+
return {
31+
'user-agent': 'python-sdk-refs/tags/python6.9.0'
32+
}
3233

3334
def __init__(self, config, call_back=None):
3435
self._config = config
@@ -70,7 +71,7 @@ def execute_request(self, request, binary=False):
7071
self.http_call_back.on_before_request(request)
7172

7273
# Add global headers to request
73-
request.headers = APIHelper.merge_dicts(self.global_headers, request.headers)
74+
request.headers = APIHelper.merge_dicts(self.global_headers(), request.headers)
7475

7576
# Invoke the API call to fetch the response.
7677
func = self.config.http_client.execute_as_binary if binary else self.config.http_client.execute_as_string

bandwidth/messaging/controllers/api_controller.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def list_media(self,
5252
# Prepare query URL
5353
_url_path = '/users/{userId}/media'
5454
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
55-
'userId': user_id
55+
'userId': {'value': user_id, 'encode': True}
5656
})
5757
_query_builder = self.config.get_base_uri(Server.MESSAGINGDEFAULT)
5858
_query_builder += _url_path
@@ -115,8 +115,8 @@ def get_media(self,
115115
# Prepare query URL
116116
_url_path = '/users/{userId}/media/{mediaId}'
117117
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
118-
'userId': user_id,
119-
'mediaId': media_id
118+
'userId': {'value': user_id, 'encode': True},
119+
'mediaId': {'value': media_id, 'encode': True}
120120
})
121121
_query_builder = self.config.get_base_uri(Server.MESSAGINGDEFAULT)
122122
_query_builder += _url_path
@@ -181,8 +181,8 @@ def upload_media(self,
181181
# Prepare query URL
182182
_url_path = '/users/{userId}/media/{mediaId}'
183183
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
184-
'userId': user_id,
185-
'mediaId': media_id
184+
'userId': {'value': user_id, 'encode': True},
185+
'mediaId': {'value': media_id, 'encode': True}
186186
})
187187
_query_builder = self.config.get_base_uri(Server.MESSAGINGDEFAULT)
188188
_query_builder += _url_path
@@ -251,8 +251,8 @@ def delete_media(self,
251251
# Prepare query URL
252252
_url_path = '/users/{userId}/media/{mediaId}'
253253
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
254-
'userId': user_id,
255-
'mediaId': media_id
254+
'userId': {'value': user_id, 'encode': True},
255+
'mediaId': {'value': media_id, 'encode': True}
256256
})
257257
_query_builder = self.config.get_base_uri(Server.MESSAGINGDEFAULT)
258258
_query_builder += _url_path
@@ -308,7 +308,7 @@ def create_message(self,
308308
# Prepare query URL
309309
_url_path = '/users/{userId}/messages'
310310
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
311-
'userId': user_id
311+
'userId': {'value': user_id, 'encode': True}
312312
})
313313
_query_builder = self.config.get_base_uri(Server.MESSAGINGDEFAULT)
314314
_query_builder += _url_path

bandwidth/messaging/controllers/base_controller.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ class BaseController(object):
2626
2727
"""
2828

29-
global_headers = {
30-
'user-agent': 'python-sdk-refs/tags/python6.8.0'
31-
}
29+
def global_headers(self):
30+
return {
31+
'user-agent': 'python-sdk-refs/tags/python6.9.0'
32+
}
3233

3334
def __init__(self, config, call_back=None):
3435
self._config = config
@@ -70,7 +71,7 @@ def execute_request(self, request, binary=False):
7071
self.http_call_back.on_before_request(request)
7172

7273
# Add global headers to request
73-
request.headers = APIHelper.merge_dicts(self.global_headers, request.headers)
74+
request.headers = APIHelper.merge_dicts(self.global_headers(), request.headers)
7475

7576
# Invoke the API call to fetch the response.
7677
func = self.config.http_client.execute_as_binary if binary else self.config.http_client.execute_as_string

bandwidth/twofactorauth/controllers/api_controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def create_voice_two_factor(self,
5252
# Prepare query URL
5353
_url_path = '/accounts/{accountId}/code/voice'
5454
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
55-
'accountId': account_id
55+
'accountId': {'value': account_id, 'encode': True}
5656
})
5757
_query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT)
5858
_query_builder += _url_path
@@ -106,7 +106,7 @@ def create_messaging_two_factor(self,
106106
# Prepare query URL
107107
_url_path = '/accounts/{accountId}/code/messaging'
108108
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
109-
'accountId': account_id
109+
'accountId': {'value': account_id, 'encode': True}
110110
})
111111
_query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT)
112112
_query_builder += _url_path
@@ -159,7 +159,7 @@ def create_verify_two_factor(self,
159159
# Prepare query URL
160160
_url_path = '/accounts/{accountId}/code/verify'
161161
_url_path = APIHelper.append_url_with_template_parameters(_url_path, {
162-
'accountId': account_id
162+
'accountId': {'value': account_id, 'encode': True}
163163
})
164164
_query_builder = self.config.get_base_uri(Server.TWOFACTORAUTHDEFAULT)
165165
_query_builder += _url_path

bandwidth/twofactorauth/controllers/base_controller.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ class BaseController(object):
2626
2727
"""
2828

29-
global_headers = {
30-
'user-agent': 'python-sdk-refs/tags/python6.8.0'
31-
}
29+
def global_headers(self):
30+
return {
31+
'user-agent': 'python-sdk-refs/tags/python6.9.0'
32+
}
3233

3334
def __init__(self, config, call_back=None):
3435
self._config = config
@@ -70,7 +71,7 @@ def execute_request(self, request, binary=False):
7071
self.http_call_back.on_before_request(request)
7172

7273
# Add global headers to request
73-
request.headers = APIHelper.merge_dicts(self.global_headers, request.headers)
74+
request.headers = APIHelper.merge_dicts(self.global_headers(), request.headers)
7475

7576
# Invoke the API call to fetch the response.
7677
func = self.config.http_client.execute_as_binary if binary else self.config.http_client.execute_as_string

0 commit comments

Comments
 (0)