Skip to content

Commit

Permalink
Merge pull request #239 from plivo/VT-6125
Browse files Browse the repository at this point in the history
Python : Number Masking SDK implementation
  • Loading branch information
manjunath-plivo authored Jul 31, 2023
2 parents 4456279 + 2c67ad7 commit 693eda8
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unitTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: UnitTests
strategy:
matrix:
python-version: [ 2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.11]
python-version: [ 3.5, 3.6, 3.7, 3.8, 3.9, 3.11]
os: [macos-latest]
runs-on: ${{ matrix.os }}

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [4.38.0](https://github.com/plivo/plivo-python/tree/v4.38.0) (2022-07-31)
**Feature - Number Masking**
- Added Create, Delete, Update, Get and List Masking Session API

## [4.37.0](https://github.com/plivo/plivo-python/tree/v4.37.0) (2022-06-38)
**Feature - Streaming API and XML**
- Added Stream API endpoints
Expand Down
19 changes: 12 additions & 7 deletions plivo/resources/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def create(self,
callback_method=None):
if from_ in to_.split('<'):
raise ValidationError('src and destination cannot overlap')
return self.client.request('POST', ('Call', ), to_param_dict(self.create, locals()), is_voice_request=True)
return self.client.request('POST', ('Call',), to_param_dict(self.create, locals()), is_voice_request=True)

@validate_args(
subaccount=[optional(is_subaccount())],
Expand Down Expand Up @@ -262,14 +262,14 @@ def list(self,
# Adding if else block because if we are fetching response without callback_url then response will be of type
# ListResponseObject, if passing callback_url then will be of type
# {'api_id': '94722e88-ae7c-11ec-b52e-0242ac11000a', 'message': 'async api spawned'}
if callback_url :
if callback_url:
return self.client.request(
'GET',
('Call',),
to_param_dict(self.list, locals()),
is_voice_request=True
)
else :
else:
return self.client.request(
'GET',
('Call',),
Expand Down Expand Up @@ -369,7 +369,8 @@ def record_stop(self, call_uuid, callback_url=None, callback_method=None):
callback_method=[optional(of_type(six.text_type))]
)
def stop_recording(self, call_uuid, callback_url, callback_method):
return self.client.request('DELETE', ('Call', call_uuid, 'Record'), to_param_dict(self.stop_recording, locals()), is_voice_request=True)
return self.client.request('DELETE', ('Call', call_uuid, 'Record'),
to_param_dict(self.stop_recording, locals()), is_voice_request=True)

@validate_args(call_uuid=[of_type(six.text_type)])
def play(self,
Expand Down Expand Up @@ -404,7 +405,8 @@ def play_stop(self, call_uuid, callback_url=None, callback_method=None):
callback_method=[optional(of_type(six.text_type))]
)
def stop_playing(self, call_uuid, callback_url=None, callback_method=None):
return self.client.request('DELETE', ('Call', call_uuid, 'Play'), to_param_dict(self.stop_playing, locals()), is_voice_request=True)
return self.client.request('DELETE', ('Call', call_uuid, 'Play'), to_param_dict(self.stop_playing, locals()),
is_voice_request=True)

@validate_args(call_uuid=[of_type(six.text_type)],
callback_url=[optional(is_url())],
Expand Down Expand Up @@ -442,7 +444,8 @@ def start_speaking(self,

@validate_args(call_uuid=[of_type(six.text_type)])
def stop_speaking(self, call_uuid, callback_url=None, callback_method=None):
return self.client.request('DELETE', ('Call', call_uuid, 'Speak'), to_param_dict(self.stop_speaking, locals()), is_voice_request=True)
return self.client.request('DELETE', ('Call', call_uuid, 'Speak'), to_param_dict(self.stop_speaking, locals()),
is_voice_request=True)

@validate_args(
callback_url=[optional(is_url())],
Expand All @@ -468,7 +471,8 @@ def delete(self,
call_uuid,
callback_url=None,
callback_method=None):
return self.client.request('DELETE', ('Call', call_uuid), to_param_dict(self.delete, locals()), is_voice_request=True)
return self.client.request('DELETE', ('Call', call_uuid), to_param_dict(self.delete, locals()),
is_voice_request=True)

@validate_args(call_uuid=[of_type(six.text_type)])
def hangup(self, call_uuid):
Expand Down Expand Up @@ -542,3 +546,4 @@ def get_details_of_specific_stream(self,
def get_all_streams(self,
call_uuid):
return self.client.request('GET', ('Call', call_uuid, 'Stream'), is_voice_request=True)

110 changes: 110 additions & 0 deletions plivo/resources/maskingsession.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from plivo.base import (ListResponseObject, PlivoResource,
PlivoResourceInterface)
from plivo.utils import to_param_dict
from plivo.utils.validators import *

class MaskingSession(PlivoResource):
_name = 'MaskingSession'
_identifier_string = 'session_uuid'
def create_masking_session(self):
return self.client.calls.create_masking_session(self.id,
**to_param_dict(self.create_masking_session(), locals()))

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

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

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

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


class MaskingSessions(PlivoResourceInterface):
_resource_type = MaskingSession

@validate_args(
callback_url=[optional(is_url())],
recording_callback_url=[optional(is_url())],
first_party_play_url=[optional(is_url())],
second_party_play_url=[optional(is_url())],
)
def create_masking_session(self,
first_party=None,
second_party=None,
session_expiry=None,
call_time_limit=None,
record=None,
record_file_format=None,
recording_callback_url=None,
initiate_call_to_first_party=None,
callback_url=None,
callback_method=None,
ring_timeout=None,
first_party_play_url=None,
second_party_play_url=None,
recording_callback_method=None
):
return self.client.request('POST', ('Masking', 'Session',),
to_param_dict(self.create_masking_session, locals()), is_voice_request=True)

def delete_masking_session(self,
session_uuid
):
return self.client.request('DELETE', ('Masking', 'Session', session_uuid),
to_param_dict(self.delete_masking_session, locals()), is_voice_request=True)

def get_masking_session(self,
session_uuid
):
return self.client.request('GET', ('Masking', 'Session', session_uuid), is_voice_request=True)

def update_masking_session(self,
session_uuid,
session_expiry=None,
call_time_limit=None,
record=None,
record_file_format=None,
recording_callback_url=None,
callback_url=None,
callback_method=None,
ring_timeout=None,
first_party_play_url=None,
second_party_play_url=None,
recording_callback_method=None
):
return self.client.request('POST', ('Masking', 'Session', session_uuid),
to_param_dict(self.update_masking_session, locals()), is_voice_request=True)

def list_masking_session(self,
first_party=None,
second_party=None,
virtual_number=None,
status=None,
created_time=None,
created_time__lt=None,
created_time__lte=None,
created_time__gt=None,
created_time__gte=None,
expiry_time=None,
expiry_time__lt=None,
expiry_time__lte=None,
expiry_time__gt=None,
expiry_time__gte=None,
duration=None,
duration__lt=None,
duration__lte=None,
duration__gt=None,
duration__gte=None,
limit=None,
offset=None
):
return self.client.request('GET', ('Masking', 'Session'), to_param_dict(self.list_masking_session, locals()),
is_voice_request=True)
2 changes: 2 additions & 0 deletions plivo/rest/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Messages, Powerpacks, Media, Lookup, Brand, Campaign, Profile,
Numbers, Pricings, Recordings, Subaccounts, CallFeedback, MultiPartyCalls)
from plivo.resources.live_calls import LiveCalls
from plivo.resources.maskingsession import MaskingSessions
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 @@ -115,6 +116,7 @@ def __init__(self, auth_id=None, auth_token=None, proxies=None, timeout=5):
self.compliance_requirements = ComplianceRequirements(self)
self.compliance_applications = ComplianceApplications(self)
self.multi_party_calls = MultiPartyCalls(self)
self.masking_sessions = MaskingSessions(self)
self.voice_retry_count = 0

def __enter__(self):
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.37.0'
__version__ = '4.38.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.37.0',
version='4.38.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
35 changes: 35 additions & 0 deletions tests/resources/fixtures/maskingSessionCreateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"api_id": "7fef62d3-a451-40ef-95e7-b4ad9969aa1e",
"session_uuid": "bc0a20bb-9f09-4116-b3f8-709def3a89df",
"virtual_number": "+916361728680",
"message": "Session created",
"session": {
"first_party": "917708772011",
"second_party": "919976106830",
"virtual_number": "916361728680",
"status": "active",
"initiate_call_to_first_party": false,
"session_uuid": "bc0a20bb-9f09-4116-b3f8-709def3a89df",
"callback_url": "http://plivobin.non-prod.plivops.com/1jvpmrs1",
"callback_method": "GET",
"created_time": "2023-07-12 15:52:14.772699 +0000 UTC",
"modified_time": "2023-07-12 15:52:14.772699 +0000 UTC",
"expiry_time": "2023-07-12 17:32:14.772699 +0000 UTC",
"duration": 6000,
"amount": 0,
"call_time_limit": 14400,
"ring_timeout": 120,
"first_party_play_url": "https://s3.amazonaws.com/plivosamplexml/play_url.xml",
"second_party_play_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"record": false,
"record_file_format": "mp3",
"recording_callback_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"recording_callback_method": "GET",
"interaction": null,
"total_call_amount": 0,
"total_call_count": 0,
"total_call_billed_duration": 0,
"total_session_amount": 0,
"last_interaction_time": ""
}
}
4 changes: 4 additions & 0 deletions tests/resources/fixtures/maskingSessionDeleteResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"api_id": "f91f459a-283d-4850-9b33-ad914dcb64c0",
"message": "Session Deleted"
}
32 changes: 32 additions & 0 deletions tests/resources/fixtures/maskingSessionGetResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"api_id": "b503c0b9-a419-406f-8e49-9856844600ab",
"response": {
"first_party": "917708772011",
"second_party": "919976106830",
"virtual_number": "916361728680",
"status": "active",
"initiate_call_to_first_party": false,
"session_uuid": "c2146ba4-798d-49b0-8580-53851a16e055",
"callback_url": "http://plivobin.non-prod.plivops.com/w7mf5kw7",
"callback_method": "GET",
"created_time": "2023-07-05 10:25:40.877364 +0000 UTC",
"modified_time": "2023-07-05 10:25:40.877364 +0000 UTC",
"expiry_time": "2023-07-05 12:05:40.877364 +0000 UTC",
"duration": 6000,
"amount": 0,
"call_time_limit": 14400,
"ring_timeout": 120,
"first_party_play_url": "https://s3.amazonaws.com/plivosamplexml/play_url.xml",
"second_party_play_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"record": false,
"record_file_format": "mp3",
"recording_callback_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"recording_callback_method": "GET",
"interaction": null,
"total_call_amount": 0,
"total_call_count": 0,
"total_call_billed_duration": 0,
"total_session_amount": 0,
"last_interaction_time": ""
}
}
Loading

0 comments on commit 693eda8

Please sign in to comment.