Skip to content

Commit

Permalink
Verify Caller ID - Python Changes (#248)
Browse files Browse the repository at this point in the history
* Verify Caller ID - Python Changes

* added SDK version
  • Loading branch information
Abinaya-Shunmugavel authored Oct 18, 2023
1 parent a3beecb commit b11ce35
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [4.43.0](https://github.com/plivo/plivo-python/tree/v4.43.0) (2023-10-18)
**Feature - Verify CallerID**
- Added Initiate and Verify VerifyCallerID API
- Added Update, Delete, Get and List verified CallerIDs API

## [4.42.0](https://github.com/plivo/plivo-python/tree/v4.42.0) (2023-10-16)
**Introducing campaign_source**
- Added campaign_source in GET / LIST campaign APIs
Expand Down
4 changes: 4 additions & 0 deletions plivo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ class ResourceNotFoundError(PlivoRestError):

class ValidationError(PlivoRestError):
pass


class ForbiddenError(PlivoRestError):
pass
84 changes: 84 additions & 0 deletions plivo/resources/verify_callerid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from plivo.base import (ListResponseObject, PlivoResource,
PlivoResourceInterface)
from plivo.utils import to_param_dict


class VerifyCallerid(PlivoResource):
_name = 'VerifyCallerid'

def initiate_verify(self):
return self.client.calls.initiate_verify(self.id,
**to_param_dict(self.initiate_verify(), locals()))

def verify_caller_id(self):
return self.client.calls.verify_caller_id(self.id,
**to_param_dict(self.verify_caller_id(), locals()))

def delete_verified_caller_id(self):
return self.client.calls.delete_verified_caller_id(self.id,
**to_param_dict(self.delete_verified_caller_id(), locals()))

def get_verified_caller_id(self):
return self.client.calls.get_verified_caller_id(self.id,
**to_param_dict(self.get_verified_caller_id(), locals()))

def update_verified_caller_id(self):
return self.client.calls.update_verified_caller_id(self.id,
**to_param_dict(self.update_verified_caller_id(), locals()))

def list_verified_caller_id(self):
return self.client.calls.list_verified_caller_id(self.id,
**to_param_dict(self.list_verified_caller_id(), locals()))


class VerifyCallerids(PlivoResourceInterface):
_resource_type = VerifyCallerid

def initiate_verify(self,
phone_number=None,
alias=None,
channel=None,
country=None,
subaccount=None,
account_id=None,
auth_id=None,
auth_token=None
):
return self.client.request('POST', ('VerifiedCallerId',),
to_param_dict(self.initiate_verify, locals()), is_voice_request=True)

def verify_caller_id(self,
verification_uuid,
otp=None,
):
return self.client.request('POST', ('VerifiedCallerId', 'Verification', verification_uuid),
to_param_dict(self.verify_caller_id, locals()), is_voice_request=True)

def delete_verified_caller_id(self,
phone_number
):
return self.client.request('DELETE', ('VerifiedCallerId', phone_number),
to_param_dict(self.delete_verified_caller_id, locals()), is_voice_request=True)

def get_verified_caller_id(self,
phone_number
):
return self.client.request('GET', ('VerifiedCallerId', phone_number), is_voice_request=True)

def update_verified_caller_id(self,
phone_number,
alias=None,
subaccount=None
):
return self.client.request('POST', ('VerifiedCallerId', phone_number),
to_param_dict(self.update_verified_caller_id, locals()), is_voice_request=True)

def list_verified_caller_id(self,
country=None,
subaccount=None,
alias=None,
limit=None,
offset=None
):
return self.client.request('GET', ('VerifiedCallerId',), to_param_dict(self.list_verified_caller_id, locals()),
is_voice_request=True)
13 changes: 11 additions & 2 deletions plivo/rest/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
from plivo.base import ResponseObject
from plivo.exceptions import (AuthenticationError, InvalidRequestError,
PlivoRestError, PlivoServerError,
ResourceNotFoundError, ValidationError)
from plivo.resources import (Accounts, Addresses, Applications, Calls,Token,
ResourceNotFoundError, ValidationError, ForbiddenError)
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)
from plivo.resources.live_calls import LiveCalls
from plivo.resources.maskingsession import MaskingSessions
from plivo.resources.verify_callerid import VerifyCallerids
from plivo.resources.profile import Profile
from plivo.resources.queued_calls import QueuedCalls
from plivo.resources.regulatory_compliance import EndUsers, ComplianceDocumentTypes, ComplianceDocuments, \
Expand Down Expand Up @@ -119,6 +120,7 @@ def __init__(self, auth_id=None, auth_token=None, proxies=None, timeout=5):
self.masking_sessions = MaskingSessions(self)
self.voice_retry_count = 0
self.verify_session = Sessions(self)
self.verify_callerids = VerifyCallerids(self)

def __enter__(self):
return self
Expand Down Expand Up @@ -164,6 +166,13 @@ def process_response(self,
'Failed to authenticate while accessing resource at: '
'{url}'.format(url=response.url))

if response.status_code == 403:
if response_json and 'error' in response_json:
raise ForbiddenError(response_json.error)
raise ForbiddenError(
'Request Failed : '
'{url}'.format(url=response.url))

if response.status_code == 404:
if response_json and 'error' in response_json:
raise ResourceNotFoundError(response_json.error)
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.42.0'
__version__ = '4.43.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.42.0',
version='4.43.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
10 changes: 10 additions & 0 deletions tests/resources/fixtures/verifyCalleridGetResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"alias": "test",
"api_id": "ee7c3cb1-c921-42c9-832b-950fb8344b9b",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"subaccount": "",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
}
5 changes: 5 additions & 0 deletions tests/resources/fixtures/verifyCalleridInitiateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"api_id": "2a5e81d7-deb3-46cd-ac34-c05ca9139b6f",
"message": "Verification code is sent to number +919768368717 which is valid for 15 minutes",
"verification_uuid": "407796a6-1f3e-4607-a9d9-5a5376b59a7b"
}
52 changes: 52 additions & 0 deletions tests/resources/fixtures/verifyCalleridListResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"api_id": "3b21c7d7-09f7-489b-b753-659814a676bf",
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 4
},
"objects": [
{
"alias": "abhishek",
"country": "IN",
"created_at": "2023-09-25T14:40:38.68729Z",
"modified_at": "2023-09-25T14:40:38.68729Z",
"phone_number": "+919653244280",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919653244280",
"subaccount": "",
"verification_uuid": "01be6b07-b106-46e2-8dfc-096d8e22cc0e"
},
{
"alias": "abhishek",
"country": "IN",
"created_at": "2023-09-25T13:10:39.968133Z",
"modified_at": "2023-09-25T13:10:39.968133Z",
"phone_number": "+919768368717",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919768368717",
"subaccount": "",
"verification_uuid": "2e68eb73-4d54-4391-bc98-71cd380911a4"
},
{
"alias": "test",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919768368718",
"subaccount": "",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
},
{
"alias": "Test2",
"country": "",
"created_at": "2023-08-30T07:47:43.87171Z",
"modified_at": "2023-08-30T07:47:43.87171Z",
"phone_number": "+917691021365",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/917691021365",
"subaccount": "SAMTU0Y2FKNGETYZDKNI",
"verification_uuid": "20265c57-2d8e-46fe-8fa8-e8ab4ee58a8c"
}
]
}
10 changes: 10 additions & 0 deletions tests/resources/fixtures/verifyCalleridUpdateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"alias": "testAbhishek",
"api_id": "6b143cb3-9c8a-42ad-b6b7-412ebd5c60a9",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"subaccount": "SAMTU0Y2FKNGETYZDKNI",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
}
9 changes: 9 additions & 0 deletions tests/resources/fixtures/verifyCalleridVerifyResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"alias": "abhishek",
"api_id": "584a97aa-ca1d-44f2-9dd3-e58fbacd6649",
"channel": "call",
"country": "IN",
"created_at": "2023-09-25T13:10:39.968133341Z",
"phone_number": "+919768368717",
"verification_uuid": "2e68eb73-4d54-4391-bc98-71cd380911a4"
}
56 changes: 56 additions & 0 deletions tests/resources/test_verifycallerids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from tests.base import PlivoResourceTestCase
from tests.decorators import with_response


