Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/plivo_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Copyright (c) 2011 Plivo Team. See LICENSE for details.


PLIVO_GIT_REPO=git://github.com/plivo/plivo.git
PLIVO_SETUP_SCRIPT=https://github.com/plivo/plivo/raw/master/scripts/ez_setup.py
PLIVO_GIT_REPO=git://github.com/digination/plivo.git
PLIVO_SETUP_SCRIPT=https://github.com/digination/plivo/raw/master/scripts/ez_setup.py


BRANCH=$2
Expand Down
147 changes: 147 additions & 0 deletions src/plivo/rest/freeswitch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2205,3 +2205,150 @@ def send_digits(self):
result = True
return self.send_response(Success=result, Message=msg)

@auth_protect
def bridge(self):
"""Creates a bridge between 2 calls given their uuids.
In order To bridge two calls, make an HTTP POST request to a
resource URI.

POST Parameters
---------------

Required Parameters - You must POST the following parameters:

CallUUID1: Unique Call ID of the first call to bridge.
CallUUID2: Unique Call ID of the second call to bridge.

"""
self._rest_inbound_socket.log.debug("RESTAPI Bridge with %s" \
% str(request.form.items()))
msg = ""
result = False

calluuid1 = get_post_param(request, 'callUUID1')
calluuid2 = get_post_param(request, 'callUUID2')

if not calluuid1 or not calluuid2:
msg = "CallUUID Parameter Missing"
return self.send_response(Success=result, Message=msg)

cmd = "uuid_bridge %s %s" % (calluuid1,calluuid2)
res = self._rest_inbound_socket.bgapi(cmd)
job_uuid = res.get_job_uuid()
if not job_uuid:
self._rest_inbound_socket.log.error("Calls bridging failed -- JobUUID not received" % job_uuid)
msg = "Bridging failed"
return self.send_response(Success=result, Message=msg)

msg = "Bridge executed"
result = True
return self.send_response(Success=result, Message=msg)

@auth_protect
def command_exec(self):
"""Executes an arbitrary command through Event Socket

POST Parameters
---------------

Required Parameters - You must POST the following parameters:

command: the command string with its arguments.
bg: tells if the command must in run through bgapi or not
"""
self._rest_inbound_socket.log.debug("RESTAPI Command with %s" \
% str(request.form.items()))
msg = ""
result = False

cmd = get_post_param(request, 'command')
bg = get_post_param(request, 'bg')

if not cmd:
msg = "command Parameter Missing"
return self.send_response(Success=result, Message=msg)
if not bg:
msg = "command Parameter Missing"
return self.send_response(Success=result, Message=msg)


if (bg == "true"):

res = self._rest_inbound_socket.bgapi(cmd)
job_uuid = res.get_job_uuid()
if not job_uuid:
self._rest_inbound_socket.log.error("command '%s' failed -- JobUUID not received" % (cmd,job_uuid))
msg = "Command failed"
return self.send_response(Success=result, Message=msg)

msg = job_uuid
result = True
return self.send_response(Success=result, Message=msg)

else:
res = self._rest_inbound_socket.api(cmd)
msg = res.get_response()
result = True
return self.send_response(Success=result, Message=msg)


@auth_protect
def get_var(self):
"""Get Contextual variables given UUID

POST Parameters
---------------

Required Parameters - You must POST the following parameters:

UUID: the call/bridge uuid
varName: name of the variable to retrieve
"""
self._rest_inbound_socket.log.debug("RESTAPI Command with %s" \
% str(request.form.items()))
msg = ""
result = False

uuid = get_post_param(request, 'UUID')
var_name = get_post_param(request, 'varName')

if not uuid:
msg = "UUID Parameter Missing"
return self.send_response(Success=result, Message=msg)
if not var_name:
msg = "varName Parameter Missing"
return self.send_response(Success=result, Message=msg)

cmd="uuid_getvar %s %s" % (uuid,var_name)
res = self._rest_inbound_socket.api(cmd)
#job_uuid = res.get_job_uuid()
#if not job_uuid:
#self._rest_inbound_socket.log.error("command '%s' failed -- JobUUID not received" % (cmd,job_uuid))
#msg = "Command failed"
#return self.send_response(Success=result, Message=msg)

msg = res.get_response()
result = True
return self.send_response(Success=result, Message=msg)

@auth_protect
def create_uuid(self):
"""Creates and return an uuid

POST Parameters
---------------

Required Parameters - You must POST the following parameters:
None
"""
self._rest_inbound_socket.log.debug("RESTAPI Command with %s" \
% str(request.form.items()))
msg = ""
result = False

cmd="create_uuid"
res = self._rest_inbound_socket.api(cmd)
msg = res.get_response()
result = True
return self.send_response(Success=result, Message=msg)

8 changes: 8 additions & 0 deletions src/plivo/rest/freeswitch/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@
'/' + PLIVO_VERSION + '/ConferenceListMembers/': (PlivoRestApi.conference_list_members, ['POST']),
# API to list all conferences with members
'/' + PLIVO_VERSION + '/ConferenceList/': (PlivoRestApi.conference_list, ['POST']),
# API to execute a raw ESL command
'/' + PLIVO_VERSION + '/Command/': (PlivoRestApi.command_exec, ['POST']),
# API to create a bridge between two calls given their uuids
'/' + PLIVO_VERSION + '/Bridge/': (PlivoRestApi.bridge, ['POST']),
# API to get contextual variables given UUID
'/' + PLIVO_VERSION + '/GetVar/': (PlivoRestApi.get_var, ['POST']),
# API to create a new uuid
'/' + PLIVO_VERSION + '/CreateUUID/': (PlivoRestApi.create_uuid, ['POST']),
}