Skip to content

Commit

Permalink
Merge branch 'blinky-lights' of git://github.com/asterisk/ari-py
Browse files Browse the repository at this point in the history
Closes asterisk#1.

Signed-off-by: David M. Lee <[email protected]>

Conflicts:
	ari/model.py
	ari_test/client_test.py
  • Loading branch information
leedm777 committed Mar 4, 2014
2 parents 6a6c842 + 450099e commit b04968e
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ari/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ def on_endpoint_event(self, event_type, fn):
"""
return self.on_object_event(event_type, fn, Endpoint, 'Endpoint')

def on_device_state_event(self, event_type, fn):
"""Register callback for DeviceState related events
:param event_type: String name of the event to register for.
:param fn: Callback function
:type fn: (DeviceState, dict) -> None or (list[DeviceState], dict) -> None
"""
return self.on_object_event(event_type, fn, DeviceState, 'DeviceState')

def on_sound_event(self, event_type, fn):
"""Register callback for Sound related events
Expand Down
18 changes: 17 additions & 1 deletion ari/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ def __init__(self, client, endpoint_json):
client.on_endpoint_event)


class DeviceState(BaseObject):
"""First class object API.
:param client: ARI client.
:type client: client.Client
:param endpoint_json: Instance data
"""
id_generator = DefaultObjectIdGenerator('deviceName', id_field='name')

def __init__(self, client, device_state_json):
super(DeviceState, self).__init__(
client, client.swagger.devicestates, device_state_json,
client.on_device_state_event)


class Sound(BaseObject):
"""First class object API.
Expand Down Expand Up @@ -361,5 +376,6 @@ def promote(client, resp, operation_json):
'Playback': Playback,
'LiveRecording': LiveRecording,
'StoredRecording': StoredRecording,
'Mailbox': Mailbox
'Mailbox': Mailbox,
'DeviceState': DeviceState,
}
9 changes: 9 additions & 0 deletions ari_test/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ def test_mailboxes(self):
self.assertEqual('1', mailbox['old_messages'])
self.assertEqual('3', mailbox['new_messages'])

def test_device_state(self):
self.serve(PUT, 'deviceStates', 'foobar',
body='{"name": "foobar", "state": "BUSY"}')
device_state = self.uut.deviceStates.update(
deviceName='foobar',
deviceState='BUSY')
self.assertEqual('foobar', device_state['name'])
self.assertEqual('BUSY', device_state['state'])

def setUp(self):
super(ClientTest, self).setUp()
self.uut = ari.connect('http://ari.py/', 'test', 'test')
Expand Down
151 changes: 151 additions & 0 deletions sample-api/deviceStates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"_copyright": "Copyright (C) 2012 - 2013, Digium, Inc.",
"_author": "Kevin Harwell <[email protected]>",
"_svn_revision": "$Revision: 407402 $",
"apiVersion": "0.0.0-test",
"swaggerVersion": "1.1",
"basePath": "http://ari.py/ari",
"resourcePath": "/api-docs/deviceStates.{format}",
"apis": [
{
"path": "/deviceStates",
"description": "Device states",
"operations": [
{
"httpMethod": "GET",
"summary": "List all ARI controlled device states.",
"nickname": "list",
"responseClass": "List[DeviceState]"
}
]
},
{
"path": "/deviceStates/{deviceName}",
"description": "Device state",
"operations": [
{
"httpMethod": "GET",
"summary": "Retrieve the current state of a device.",
"nickname": "get",
"responseClass": "DeviceState",
"parameters": [
{
"name": "deviceName",
"description": "Name of the device",
"paramType": "path",
"required": true,
"allowMultiple": false,
"dataType": "string"
}
]
},
{
"httpMethod": "PUT",
"summary": "Change the state of a device controlled by ARI. (Note - implicitly creates the device state).",
"nickname": "update",
"responseClass": "void",
"parameters": [
{
"name": "deviceName",
"description": "Name of the device",
"paramType": "path",
"required": true,
"allowMultiple": false,
"dataType": "string"
},
{
"name": "deviceState",
"description": "Device state value",
"paramType": "query",
"required": true,
"allowMultiple": false,
"dataType": "string",
"allowableValues": {
"valueType": "LIST",
"values": [
"NOT_INUSE",
"INUSE",
"BUSY",
"INVALID",
"UNAVAILABLE",
"RINGING",
"RINGINUSE",
"ONHOLD"
]
}

}
],
"errorResponses": [
{
"code": 404,
"reason": "Device name is missing"
},
{
"code": 409,
"reason": "Uncontrolled device specified"
}
]
},
{
"httpMethod": "DELETE",
"summary": "Destroy a device-state controlled by ARI.",
"nickname": "delete",
"responseClass": "void",
"parameters": [
{
"name": "deviceName",
"description": "Name of the device",
"paramType": "path",
"required": true,
"allowMultiple": false,
"dataType": "string"
}
],
"errorResponses": [
{
"code": 404,
"reason": "Device name is missing"
},
{
"code": 409,
"reason": "Uncontrolled device specified"
}
]
}
]
}
],
"models": {
"DeviceState": {
"id": "DeviceState",
"description": "Represents the state of a device.",
"properties": {
"name": {
"type": "string",
"description": "Name of the device.",
"required": true
},
"state": {
"type": "string",
"description": "Device's state",
"required": true,
"allowableValues": {
"valueType": "LIST",
"values": [
"UNKNOWN",
"NOT_INUSE",
"INUSE",
"BUSY",
"INVALID",
"UNAVAILABLE",
"RINGING",
"RINGINUSE",
"ONHOLD"
]
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions sample-api/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"path": "/api-docs/playbacks.{format}",
"description": "Playback control resources"
},
{
"path": "/api-docs/deviceStates.{format}",
"description": "Device state resources"
},
{
"path": "/api-docs/events.{format}",
"description": "WebSocket resource"
Expand Down

0 comments on commit b04968e

Please sign in to comment.