class VerifyCalleridTest(PlivoResourceTestCase):
@with_response(201)
def test_initiate(self):
self.client.verify_callerids.initiate_verify(phone_number='917708772011',
alias='test',
channel='call')
self.assertEqual(self.client.current_request.method, 'POST')
self.assertUrlEqual(
self.get_voice_url('VerifiedCallerId'), self.client.current_request.url)

@with_response(201)
def test_verify(self):
verification_uuid = 'eeab1477-e59b-4821-9e61-fd5847c2a5db'
self.client.verify_callerids.verify_caller_id(
verification_uuid='eeab1477-e59b-4821-9e61-fd5847c2a5db', otp='610534')
self.assertEqual(self.client.current_request.method, 'POST')
self.assertUrlEqual(
self.get_voice_url('VerifiedCallerId', 'Verification', verification_uuid), self.client.current_request.url)

@with_response(200)
def test_delete(self):
phone_number = "917708772011"
self.client.verify_callerids.delete_verified_caller_id(
phone_number)
self.assertEqual(self.client.current_request.method, 'DELETE')
self.assertUrlEqual(
self.get_voice_url('VerifiedCallerId', phone_number), self.client.current_request.url)

@with_response(200)
def test_get(self):
phone_number = "917708772011"
self.client.verify_callerids.get_verified_caller_id(phone_number)
self.assertEqual(self.client.current_request.method, 'GET')
self.assertUrlEqual(
self.get_voice_url('VerifiedCallerId', phone_number), self.client.current_request.url)

@with_response(200)
def test_update(self):
phone_number = "917708772011"
self.client.verify_callerids.update_verified_caller_id(
phone_number=phone_number,
alias='test123')
self.assertEqual(self.client.current_request.method, 'POST')
self.assertUrlEqual(
self.get_voice_url('VerifiedCallerId', phone_number), self.client.current_request.url)

@with_response(200)
def test_list(self):
self.client.verify_callerids.list_verified_caller_id()
self.assertEqual(self.client.current_request.method, 'GET')
self.assertUrlEqual(
self.get_voice_url('VerifiedCallerId'), self.client.current_request.url)

0 comments on commit b11ce35

Please sign in to comment.