diff --git a/plivo/base.py b/plivo/base.py index 5378e0a0..498720fe 100644 --- a/plivo/base.py +++ b/plivo/base.py @@ -151,6 +151,42 @@ def __str__(self): def __repr__(self): return str([object for object in self.objects]) +class ListTollfreeRequestResponseObject(ResponseObject): + def __init__(self, client, dct): + super(ListTollfreeRequestResponseObject, self).__init__(dct) + self.error = dct.get('error', None) + self.objects = dct.get('objects', None) + self.meta = dct.get('meta', None) + self.apiID = dct.get('api_id', None) + + def __iter__(self): + if self.objects is not None: + return self.objects.__iter__() + else: + return iter([]) + + def __len__(self): + if self.objects is not None: + return len(self.objects) + else: + return 0 # Return 0 for error case + + def __str__(self): + if self.objects is not None: + response_dict = {'api_id': self.apiID, 'meta': self.meta, 'objects': self.objects} + return pprint.pformat(response_dict) + else: + return str(self.error) # Display error message for error case + + def __repr__(self): + if self.objects is not None: + response_dict = {'api_id': self.apiID, 'meta': self.meta, 'objects': [session for session in self.objects]} + return str(response_dict) + else: + return str(self.error) # Display error message for error case + + def has_error(self): + return self.error is not None class PlivoResource(ResponseObject): """The Plivo resource object diff --git a/plivo/resources/__init__.py b/plivo/resources/__init__.py index 6850f5a2..0608fbe4 100644 --- a/plivo/resources/__init__.py +++ b/plivo/resources/__init__.py @@ -21,3 +21,4 @@ from .profile import Profile from .multipartycall import MultiPartyCalls, MultiPartyCall, MultiPartyCallParticipant from .verify import Sessions +from .tollfree_verification import TollFreeVerificationRequests diff --git a/plivo/resources/tollfree_verification.py b/plivo/resources/tollfree_verification.py new file mode 100644 index 00000000..0337d755 --- /dev/null +++ b/plivo/resources/tollfree_verification.py @@ -0,0 +1,91 @@ +from ..utils.validators import * + +from ..base import ListResponseObject, PlivoResource, PlivoResourceInterface, ListTollfreeRequestResponseObject, \ + ListSessionResponseObject +from ..exceptions import * +from ..utils import * + + +class TollFreeVerificationRequest(PlivoResource): + _name = 'TollFreeVerificationRequest' + _identifier_string = 'uuid' + + def delete(self): + return self.client.tollfree_verification.delete(self.uuid) + + def update(self, + profile_uuid=None, + usecase=None, + usecase_summary=None, + message_sample=None, + optin_image_url=None, + volume=None, + additional_information=None, + extra_data=None, + optin_type=None, + callback_url=None, + callback_method=None): + return self.client.tollfree_verification.update(self.uuid, profile_uuid=profile_uuid, usecase=usecase, + usecase_summary=usecase_summary, message_sample=message_sample, + optin_image_url=optin_image_url, volume=volume, + additional_information=additional_information, + extra_data=extra_data, optin_type=optin_type, + callback_url=callback_url, callback_method=callback_method) + +class TollFreeVerificationRequests(PlivoResourceInterface): + def __init__(self, client): + self._resource_type = TollFreeVerificationRequest + super(TollFreeVerificationRequests, self).__init__(client) + + def create(self, + profile_uuid=None, + usecase=None, + usecase_summary=None, + message_sample=None, + optin_image_url=None, + volume=None, + number=None, + additional_information=None, + extra_data=None, + optin_type=None, + callback_url=None, + callback_method=None): + return self.client.request( + 'POST', ('TollfreeVerification',), to_param_dict(self.create, locals())) + + def get(self, tollfree_verification_uuid=None): + return self.client.request( + 'GET', ('TollfreeVerification', tollfree_verification_uuid), response_type=TollFreeVerificationRequest) + + def list(self, + number=None, + status=None, + profile_uuid=None, + created_gt=None, + created_gte=None, + created_lt=None, + created_lte=None, + usecase=None, + limit=20, + offset=0): + return self.client.request( + 'GET', ('TollfreeVerification',), to_param_dict(self.list, locals()), + objects_type=TollFreeVerificationRequest, response_type=ListTollfreeRequestResponseObject, ) + + def update(self, tollfree_verification_uuid=None, + profile_uuid=None, + usecase=None, + usecase_summary=None, + message_sample=None, + optin_image_url=None, + volume=None, + additional_information=None, + extra_data=None, + optin_type=None, + callback_url=None, + callback_method=None): + return self.client.request( + 'POST', ('TollfreeVerification', tollfree_verification_uuid), to_param_dict(self.update, locals())) + + def delete(self, tollfree_verification_uuid): + return self.client.request('DELETE', ('TollfreeVerification', tollfree_verification_uuid)) diff --git a/plivo/rest/client.py b/plivo/rest/client.py index ce459cf6..deeb2410 100644 --- a/plivo/rest/client.py +++ b/plivo/rest/client.py @@ -14,7 +14,8 @@ from plivo.resources import (Accounts, Addresses, Applications, Calls, Token, Conferences, Endpoints, Identities, Messages, Powerpacks, Media, Lookup, Brand, Campaign, Profile, - Numbers, Pricings, Recordings, Subaccounts, CallFeedback, MultiPartyCalls, Sessions) + Numbers, Pricings, Recordings, Subaccounts, CallFeedback, MultiPartyCalls, Sessions, + TollFreeVerificationRequests) from plivo.resources.live_calls import LiveCalls from plivo.resources.maskingsession import MaskingSessions from plivo.resources.verify_callerid import VerifyCallerids @@ -101,6 +102,7 @@ def __init__(self, auth_id=None, auth_token=None, proxies=None, timeout=5): self.messages = Messages(self) self.lookup = Lookup(self) self.numbers = Numbers(self) + self.tollfree_request = TollFreeVerificationRequests(self) self.powerpacks = Powerpacks(self) self.brand = Brand(self) self.campaign = Campaign(self)