Skip to content

Commit d54facd

Browse files
authored
Dx 2050 (#24)
* Add Phone Number Lookup API * Update api_tests.py * Update api_tests.py * Update api_tests.py * Create phone_number_lookup_basic_auth.py * Update bandwidth_client.py * Fix config and update test * Update api_tests.py * Revert Test changes * Update test to include GET method * copy/paste error * typo fix * Update README.md * Changes based on updated spec * Update api_tests.py * bump version
1 parent aa09863 commit d54facd

20 files changed

+1179
-11
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.DS_Store

README.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pip install bandwidth-sdk
1010

1111
### Initialize
1212

13-
```
13+
```python
1414
from bandwidth.bandwidth_client import BandwidthClient
1515

1616
from bandwidth.messaging.models.message_request import MessageRequest
@@ -22,6 +22,9 @@ from bandwidth.voice.bxml.verbs import *
2222
from bandwidth.twofactorauth.models.two_factor_code_request_schema import TwoFactorCodeRequestSchema
2323
from bandwidth.twofactorauth.models.two_factor_verify_request_schema import TwoFactorVerifyRequestSchema
2424

25+
from bandwidth.phonenumberlookup.controllers.api_controller import APIController, ApiResponse, APIException
26+
from bandwidth.phonenumberlookup.models.accounts_tnlookup_request import AccountsTnlookupRequest
27+
2528
from bandwidth.webrtc.models.session import Session
2629
from bandwidth.webrtc.models.participant import Participant
2730
from bandwidth.webrtc.models.publish_permission_enum import PublishPermissionEnum
@@ -33,6 +36,8 @@ bandwidth_client = BandwidthClient(
3336
messaging_basic_auth_password='password',
3437
two_factor_auth_basic_auth_user_name='username',
3538
two_factor_auth_basic_auth_password='password',
39+
phone_number_lookup_basic_auth_user_name='username',
40+
phone_number_lookup_basic_auth_password='password',
3641
web_rtc_basic_auth_user_name='username',
3742
web_rtc_basic_auth_password='password'
3843
)
@@ -41,7 +46,7 @@ account_id = "12345"
4146

4247
### Create A Phone Call
4348

44-
```
49+
```python
4550
voice_client = bandwidth_client.voice_client.client
4651

4752
##Create phone call
@@ -62,7 +67,7 @@ except ApiErrorResponseException as e:
6267

6368
### Send A Text Message
6469

65-
```
70+
```python
6671
messaging_client = bandwidth_client.messaging_client.client
6772

6873
body = MessageRequest()
@@ -82,7 +87,7 @@ except MessagingException as e:
8287

8388
### Create BXML
8489

85-
```
90+
```python
8691
response = Response()
8792
speak_sentence = SpeakSentence(
8893
sentence="Test",
@@ -97,7 +102,7 @@ print(response.to_bxml())
97102

98103
### Create A MFA Request
99104

100-
```
105+
```python
101106
auth_client = bandwidth_client.two_factor_auth_client.client
102107

103108
from_phone = "+18888888888"
@@ -131,9 +136,33 @@ response = auth_client.create_verify_two_factor(account_id, body)
131136
print("Auth status: " + str(response.body.valid))
132137
```
133138

134-
### WebRtc Participant & Session Management
139+
### Perform a TN Lookup Request
135140

141+
```python
142+
tnLookup_controller = bandwidth_client.phone_number_lookup_client.client
143+
body = AccountsTnlookupRequest()
144+
body.tns = ['+19195551234']
145+
146+
try:
147+
response = tnLookup_controller.create_tn_lookup_request(account_id, body)
148+
print(response.status_code)
149+
150+
except APIException as e:
151+
print("Error:", e.response_code)
152+
153+
requestId = response.body.request_id # "1234-abcd-5678-efgh"
154+
155+
try:
156+
response = tnLookup_controller.get_tn_lookup_result(account_id, requestId)
157+
print(response)
158+
159+
except APIException as e:
160+
print("Error:", e.response_code)
136161
```
162+
163+
### WebRtc Participant & Session Management
164+
165+
```python
137166
web_rtc_client = bandwidth_client.web_rtc_client.client
138167

139168
create_session_body = Session()
@@ -157,7 +186,7 @@ web_rtc_client.add_participant_to_session(account_id, session_id, participant_id
157186

158187
## Supported Python Versions
159188

160-
This package can be used with Python >= 3.0
189+
This package can be used with Python >= 3.0
161190

162191
## Documentation
163192

bandwidth/bandwidth_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from bandwidth.configuration import Environment
1212
from bandwidth.messaging.messaging_client import MessagingClient
1313
from bandwidth.twofactorauth.two_factor_auth_client import TwoFactorAuthClient
14+
from bandwidth.phonenumberlookup.phone_number_lookup_client import PhoneNumberLookupClient
1415
from bandwidth.voice.voice_client import VoiceClient
1516
from bandwidth.webrtc.web_rtc_client import WebRtcClient
1617

@@ -25,6 +26,10 @@ def messaging_client(self):
2526
def two_factor_auth_client(self):
2627
return TwoFactorAuthClient(config=self.config)
2728

29+
@lazy_property
30+
def phone_number_lookup_client(self):
31+
return PhoneNumberLookupClient(config=self.config)
32+
2833
@lazy_property
2934
def voice_client(self):
3035
return VoiceClient(config=self.config)
@@ -40,6 +45,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
4045
messaging_basic_auth_password='TODO: Replace',
4146
two_factor_auth_basic_auth_user_name='TODO: Replace',
4247
two_factor_auth_basic_auth_password='TODO: Replace',
48+
phone_number_lookup_basic_auth_user_name='TODO: Replace',
49+
phone_number_lookup_basic_auth_password='TODO: Replace',
4350
voice_basic_auth_user_name='TODO: Replace',
4451
voice_basic_auth_password='TODO: Replace',
4552
web_rtc_basic_auth_user_name='TODO: Replace',
@@ -54,6 +61,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
5461
messaging_basic_auth_password=messaging_basic_auth_password,
5562
two_factor_auth_basic_auth_user_name=two_factor_auth_basic_auth_user_name,
5663
two_factor_auth_basic_auth_password=two_factor_auth_basic_auth_password,
64+
phone_number_lookup_basic_auth_user_name=phone_number_lookup_basic_auth_user_name,
65+
phone_number_lookup_basic_auth_password=phone_number_lookup_basic_auth_password,
5766
voice_basic_auth_user_name=voice_basic_auth_user_name,
5867
voice_basic_auth_password=voice_basic_auth_password,
5968
web_rtc_basic_auth_user_name=web_rtc_basic_auth_user_name,

bandwidth/configuration.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class Server(Enum):
2222
DEFAULT = 0
2323
MESSAGINGDEFAULT = 1
2424
TWOFACTORAUTHDEFAULT = 2
25-
VOICEDEFAULT = 3
26-
WEBRTCDEFAULT = 4
25+
PHONENUMBERLOOKUPDEFAULT = 3
26+
VOICEDEFAULT = 4
27+
WEBRTCDEFAULT = 5
2728

2829

2930
class Configuration(object):
@@ -70,6 +71,14 @@ def two_factor_auth_basic_auth_user_name(self):
7071
def two_factor_auth_basic_auth_password(self):
7172
return self._two_factor_auth_basic_auth_password
7273

74+
@property
75+
def phone_number_lookup_basic_auth_user_name(self):
76+
return self._phone_number_lookup_basic_auth_user_name
77+
78+
@property
79+
def phone_number_lookup_basic_auth_password(self):
80+
return self._phone_number_lookup_basic_auth_password
81+
7382
@property
7483
def voice_basic_auth_user_name(self):
7584
return self._voice_basic_auth_user_name
@@ -93,6 +102,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
93102
messaging_basic_auth_password='TODO: Replace',
94103
two_factor_auth_basic_auth_user_name='TODO: Replace',
95104
two_factor_auth_basic_auth_password='TODO: Replace',
105+
phone_number_lookup_basic_auth_user_name='TODO: Replace',
106+
phone_number_lookup_basic_auth_password='TODO: Replace',
96107
voice_basic_auth_user_name='TODO: Replace',
97108
voice_basic_auth_password='TODO: Replace',
98109
web_rtc_basic_auth_user_name='TODO: Replace',
@@ -126,6 +137,12 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
126137
# The password to use with basic authentication
127138
self._two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password
128139

140+
# The username to use with basic authentication
141+
self._phone_number_lookup_basic_auth_user_name = phone_number_lookup_basic_auth_user_name
142+
143+
# The password to use with basic authentication
144+
self._phone_number_lookup_basic_auth_password = phone_number_lookup_basic_auth_password
145+
129146
# The username to use with basic authentication
130147
self._voice_basic_auth_user_name = voice_basic_auth_user_name
131148

@@ -147,6 +164,8 @@ def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
147164
messaging_basic_auth_password=None,
148165
two_factor_auth_basic_auth_user_name=None,
149166
two_factor_auth_basic_auth_password=None,
167+
phone_number_lookup_basic_auth_user_name=None,
168+
phone_number_lookup_basic_auth_password=None,
150169
voice_basic_auth_user_name=None,
151170
voice_basic_auth_password=None,
152171
web_rtc_basic_auth_user_name=None,
@@ -160,6 +179,8 @@ def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
160179
messaging_basic_auth_password = messaging_basic_auth_password or self.messaging_basic_auth_password
161180
two_factor_auth_basic_auth_user_name = two_factor_auth_basic_auth_user_name or self.two_factor_auth_basic_auth_user_name
162181
two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password or self.two_factor_auth_basic_auth_password
182+
phone_number_lookup_basic_auth_user_name = phone_number_lookup_basic_auth_user_name or self.phone_number_lookup_basic_auth_user_name
183+
phone_number_lookup_basic_auth_password = phone_number_lookup_basic_auth_password or self.phone_number_lookup_basic_auth_password
163184
voice_basic_auth_user_name = voice_basic_auth_user_name or self.voice_basic_auth_user_name
164185
voice_basic_auth_password = voice_basic_auth_password or self.voice_basic_auth_password
165186
web_rtc_basic_auth_user_name = web_rtc_basic_auth_user_name or self.web_rtc_basic_auth_user_name
@@ -172,6 +193,8 @@ def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
172193
messaging_basic_auth_password=messaging_basic_auth_password,
173194
two_factor_auth_basic_auth_user_name=two_factor_auth_basic_auth_user_name,
174195
two_factor_auth_basic_auth_password=two_factor_auth_basic_auth_password,
196+
phone_number_lookup_basic_auth_user_name=phone_number_lookup_basic_auth_user_name,
197+
phone_number_lookup_basic_auth_password=phone_number_lookup_basic_auth_password,
175198
voice_basic_auth_user_name=voice_basic_auth_user_name,
176199
voice_basic_auth_password=voice_basic_auth_password,
177200
web_rtc_basic_auth_user_name=web_rtc_basic_auth_user_name,
@@ -189,13 +212,15 @@ def create_http_client(self):
189212
Server.DEFAULT: 'api.bandwidth.com',
190213
Server.MESSAGINGDEFAULT: 'https://messaging.bandwidth.com/api/v2',
191214
Server.TWOFACTORAUTHDEFAULT: 'https://mfa.bandwidth.com/api/v1',
215+
Server.PHONENUMBERLOOKUPDEFAULT: 'https://numbers.bandwidth.com/api/v1',
192216
Server.VOICEDEFAULT: 'https://voice.bandwidth.com',
193217
Server.WEBRTCDEFAULT: 'https://api.webrtc.bandwidth.com/v1'
194218
},
195219
Environment.CUSTOM: {
196220
Server.DEFAULT: '{base_url}',
197221
Server.MESSAGINGDEFAULT: '{base_url}',
198222
Server.TWOFACTORAUTHDEFAULT: '{base_url}',
223+
Server.PHONENUMBERLOOKUPDEFAULT: '{base_url}',
199224
Server.VOICEDEFAULT: '{base_url}',
200225
Server.WEBRTCDEFAULT: '{base_url}'
201226
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
bandwidth
5+
6+
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
7+
"""
8+
9+
import base64
10+
11+
12+
class PhoneNumberLookupBasicAuth:
13+
14+
@staticmethod
15+
def apply(config, http_request):
16+
""" Add basic authentication to the request.
17+
18+
Args:
19+
config (Configuration): The Configuration object which holds the
20+
authentication information.
21+
http_request (HttpRequest): The HttpRequest object to which
22+
authentication will be added.
23+
24+
"""
25+
username = config.phone_number_lookup_basic_auth_user_name
26+
password = config.phone_number_lookup_basic_auth_password
27+
joined = "{}:{}".format(username, password)
28+
encoded = base64.b64encode(str.encode(joined)).decode('iso-8859-1')
29+
header_value = "Basic {}".format(encoded)
30+
http_request.headers["Authorization"] = header_value
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__all__ = [
2+
'controllers',
3+
'exceptions',
4+
'models',
5+
'phone_number_lookup_client',
6+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__all__ = [
2+
'base_controller',
3+
'api_controller',
4+
]

0 commit comments

Comments
 (0)