Skip to content

Commit

Permalink
Python SDK development for tollfree verification
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-gupta-plivo committed Oct 30, 2023
1 parent 489edb8 commit 8dc3abb
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
36 changes: 36 additions & 0 deletions plivo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions plivo/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
from .profile import Profile
from .multipartycall import MultiPartyCalls, MultiPartyCall, MultiPartyCallParticipant
from .verify import Sessions
from .tollfree_verification import TollFreeVerificationRequests
91 changes: 91 additions & 0 deletions plivo/resources/tollfree_verification.py
Original file line number Diff line number Diff line change
@@ -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))
4 changes: 3 additions & 1 deletion plivo/rest/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8dc3abb

Please sign in to comment.