|
12 | 12 | PlivoRestError, PlivoServerError, |
13 | 13 | ResourceNotFoundError, ValidationError) |
14 | 14 | from plivo.resources import (Accounts, Addresses, Applications, Calls, |
15 | | - Conferences, Endpoints, Identities, Messages, Powerpacks, Media, |
| 15 | + Conferences, Endpoints, Identities, |
| 16 | + Messages, Powerpacks, Media, Lookup, |
16 | 17 | Numbers, Pricings, Recordings, Subaccounts, CallFeedback) |
17 | 18 | from plivo.resources.live_calls import LiveCalls |
18 | 19 | from plivo.resources.queued_calls import QueuedCalls |
|
24 | 25 | 'auth_id auth_token') |
25 | 26 |
|
26 | 27 | PLIVO_API = 'https://api.plivo.com' |
| 28 | +PLIVO_API_V1 = '/'.join([PLIVO_API, 'v1']) |
27 | 29 | PLIVO_API_BASE_URI = '/'.join([PLIVO_API, 'v1/Account']) |
28 | 30 |
|
29 | 31 | # Will change these urls before putting this change in production |
@@ -92,6 +94,7 @@ def __init__(self, auth_id=None, auth_token=None, proxies=None, timeout=5): |
92 | 94 | self.conferences = Conferences(self) |
93 | 95 | self.endpoints = Endpoints(self) |
94 | 96 | self.messages = Messages(self) |
| 97 | + self.lookup = Lookup(self) |
95 | 98 | self.numbers = Numbers(self) |
96 | 99 | self.powerpacks = Powerpacks(self) |
97 | 100 | self.media = Media(self) |
@@ -197,10 +200,17 @@ def process_response(self, |
197 | 200 | return response_json |
198 | 201 |
|
199 | 202 | def create_request(self, method, path=None, data=None, **kwargs): |
200 | | - |
| 203 | + # The abstraction created by request() and create_request() is moot |
| 204 | + # now since several product-specific handling have been aded. |
| 205 | + # Requires a refactor. |
201 | 206 | if 'is_callinsights_request' in kwargs: |
202 | 207 | url = '/'.join([CALLINSIGHTS_BASE_URL, kwargs['callinsights_request_path']]) |
203 | 208 | 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 |
| 211 | + path = path or [] |
| 212 | + url = '/'.join([PLIVO_API_V1] + list([str(p) for p in path])) |
| 213 | + req = Request(method, url, **({'params': data} if method == 'GET' else {'json': data})) |
204 | 214 | else: |
205 | 215 | path = path or [] |
206 | 216 | req = Request(method, '/'.join([self.base_uri, self.session.auth[0]] + |
@@ -285,6 +295,9 @@ def request(self, |
285 | 295 | kwargs["is_voice_request"] = True |
286 | 296 | return self.request(method, path, data, **kwargs) |
287 | 297 | 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'] |
288 | 301 | else: |
289 | 302 | req = self.create_request(method, path, data) |
290 | 303 | session = self.session |
|
0 commit comments