Skip to content

Commit

Permalink
Merge pull request #131 from plivo/diff_base_url_voice_and_retry
Browse files Browse the repository at this point in the history
change base url and add retries for voice requests
  • Loading branch information
nixonsam authored Jul 21, 2020
2 parents 8779d2c + db750a5 commit 7e50019
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 53 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [4.9.0](https://github.com/plivo/plivo-python/tree/v4.8.1) (2020-07-21)
- Add retries to other regions for voice requests.

## [4.8.1](https://github.com/plivo/plivo-python/tree/v4.8.1) (2020-06-12)
- Fix SMS Test cases.

Expand Down
12 changes: 5 additions & 7 deletions plivo/resources/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,12 @@ def create(self,
if subaccount:
if isinstance(subaccount, Subaccount):
subaccount = subaccount.id

return self.client.request('POST', ('Application', ),
to_param_dict(self.create, locals()))
return self.client.request('POST', ('Application', ), to_param_dict(self.create, locals()), is_voice_request=True)

@validate_args(app_id=[of_type(six.text_type)])
def get(self, app_id):
return self.client.request(
'GET', ('Application', app_id), response_type=Application)
'GET', ('Application', app_id), response_type=Application, is_voice_request=True)

@validate_args(
subaccount=[optional(is_subaccount())],
Expand All @@ -106,7 +104,7 @@ def list(self, subaccount=None, limit=20, offset=0):
'GET', ('Application', ),
to_param_dict(self.list, locals()),
response_type=ListResponseObject,
objects_type=Application)
objects_type=Application, is_voice_request=True)

@validate_args(
answer_url=[is_url()],
Expand Down Expand Up @@ -140,7 +138,7 @@ def update(self,
if isinstance(subaccount, Subaccount):
subaccount = subaccount.id
return self.client.request('POST', ('Application', app_id),
to_param_dict(self.update, locals()))
to_param_dict(self.update, locals()), is_voice_request=True)

@validate_args(
app_id=[of_type(six.text_type)],
Expand All @@ -149,4 +147,4 @@ def update(self,
)
def delete(self, app_id, cascade=None, new_endpoint_application=None):
return self.client.request('DELETE', ('Application', app_id),
to_param_dict(self.delete, locals()))
to_param_dict(self.delete, locals()), is_voice_request=True)
32 changes: 15 additions & 17 deletions plivo/resources/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ class Call(PlivoResource):
_identifier_string = 'call_uuid'

def update(self,
call_uuid,
legs=None,
aleg_url=None,
aleg_method=None,
bleg_url=None,
bleg_method=None):
return self.client.calls.update(call_uuid,
return self.client.calls.update(self.id,
**to_param_dict(self.update, locals()))

def get(self):
Expand Down Expand Up @@ -73,7 +72,7 @@ def speak(self,
language=None,
legs=None,
loop=None,
mix=None):
mix=None, is_voice_request=True):
return self.client.calls.speak(self.id,
**to_param_dict(self.start_playing,
locals()))
Expand Down Expand Up @@ -157,9 +156,7 @@ def create(self,
error_if_parent_not_found=False):
if from_ in to_.split('<'):
raise ValidationError('src and destination cannot overlap')

return self.client.request('POST', ('Call', ),
to_param_dict(self.create, locals()))
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 @@ -217,11 +214,12 @@ def list(self,
('Call', ),
to_param_dict(self.list, locals()),
response_type=ListResponseObject,
is_voice_request=True
)

@validate_args(call_uuid=[of_type(six.text_type)])
def get(self, call_uuid):
return self.client.request('GET', ('Call', call_uuid))
return self.client.request('GET', ('Call', call_uuid), is_voice_request=True)

@validate_args(
call_uuid=[of_type(six.text_type)],
Expand All @@ -240,7 +238,7 @@ def update(self,
bleg_url=None,
bleg_method=None):
return self.client.request('POST', ('Call', call_uuid),
to_param_dict(self.update, locals()))
to_param_dict(self.update, locals()), is_voice_request=True)

def transfer(self,
call_uuid,
Expand Down Expand Up @@ -282,14 +280,14 @@ def start_recording(self,
callback_mathod=None):
return self.client.request('POST', ('Call', call_uuid, 'Record'),
to_param_dict(self.start_recording,
locals()))
locals()), is_voice_request=True)

def record_stop(self, call_uuid):
return self.client.calls.stop_recording(call_uuid)

@validate_args(call_uuid=[of_type(six.text_type)])
def stop_recording(self, call_uuid):
return self.client.request('DELETE', ('Call', call_uuid, 'Record'))
return self.client.request('DELETE', ('Call', call_uuid, 'Record'), is_voice_request=True)

