Skip to content

Commit

Permalink
Merge pull request #148 from plivo/ppai-lookup-api-v2
Browse files Browse the repository at this point in the history
Lookup API: Change endpoint and response
  • Loading branch information
nixonsam authored Oct 30, 2020
2 parents 57853a2 + 1835da3 commit 54bc2ff
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [4.13.0](https://github.com/plivo/plivo-python/tree/v4.13.0) (2020-10-23)
- Change lookup API endpoint and response.

## [4.12.0](https://github.com/plivo/plivo-python/tree/v4.12.0) (2020-10-06)
- Add lookup API support.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ call_made = client.calls.create(
import plivo

client = plivo.RestClient(auth_id='', auth_token='')
resp = client.lookup.get("<insert-number-here>", info_type='carrier')
resp = client.lookup.get("<insert-number-here>")
print(resp)
```

Expand Down
7 changes: 5 additions & 2 deletions plivo/resources/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from plivo.base import PlivoResourceInterface, ResponseObject


LOOKUP_API_ENDPOINT = "https://lookup.plivo.com/v1/Number"


class Number(ResponseObject):
def __init__(self, client, data):
super(Number, self).__init__(data)
Expand All @@ -16,7 +19,7 @@ def get(self, number, info_type='carrier'):
}
return self.client.request(
'GET',
('Lookup/Number', number),
(LOOKUP_API_ENDPOINT, number),
data=params,
response_type=Number,
plivo_api_v1_base_url=True)
is_lookup_request=True)
12 changes: 5 additions & 7 deletions plivo/rest/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'auth_id auth_token')

PLIVO_API = 'https://api.plivo.com'
PLIVO_API_V1 = '/'.join([PLIVO_API, 'v1'])
PLIVO_API_BASE_URI = '/'.join([PLIVO_API, 'v1/Account'])

# Will change these urls before putting this change in production
Expand Down Expand Up @@ -206,10 +205,9 @@ def create_request(self, method, path=None, data=None, **kwargs):
if 'is_callinsights_request' in kwargs:
url = '/'.join([CALLINSIGHTS_BASE_URL, kwargs['callinsights_request_path']])
req = Request(method, url, **({'params': data} if method == 'GET' else {'json': data}))
elif kwargs.get('plivo_api_v1_base_url', False):
# currently used by lookup API but can be used by other APIs in future
elif kwargs.get('is_lookup_request', False):
path = path or []
url = '/'.join([PLIVO_API_V1] + list([str(p) for p in path]))
url = '/'.join(list([str(p) for p in path]))
req = Request(method, url, **({'params': data} if method == 'GET' else {'json': data}))
else:
path = path or []
Expand Down Expand Up @@ -295,9 +293,9 @@ def request(self,
kwargs["is_voice_request"] = True
return self.request(method, path, data, **kwargs)
return self.process_response(method, response, response_type, objects_type)
elif kwargs.get('plivo_api_v1_base_url', False):
req = self.create_request(method, path, data, plivo_api_v1_base_url=True)
del kwargs['plivo_api_v1_base_url']
elif kwargs.get('is_lookup_request', False):
req = self.create_request(method, path, data, is_lookup_request=True)
del kwargs['is_lookup_request']
else:
req = self.create_request(method, path, data)
session = self.session
Expand Down
2 changes: 1 addition & 1 deletion plivo/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '4.12.0'
__version__ = '4.13.0'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='plivo',
version='4.12.0',
version='4.13.0',
description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML',
long_description=long_description,
url='https://github.com/plivo/plivo-python',
Expand Down
8 changes: 4 additions & 4 deletions tests/resources/fixtures/lookupGetResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"phone_number": "+14154305555",
"country": {
"name": "United States",
"code_iso2": "US",
"code_iso3": "USA"
"iso2": "US",
"iso3": "USA"
},
"format": {
"e164": "+14154305555",
Expand All @@ -17,7 +17,7 @@
"mobile_network_code": "150",
"name": "Cingular Wireless",
"type": "mobile",
"ported": true
"ported": "yes"
},
"resource_uri": "/v1/Lookup/Number/+14154305555?type=carrier"
"resource_uri": "/v1/Number/+14154305555?type=carrier"
}

0 comments on commit 54bc2ff

Please sign in to comment.