Add subscriptions API piece.
Change-Id: I9cc8707bbadb8def65b250a5336230d0f32a7630
This commit is contained in:
parent
7bab5b535a
commit
276af83a3d
@ -89,3 +89,42 @@ class Queues(generic.View):
|
||||
'total': 0,
|
||||
'metadata': new_queue._metadata}
|
||||
return rest_utils.CreatedResponse(location, response)
|
||||
|
||||
|
||||
@urls.register
|
||||
class Subscriptions(generic.View):
|
||||
"""API for queues"""
|
||||
url_regex = r'zaqar/queues/(?P<queue_name>[^/]+)/subscriptions/$'
|
||||
|
||||
@rest_utils.ajax()
|
||||
def get(self, request, queue_name):
|
||||
"""Get a list of the Subscriptions for a queue."""
|
||||
return zaqar.subscription_list(request, queue_name)
|
||||
|
||||
@rest_utils.ajax(data_required=True)
|
||||
def delete(self, request, queue_name):
|
||||
"""Delete one or more queue by name.
|
||||
|
||||
Returns HTTP 204 (no content) on successful deletion.
|
||||
"""
|
||||
zaqar.subscription_delete(request, queue_name, request.DATA)
|
||||
|
||||
@rest_utils.ajax(data_required=True)
|
||||
def put(self, request, queue_name):
|
||||
"""Create a new subscription.
|
||||
|
||||
Returns the new queue object on success.
|
||||
"""
|
||||
return zaqar.subscription_create(request, queue_name, request.DATA)
|
||||
|
||||
|
||||
@urls.register
|
||||
class Subscription(generic.View):
|
||||
"""API for retrieving a single subscription"""
|
||||
url_regex = r'zaqar/queues/(?P<queue_name>[^/]+)/' \
|
||||
r'subscription/(?P<subscriber>[^/]+)/$'
|
||||
|
||||
@rest_utils.ajax(data_required=True)
|
||||
def post(self, request, queue_name, subscriber):
|
||||
zaqar.subscription_update(request, queue_name,
|
||||
{'id': subscriber}, request.DATA)
|
||||
|
@ -83,8 +83,28 @@ def queue_get(request, queue_name):
|
||||
return zaqarclient(request).queue(queue_name, auto_create=False)
|
||||
|
||||
|
||||
def queue_subscribe(request, subscriber, ttl=None, options={}):
|
||||
# Popup a modal form, user can input subscriber, ttl and options to
|
||||
# subscribe the queue.
|
||||
# subscriber could be an URL or email address.
|
||||
pass
|
||||
def subscription_list(request, queue_name):
|
||||
return [{'subscriber': s.subscriber,
|
||||
'id': s.id,
|
||||
'ttl': s.ttl,
|
||||
'options': s.options}
|
||||
for s in zaqarclient(request).subscriptions(queue_name)]
|
||||
|
||||
|
||||
def subscription_create(request, queue_name, sub_data):
|
||||
subscription = zaqarclient(request).subscription(queue_name, **sub_data)
|
||||
return {'subscriber': subscription.subscriber,
|
||||
'id': subscription.id,
|
||||
'ttl': subscription.ttl,
|
||||
'options': subscription.options}
|
||||
|
||||
|
||||
def subscription_delete(request, queue_name, sub_data):
|
||||
subscription = zaqarclient(request).subscription(queue_name, **sub_data)
|
||||
subscription.delete()
|
||||
|
||||
|
||||
def subscription_update(request, queue_name, old_data, new_data):
|
||||
subscription = zaqarclient(request).subscription(queue_name, **old_data)
|
||||
subscription.update(new_data)
|
||||
return subscription
|
||||
|
Loading…
Reference in New Issue
Block a user