@validate_args(call_uuid=[of_type(six.text_type)])
def play(self,
Expand All @@ -310,14 +308,14 @@ def start_playing(self,
loop=None,
mix=None):
return self.client.request('POST', ('Call', call_uuid, 'Play'),
to_param_dict(self.play, locals()))
to_param_dict(self.play, locals()), is_voice_request=True)

def play_stop(self, call_uuid):
return self.client.calls.stop_playing(call_uuid)

@validate_args(call_uuid=[of_type(six.text_type)])
def stop_playing(self, call_uuid):
return self.client.request('DELETE', ('Call', call_uuid, 'Play'))
return self.client.request('DELETE', ('Call', call_uuid, 'Play'), is_voice_request=True)

@validate_args(call_uuid=[of_type(six.text_type)])
def speak(self,
Expand All @@ -342,30 +340,30 @@ def start_speaking(self,
mix=None):
return self.client.request('POST', ('Call', call_uuid, 'Speak'),
to_param_dict(self.start_speaking,
locals()))
locals()), is_voice_request=True)

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

def speak_stop(self, call_uuid):
return self.client.calls.stop_speaking(call_uuid)

@validate_args(call_uuid=[of_type(six.text_type)])
def send_digits(self, call_uuid, digits, leg=None):
return self.client.request('POST', ('Call', call_uuid, 'DTMF'),
to_param_dict(self.send_digits, locals()))
to_param_dict(self.send_digits, locals()), is_voice_request=True)

@validate_args(call_uuid=[of_type(six.text_type)])
def delete(self, call_uuid):
return self.client.request('DELETE', ('Call', call_uuid))
return self.client.request('DELETE', ('Call', call_uuid), is_voice_request=True)

@validate_args(call_uuid=[of_type(six.text_type)])
def hangup(self, call_uuid):
return self.client.calls.delete(call_uuid)

def cancel(self, request_uuid):
return self.client.request('DELETE', ('Request', request_uuid))
return self.client.request('DELETE', ('Request', request_uuid), is_voice_request=True)

def live_call_list_ids(self, limit=None, offset=None):
return self.client.live_calls.list_ids(limit, offset)
Expand Down
32 changes: 16 additions & 16 deletions plivo/resources/conferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ class Conferences(PlivoResourceInterface):
_iterable = False

def list(self):
return self.client.request('GET', ('Conference', ))
return self.client.request('GET', ('Conference', ), is_voice_request=True)

def get(self, conference_name):
return self.client.request('GET', ('Conference', conference_name))
return self.client.request('GET', ('Conference', conference_name), is_voice_request=True)

def delete(self, conference_name):
return self.client.request('DELETE', ('Conference', conference_name))
return self.client.request('DELETE', ('Conference', conference_name), is_voice_request=True)

def delete_all(self):
return self.client.request('DELETE', ('Conference', ))
return self.client.request('DELETE', ('Conference', ), is_voice_request=True)

def hangup_all(self):
return self.delete_all()
Expand All @@ -109,52 +109,52 @@ def member_speak(self,
return self.client.request(
'POST',
('Conference', conference_name, 'Member', member_id, 'Speak'),
to_param_dict(self.member_speak, locals()))
to_param_dict(self.member_speak, locals()), is_voice_request=True)

def member_play(self, conference_name, member_id, url):
return self.client.request(
'POST',
('Conference', conference_name, 'Member', member_id, 'Play'),
to_param_dict(self.member_play, locals()))
to_param_dict(self.member_play, locals()), is_voice_request=True)

def member_deaf(self, conference_name, member_id):
return self.client.request(
'POST',
('Conference', conference_name, 'Member', member_id, 'Deaf'))
('Conference', conference_name, 'Member', member_id, 'Deaf'), is_voice_request=True)

def member_mute(self, conference_name, member_id):
return self.client.request(
'POST',
('Conference', conference_name, 'Member', member_id, 'Mute'))
('Conference', conference_name, 'Member', member_id, 'Mute'), is_voice_request=True)

def member_speak_stop(self, conference_name, member_id):
return self.client.request(
'DELETE',
('Conference', conference_name, 'Member', member_id, 'Speak'))
('Conference', conference_name, 'Member', member_id, 'Speak'), is_voice_request=True)

def member_play_stop(self, conference_name, member_id):
return self.client.request(
'DELETE',
('Conference', conference_name, 'Member', member_id, 'Play'))
('Conference', conference_name, 'Member', member_id, 'Play'), is_voice_request=True)

def member_deaf_stop(self, conference_name, member_id):
return self.client.request(
'DELETE',
('Conference', conference_name, 'Member', member_id, 'Deaf'))
('Conference', conference_name, 'Member', member_id, 'Deaf'), is_voice_request=True)

