Skip to content

Commit 54bc2ff

Browse files
authored
Merge pull request #148 from plivo/ppai-lookup-api-v2
Lookup API: Change endpoint and response
2 parents 57853a2 + 1835da3 commit 54bc2ff

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
## [4.13.0](https://github.com/plivo/plivo-python/tree/v4.13.0) (2020-10-23)
4+
- Change lookup API endpoint and response.
5+
36
## [4.12.0](https://github.com/plivo/plivo-python/tree/v4.12.0) (2020-10-06)
47
- Add lookup API support.
58

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ call_made = client.calls.create(
122122
import plivo
123123

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

plivo/resources/lookup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from plivo.base import PlivoResourceInterface, ResponseObject
33

44

5+
LOOKUP_API_ENDPOINT = "https://lookup.plivo.com/v1/Number"
6+
7+
58
class Number(ResponseObject):
69
def __init__(self, client, data):
710
super(Number, self).__init__(data)
@@ -16,7 +19,7 @@ def get(self, number, info_type='carrier'):
1619
}
1720
return self.client.request(
1821
'GET',
19-
('Lookup/Number', number),
22+
(LOOKUP_API_ENDPOINT, number),
2023
data=params,
2124
response_type=Number,
22-
plivo_api_v1_base_url=True)
25+
is_lookup_request=True)

plivo/rest/client.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
'auth_id auth_token')
2626

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

3130
# Will change these urls before putting this change in production
@@ -206,10 +205,9 @@ def create_request(self, method, path=None, data=None, **kwargs):
206205
if 'is_callinsights_request' in kwargs:
207206
url = '/'.join([CALLINSIGHTS_BASE_URL, kwargs['callinsights_request_path']])
208207
req = Request(method, url, **({'params': data} if method == 'GET' else {'json': data}))
209-
elif kwargs.get('plivo_api_v1_base_url', False):
210-
# currently used by lookup API but can be used by other APIs in future
208+
elif kwargs.get('is_lookup_request', False):
211209
path = path or []
212-
url = '/'.join([PLIVO_API_V1] + list([str(p) for p in path]))
210+
url = '/'.join(list([str(p) for p in path]))
213211
req = Request(method, url, **({'params': data} if method == 'GET' else {'json': data}))
214212
else:
215213
path = path or []
@@ -295,9 +293,9 @@ def request(self,
295293
kwargs["is_voice_request"] = True
296294
return self.request(method, path, data, **kwargs)
297295
return self.process_response(method, response, response_type, objects_type)
298-
elif kwargs.get('plivo_api_v1_base_url', False):
299-
req = self.create_request(method, path, data, plivo_api_v1_base_url=True)
300-
del kwargs['plivo_api_v1_base_url']
296+
elif kwargs.get('is_lookup_request', False):
297+
req = self.create_request(method, path, data, is_lookup_request=True)
298+
del kwargs['is_lookup_request']
301299
else:
302300
req = self.create_request(method, path, data)
303301
session = self.session

plivo/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = '4.12.0'
2+
__version__ = '4.13.0'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='plivo',
13-
version='4.12.0',
13+
version='4.13.0',
1414
description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML',
1515
long_description=long_description,
1616
url='https://github.com/plivo/plivo-python',

tests/resources/fixtures/lookupGetResponse.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"phone_number": "+14154305555",
44
"country": {
55
"name": "United States",
6-
"code_iso2": "US",
7-
"code_iso3": "USA"
6+
"iso2": "US",
7+
"iso3": "USA"
88
},
99
"format": {
1010
"e164": "+14154305555",
@@ -17,7 +17,7 @@
1717
"mobile_network_code": "150",
1818
"name": "Cingular Wireless",
1919
"type": "mobile",
20-
"ported": true
20+
"ported": "yes"
2121
},
22-
"resource_uri": "/v1/Lookup/Number/+14154305555?type=carrier"
22+
"resource_uri": "/v1/Number/+14154305555?type=carrier"
2323
}

0 commit comments

Comments
 (0)