Skip to content

Commit

Permalink
Dx 2050 (#24)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ajrice6713 authored Jun 23, 2021
1 parent aa09863 commit d54facd
Show file tree
Hide file tree
Showing 20 changed files with 1,179 additions and 11 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.DS_Store
43 changes: 36 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pip install bandwidth-sdk

### Initialize

```
```python
from bandwidth.bandwidth_client import BandwidthClient

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

from bandwidth.phonenumberlookup.controllers.api_controller import APIController, ApiResponse, APIException
from bandwidth.phonenumberlookup.models.accounts_tnlookup_request import AccountsTnlookupRequest

from bandwidth.webrtc.models.session import Session
from bandwidth.webrtc.models.participant import Participant
from bandwidth.webrtc.models.publish_permission_enum import PublishPermissionEnum
Expand All @@ -33,6 +36,8 @@ bandwidth_client = BandwidthClient(
messaging_basic_auth_password='password',
two_factor_auth_basic_auth_user_name='username',
two_factor_auth_basic_auth_password='password',
phone_number_lookup_basic_auth_user_name='username',
phone_number_lookup_basic_auth_password='password',
web_rtc_basic_auth_user_name='username',
web_rtc_basic_auth_password='password'
)
Expand All @@ -41,7 +46,7 @@ account_id = "12345"

### Create A Phone Call

```
```python
voice_client = bandwidth_client.voice_client.client

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

### Send A Text Message

```
```python
messaging_client = bandwidth_client.messaging_client.client

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

### Create BXML

```
```python
response = Response()
speak_sentence = SpeakSentence(
sentence="Test",
Expand All @@ -97,7 +102,7 @@ print(response.to_bxml())

### Create A MFA Request

```
```python
auth_client = bandwidth_client.two_factor_auth_client.client

from_phone = "+18888888888"
Expand Down Expand Up @@ -131,9 +136,33 @@ response = auth_client.create_verify_two_factor(account_id, body)
print("Auth status: " + str(response.body.valid))
```

### WebRtc Participant & Session Management
### Perform a TN Lookup Request

```python
tnLookup_controller = bandwidth_client.phone_number_lookup_client.client
body = AccountsTnlookupRequest()
body.tns = ['+19195551234']

try:
response = tnLookup_controller.create_tn_lookup_request(account_id, body)
print(response.status_code)

except APIException as e:
print("Error:", e.response_code)

requestId = response.body.request_id # "1234-abcd-5678-efgh"

try:
response = tnLookup_controller.get_tn_lookup_result(account_id, requestId)
print(response)

except APIException as e:
print("Error:", e.response_code)
```

### WebRtc Participant & Session Management

```python
web_rtc_client = bandwidth_client.web_rtc_client.client

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

## Supported Python Versions

This package can be used with Python >= 3.0
This package can be used with Python >= 3.0

## Documentation

Expand Down
9 changes: 9 additions & 0 deletions bandwidth/bandwidth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from bandwidth.configuration import Environment
from bandwidth.messaging.messaging_client import MessagingClient
from bandwidth.twofactorauth.two_factor_auth_client import TwoFactorAuthClient
from bandwidth.phonenumberlookup.phone_number_lookup_client import PhoneNumberLookupClient
from bandwidth.voice.voice_client import VoiceClient
from bandwidth.webrtc.web_rtc_client import WebRtcClient

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

@lazy_property
def phone_number_lookup_client(self):
return PhoneNumberLookupClient(config=self.config)

@lazy_property
def voice_client(self):
return VoiceClient(config=self.config)
Expand All @@ -40,6 +45,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
messaging_basic_auth_password='TODO: Replace',
two_factor_auth_basic_auth_user_name='TODO: Replace',
two_factor_auth_basic_auth_password='TODO: Replace',
phone_number_lookup_basic_auth_user_name='TODO: Replace',
phone_number_lookup_basic_auth_password='TODO: Replace',
voice_basic_auth_user_name='TODO: Replace',
voice_basic_auth_password='TODO: Replace',
web_rtc_basic_auth_user_name='TODO: Replace',
Expand All @@ -54,6 +61,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
messaging_basic_auth_password=messaging_basic_auth_password,
two_factor_auth_basic_auth_user_name=two_factor_auth_basic_auth_user_name,
two_factor_auth_basic_auth_password=two_factor_auth_basic_auth_password,
phone_number_lookup_basic_auth_user_name=phone_number_lookup_basic_auth_user_name,
phone_number_lookup_basic_auth_password=phone_number_lookup_basic_auth_password,
voice_basic_auth_user_name=voice_basic_auth_user_name,
voice_basic_auth_password=voice_basic_auth_password,
web_rtc_basic_auth_user_name=web_rtc_basic_auth_user_name,
Expand Down
29 changes: 27 additions & 2 deletions bandwidth/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class Server(Enum):
DEFAULT = 0
MESSAGINGDEFAULT = 1
TWOFACTORAUTHDEFAULT = 2
VOICEDEFAULT = 3
WEBRTCDEFAULT = 4
PHONENUMBERLOOKUPDEFAULT = 3
VOICEDEFAULT = 4
WEBRTCDEFAULT = 5


class Configuration(object):
Expand Down Expand Up @@ -70,6 +71,14 @@ def two_factor_auth_basic_auth_user_name(self):
def two_factor_auth_basic_auth_password(self):
return self._two_factor_auth_basic_auth_password

@property
def phone_number_lookup_basic_auth_user_name(self):
return self._phone_number_lookup_basic_auth_user_name

@property
def phone_number_lookup_basic_auth_password(self):
return self._phone_number_lookup_basic_auth_password

@property
def voice_basic_auth_user_name(self):
return self._voice_basic_auth_user_name
Expand All @@ -93,6 +102,8 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
messaging_basic_auth_password='TODO: Replace',
two_factor_auth_basic_auth_user_name='TODO: Replace',
two_factor_auth_basic_auth_password='TODO: Replace',
phone_number_lookup_basic_auth_user_name='TODO: Replace',
phone_number_lookup_basic_auth_password='TODO: Replace',
voice_basic_auth_user_name='TODO: Replace',
voice_basic_auth_password='TODO: Replace',
web_rtc_basic_auth_user_name='TODO: Replace',
Expand Down Expand Up @@ -126,6 +137,12 @@ def __init__(self, timeout=60, max_retries=3, backoff_factor=0,
# The password to use with basic authentication
self._two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password

# The username to use with basic authentication
self._phone_number_lookup_basic_auth_user_name = phone_number_lookup_basic_auth_user_name

# The password to use with basic authentication
self._phone_number_lookup_basic_auth_password = phone_number_lookup_basic_auth_password

# The username to use with basic authentication
self._voice_basic_auth_user_name = voice_basic_auth_user_name

Expand All @@ -147,6 +164,8 @@ def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
messaging_basic_auth_password=None,
two_factor_auth_basic_auth_user_name=None,
two_factor_auth_basic_auth_password=None,
phone_number_lookup_basic_auth_user_name=None,
phone_number_lookup_basic_auth_password=None,
voice_basic_auth_user_name=None,
voice_basic_auth_password=None,
web_rtc_basic_auth_user_name=None,
Expand All @@ -160,6 +179,8 @@ def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
messaging_basic_auth_password = messaging_basic_auth_password or self.messaging_basic_auth_password
two_factor_auth_basic_auth_user_name = two_factor_auth_basic_auth_user_name or self.two_factor_auth_basic_auth_user_name
two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password or self.two_factor_auth_basic_auth_password
phone_number_lookup_basic_auth_user_name = phone_number_lookup_basic_auth_user_name or self.phone_number_lookup_basic_auth_user_name
phone_number_lookup_basic_auth_password = phone_number_lookup_basic_auth_password or self.phone_number_lookup_basic_auth_password
voice_basic_auth_user_name = voice_basic_auth_user_name or self.voice_basic_auth_user_name
voice_basic_auth_password = voice_basic_auth_password or self.voice_basic_auth_password
web_rtc_basic_auth_user_name = web_rtc_basic_auth_user_name or self.web_rtc_basic_auth_user_name
Expand All @@ -172,6 +193,8 @@ def clone_with(self, timeout=None, max_retries=None, backoff_factor=None,
messaging_basic_auth_password=messaging_basic_auth_password,
two_factor_auth_basic_auth_user_name=two_factor_auth_basic_auth_user_name,
two_factor_auth_basic_auth_password=two_factor_auth_basic_auth_password,
phone_number_lookup_basic_auth_user_name=phone_number_lookup_basic_auth_user_name,
phone_number_lookup_basic_auth_password=phone_number_lookup_basic_auth_password,
voice_basic_auth_user_name=voice_basic_auth_user_name,
voice_basic_auth_password=voice_basic_auth_password,
web_rtc_basic_auth_user_name=web_rtc_basic_auth_user_name,
Expand All @@ -189,13 +212,15 @@ def create_http_client(self):
Server.DEFAULT: 'api.bandwidth.com',
Server.MESSAGINGDEFAULT: 'https://messaging.bandwidth.com/api/v2',
Server.TWOFACTORAUTHDEFAULT: 'https://mfa.bandwidth.com/api/v1',
Server.PHONENUMBERLOOKUPDEFAULT: 'https://numbers.bandwidth.com/api/v1',
Server.VOICEDEFAULT: 'https://voice.bandwidth.com',
Server.WEBRTCDEFAULT: 'https://api.webrtc.bandwidth.com/v1'
},
Environment.CUSTOM: {
Server.DEFAULT: '{base_url}',
Server.MESSAGINGDEFAULT: '{base_url}',
Server.TWOFACTORAUTHDEFAULT: '{base_url}',
Server.PHONENUMBERLOOKUPDEFAULT: '{base_url}',
Server.VOICEDEFAULT: '{base_url}',
Server.WEBRTCDEFAULT: '{base_url}'
}
Expand Down
30 changes: 30 additions & 0 deletions bandwidth/http/auth/phone_number_lookup_basic_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-

"""
bandwidth
This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
"""

import base64


class PhoneNumberLookupBasicAuth:

@staticmethod
def apply(config, http_request):
""" Add basic authentication to the request.
Args:
config (Configuration): The Configuration object which holds the
authentication information.
http_request (HttpRequest): The HttpRequest object to which
authentication will be added.
"""
username = config.phone_number_lookup_basic_auth_user_name
password = config.phone_number_lookup_basic_auth_password
joined = "{}:{}".format(username, password)
encoded = base64.b64encode(str.encode(joined)).decode('iso-8859-1')
header_value = "Basic {}".format(encoded)
http_request.headers["Authorization"] = header_value
6 changes: 6 additions & 0 deletions bandwidth/phonenumberlookup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__all__ = [
'controllers',
'exceptions',
'models',
'phone_number_lookup_client',
]
4 changes: 4 additions & 0 deletions bandwidth/phonenumberlookup/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__all__ = [
'base_controller',
'api_controller',
]
Loading

0 comments on commit d54facd

Please sign in to comment.