Skip to content

Commit

Permalink
Merge pull request asterisk#2 from asterisk/mwi
Browse files Browse the repository at this point in the history
Add Mailboxes resource
  • Loading branch information
leedm777 committed Mar 4, 2014
2 parents 2b534a7 + 22bd6bb commit 6a6c842
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ari/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ def fn_filter(objects, event):
if self.id == objects.id:
fn(objects, event)

if not self.event_reg:
msg = "Event callback registration called on object with no events"
raise RuntimeError(msg)

return self.event_reg(event_type, fn_filter)


Expand Down Expand Up @@ -303,6 +307,21 @@ def __init__(self, client, sound_json):
client, client.swagger.sounds, sound_json, client.on_sound_event)


class Mailbox(BaseObject):
"""First class object API.
:param client: ARI client.
:type client: client.Client
:param mailbox_json: Instance data
"""

id_generator = DefaultObjectIdGenerator('mailboxName', id_field='name')

def __init__(self, client, mailbox_json):
super(Mailbox, self).__init__(
client, client.swagger.mailboxes, mailbox_json, None)


def promote(client, resp, operation_json):
"""Promote a response from the request's HTTP response to a first class
object.
Expand Down Expand Up @@ -341,5 +360,6 @@ def promote(client, resp, operation_json):
'Endpoint': Endpoint,
'Playback': Playback,
'LiveRecording': LiveRecording,
'StoredRecording': StoredRecording
'StoredRecording': StoredRecording,
'Mailbox': Mailbox
}
12 changes: 12 additions & 0 deletions ari_test/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ def test_stored_recording(self):
recordingName='test-recording')
recording.deleteStored()

def test_mailboxes(self):
self.serve(PUT, 'mailboxes', '1000',
body='{"name": "1000", "old_messages": "1", "new_messages": "3"}')

mailbox = self.uut.mailboxes.update(
mailboxName='1000',
oldMessages='1',
newMessages='3')
self.assertEqual('1000', mailbox['name'])
self.assertEqual('1', mailbox['old_messages'])
self.assertEqual('3', mailbox['new_messages'])

def setUp(self):
super(ClientTest, self).setUp()
self.uut = ari.connect('http://ari.py/', 'test', 'test')
Expand Down
133 changes: 133 additions & 0 deletions sample-api/mailboxes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"_copyright": "Copyright (C) 2013, Digium, Inc.",
"_author": "Jonathan Rose <[email protected]>",
"apiVersion": "0.0.0-test",
"swaggerVersion": "1.1",
"basePath": "http://ari.py/ari",
"resourcePath": "/api-docs/mailboxes.{format}",
"apis": [
{
"path": "/mailboxes",
"description": "Mailboxes",
"operations": [
{
"httpMethod": "GET",
"summary": "List all mailboxes.",
"nickname": "list",
"responseClass": "List[Mailbox]"
}
]
},
{
"path": "/mailboxes/{mailboxName}",
"description": "Mailbox state",
"operations": [
{
"httpMethod": "GET",
"summary": "Retrieve the current state of a mailbox.",
"nickname": "get",
"responseClass": "Mailbox",
"parameters": [
{
"name": "mailboxName",
"description": "Name of the mailbox",
"paramType": "path",
"required": true,
"allowMultiple": false,
"dataType": "string"
}
],
"errorResponses": [
{
"code": 404,
"reason": "Mailbox not found"
}
]
},
{
"httpMethod": "PUT",
"summary": "Change the state of a mailbox. (Note - implicitly creates the mailbox).",
"nickname": "update",
"responseClass": "void",
"parameters": [
{
"name": "mailboxName",
"description": "Name of the mailbox",
"paramType": "path",
"required": true,
"allowMultiple": false,
"dataType": "string"
},
{
"name": "oldMessages",
"description": "Count of old messages in the mailbox",
"paramType": "query",
"required": true,
"allowMultiple": false,
"dataType": "int"
},
{
"name": "newMessages",
"description": "Count of new messages in the mailbox",
"paramType": "query",
"required": true,
"allowMultiple": false,
"dataType": "int"
}
],
"errorResponses": [
{
"code": 404,
"reason": "Mailbox not found"
}
]
},
{
"httpMethod": "DELETE",
"summary": "Destroy a mailbox.",
"nickname": "delete",
"responseClass": "void",
"parameters": [
{
"name": "mailboxName",
"description": "Name of the mailbox",
"paramType": "path",
"required": true,
"allowMultiple": false,
"dataType": "string"
}
],
"errorResponses": [
{
"code": 404,
"reason": "Mailbox not found"
}
]
}
]
}
],
"models": {
"Mailbox": {
"id": "Mailbox",
"description": "Represents the state of a mailbox.",
"properties": {
"name": {
"type": "string",
"description": "Name of the mailbox.",
"required": true
},
"old_messages": {
"type": "int",
"description": "Count of old messages in the mailbox.",
"required": true
},
"new_messages": {
"type": "int",
"description": "Count of new messages in the mailbox.",
"required": true
}
}
}
}
}
4 changes: 4 additions & 0 deletions sample-api/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"path": "/api-docs/sounds.{format}",
"description": "Sound resources"
},
{
"path": "/api-docs/mailboxes.{format}",
"description": "Mailbox (MWI) resources"
},
{
"path": "/api-docs/playbacks.{format}",
"description": "Playback control resources"
Expand Down

0 comments on commit 6a6c842

Please sign in to comment.