Skip to content

Commit b04968e

Browse files
committed
Merge branch 'blinky-lights' of git://github.com/asterisk/ari-py
Closes #1. Signed-off-by: David M. Lee <dlee@digium.com> Conflicts: ari/model.py ari_test/client_test.py
2 parents 6a6c842 + 450099e commit b04968e

File tree

5 files changed

+190
-1
lines changed

5 files changed

+190
-1
lines changed

ari/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ def on_endpoint_event(self, event_type, fn):
237237
"""
238238
return self.on_object_event(event_type, fn, Endpoint, 'Endpoint')
239239

240+
def on_device_state_event(self, event_type, fn):
241+
"""Register callback for DeviceState related events
242+
243+
:param event_type: String name of the event to register for.
244+
:param fn: Callback function
245+
:type fn: (DeviceState, dict) -> None or (list[DeviceState], dict) -> None
246+
"""
247+
return self.on_object_event(event_type, fn, DeviceState, 'DeviceState')
248+
240249
def on_sound_event(self, event_type, fn):
241250
"""Register callback for Sound related events
242251

ari/model.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,21 @@ def __init__(self, client, endpoint_json):
292292
client.on_endpoint_event)
293293

294294

295+
class DeviceState(BaseObject):
296+
"""First class object API.
297+
298+
:param client: ARI client.
299+
:type client: client.Client
300+
:param endpoint_json: Instance data
301+
"""
302+
id_generator = DefaultObjectIdGenerator('deviceName', id_field='name')
303+
304+
def __init__(self, client, device_state_json):
305+
super(DeviceState, self).__init__(
306+
client, client.swagger.devicestates, device_state_json,
307+
client.on_device_state_event)
308+
309+
295310
class Sound(BaseObject):
296311
"""First class object API.
297312
@@ -361,5 +376,6 @@ def promote(client, resp, operation_json):
361376
'Playback': Playback,
362377
'LiveRecording': LiveRecording,
363378
'StoredRecording': StoredRecording,
364-
'Mailbox': Mailbox
379+
'Mailbox': Mailbox,
380+
'DeviceState': DeviceState,
365381
}

ari_test/client_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ def test_mailboxes(self):
135135
self.assertEqual('1', mailbox['old_messages'])
136136
self.assertEqual('3', mailbox['new_messages'])
137137

138+
def test_device_state(self):
139+
self.serve(PUT, 'deviceStates', 'foobar',
140+
body='{"name": "foobar", "state": "BUSY"}')
141+
device_state = self.uut.deviceStates.update(
142+
deviceName='foobar',
143+
deviceState='BUSY')
144+
self.assertEqual('foobar', device_state['name'])
145+
self.assertEqual('BUSY', device_state['state'])
146+
138147
def setUp(self):
139148
super(ClientTest, self).setUp()
140149
self.uut = ari.connect('http://ari.py/', 'test', 'test')

sample-api/deviceStates.json

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
{
2+
"_copyright": "Copyright (C) 2012 - 2013, Digium, Inc.",
3+
"_author": "Kevin Harwell <kharwell@digium.com>",
4+
"_svn_revision": "$Revision: 407402 $",
5+
"apiVersion": "0.0.0-test",
6+
"swaggerVersion": "1.1",
7+
"basePath": "http://ari.py/ari",
8+
"resourcePath": "/api-docs/deviceStates.{format}",
9+
"apis": [
10+
{
11+
"path": "/deviceStates",
12+
"description": "Device states",
13+
"operations": [
14+
{
15+
"httpMethod": "GET",
16+
"summary": "List all ARI controlled device states.",
17+
"nickname": "list",
18+
"responseClass": "List[DeviceState]"
19+
}
20+
]
21+
},
22+
{
23+
"path": "/deviceStates/{deviceName}",
24+
"description": "Device state",
25+
"operations": [
26+
{
27+
"httpMethod": "GET",
28+
"summary": "Retrieve the current state of a device.",
29+
"nickname": "get",
30+
"responseClass": "DeviceState",
31+
"parameters": [
32+
{
33+
"name": "deviceName",
34+
"description": "Name of the device",
35+
"paramType": "path",
36+
"required": true,
37+
"allowMultiple": false,
38+
"dataType": "string"
39+
}
40+
]
41+
},
42+
{
43+
"httpMethod": "PUT",
44+
"summary": "Change the state of a device controlled by ARI. (Note - implicitly creates the device state).",
45+
"nickname": "update",
46+
"responseClass": "void",
47+
"parameters": [
48+
{
49+
"name": "deviceName",
50+
"description": "Name of the device",
51+
"paramType": "path",
52+
"required": true,
53+
"allowMultiple": false,
54+
"dataType": "string"
55+
},
56+
{
57+
"name": "deviceState",
58+
"description": "Device state value",
59+
"paramType": "query",
60+
"required": true,
61+
"allowMultiple": false,
62+
"dataType": "string",
63+
"allowableValues": {
64+
"valueType": "LIST",
65+
"values": [
66+
"NOT_INUSE",
67+
"INUSE",
68+
"BUSY",
69+
"INVALID",
70+
"UNAVAILABLE",
71+
"RINGING",
72+
"RINGINUSE",
73+
"ONHOLD"
74+
]
75+
}
76+
77+
}
78+
],
79+
"errorResponses": [
80+
{
81+
"code": 404,
82+
"reason": "Device name is missing"
83+
},
84+
{
85+
"code": 409,
86+
"reason": "Uncontrolled device specified"
87+
}
88+
]
89+
},
90+
{
91+
"httpMethod": "DELETE",
92+
"summary": "Destroy a device-state controlled by ARI.",
93+
"nickname": "delete",
94+
"responseClass": "void",
95+
"parameters": [
96+
{
97+
"name": "deviceName",
98+
"description": "Name of the device",
99+
"paramType": "path",
100+
"required": true,
101+
"allowMultiple": false,
102+
"dataType": "string"
103+
}
104+
],
105+
"errorResponses": [
106+
{
107+
"code": 404,
108+
"reason": "Device name is missing"
109+
},
110+
{
111+
"code": 409,
112+
"reason": "Uncontrolled device specified"
113+
}
114+
]
115+
}
116+
]
117+
}
118+
],
119+
"models": {
120+
"DeviceState": {
121+
"id": "DeviceState",
122+
"description": "Represents the state of a device.",
123+
"properties": {
124+
"name": {
125+
"type": "string",
126+
"description": "Name of the device.",
127+
"required": true
128+
},
129+
"state": {
130+
"type": "string",
131+
"description": "Device's state",
132+
"required": true,
133+
"allowableValues": {
134+
"valueType": "LIST",
135+
"values": [
136+
"UNKNOWN",
137+
"NOT_INUSE",
138+
"INUSE",
139+
"BUSY",
140+
"INVALID",
141+
"UNAVAILABLE",
142+
"RINGING",
143+
"RINGINUSE",
144+
"ONHOLD"
145+
]
146+
}
147+
}
148+
}
149+
}
150+
}
151+
}

sample-api/resources.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
"path": "/api-docs/playbacks.{format}",
3838
"description": "Playback control resources"
3939
},
40+
{
41+
"path": "/api-docs/deviceStates.{format}",
42+
"description": "Device state resources"
43+
},
4044
{
4145
"path": "/api-docs/events.{format}",
4246
"description": "WebSocket resource"

0 commit comments

Comments
 (0)