def member_mute_stop(self, conference_name, member_id):
return self.client.request(
'DELETE',
('Conference', conference_name, 'Member', member_id, 'Mute'))
('Conference', conference_name, 'Member', member_id, 'Mute'), is_voice_request=True)

def member_kick(self, conference_name, member_id):
return self.client.request(
'POST',
('Conference', conference_name, 'Member', member_id, 'Kick'))
('Conference', conference_name, 'Member', member_id, 'Kick'), is_voice_request=True)

def member_hangup(self, conference_name, member_id):
return self.client.request(
'DELETE', ('Conference', conference_name, 'Member', member_id))
'DELETE', ('Conference', conference_name, 'Member', member_id), is_voice_request=True)

def record(self,
conference_name,
Expand All @@ -165,8 +165,8 @@ def record(self,
callback_url=None,
callback_method=None):
return self.client.request('POST',
('Conference', conference_name, 'Record'))
('Conference', conference_name, 'Record'), is_voice_request=True)

def record_stop(self, conference_name):
return self.client.request('DELETE',
('Conference', conference_name, 'Record'))
('Conference', conference_name, 'Record'), is_voice_request=True)
10 changes: 5 additions & 5 deletions plivo/resources/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class Endpoints(PlivoResourceInterface):
app_id=[optional(of_type(six.text_type))])
def create(self, username, password, alias, app_id=None):
return self.client.request('POST', ('Endpoint', ),
to_param_dict(self.create, locals()))
to_param_dict(self.create, locals()), is_voice_request=True)

@validate_args(endpoint_id=[of_type(six.text_type)])
def get(self, endpoint_id):
return self.client.request('GET', ('Endpoint', endpoint_id))
return self.client.request('GET', ('Endpoint', endpoint_id), is_voice_request=True)

@validate_args(
limit=[
Expand All @@ -57,7 +57,7 @@ def list(self, limit=20, offset=0):
('Endpoint', ),
to_param_dict(self.list, locals()),
objects_type=Endpoint,
response_type=ListResponseObject)
response_type=ListResponseObject, is_voice_request=True)

@validate_args(
endpoint_id=[of_type(six.text_type)],
Expand All @@ -66,8 +66,8 @@ def list(self, limit=20, offset=0):
app_id=[optional(of_type(six.text_type))])
def update(self, endpoint_id, password=None, alias=None, app_id=None):
return self.client.request('POST', ('Endpoint', endpoint_id),
to_param_dict(self.update, locals()))
to_param_dict(self.update, locals()), is_voice_request=True)

@validate_args(endpoint_id=[of_type(six.text_type)])
def delete(self, endpoint_id):
return self.client.request('DELETE', ('Endpoint', endpoint_id))
return self.client.request('DELETE', ('Endpoint', endpoint_id), is_voice_request=True)
4 changes: 2 additions & 2 deletions plivo/resources/live_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def list_ids(self,
):
params = to_param_dict(self.list_ids, locals())
params.update({'status': 'live'})
return self.client.request('GET', ('Call',), params)
return self.client.request('GET', ('Call',), params, is_voice_request=True)

@validate_args(_id=[of_type(six.text_type)])
def get(self, _id):
return self.client.request(
'GET', ('Call', _id), {'status': 'live'}
'GET', ('Call', _id), {'status': 'live'}, is_voice_request=True
)
4 changes: 2 additions & 2 deletions plivo/resources/queued_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def list_ids(self, limit=20, offset=0):
'status': 'queued',
'limit': limit,
'offset': offset,
})
}, is_voice_request=True)

@validate_args(_id=[of_type(six.text_type)])
def get(self, _id):
return self.client.request('GET', ('Call', _id), {'status': 'queued'})
return self.client.request('GET', ('Call', _id), {'status': 'queued'}, is_voice_request=True)
5 changes: 3 additions & 2 deletions plivo/resources/recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ def list(self,
to_param_dict(self.list, locals()),
objects_type=Recording,
response_type=ListResponseObject,
is_voice_request=True
)

@validate_args(recording_id=[of_type(six.text_type)])
def get(self, recording_id):
return self.client.request(
'GET', ('Recording', recording_id), response_type=Recording)
'GET', ('Recording', recording_id), response_type=Recording, is_voice_request=True)

@validate_args(recording_id=[of_type(six.text_type)])
def delete(self, recording_id):
return self.client.request('DELETE', ('Recording', recording_id))
return self.client.request('DELETE', ('Recording', recording_id), is_voice_request=True)
Loading

0 comments on commit 7e50019

Please sign in to comment.