| 1 |
# Copyright (C) 2016 Catalyst IT Ltd |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 |
# not use this file except in compliance with the License. You may obtain |
| 5 |
# a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 |
# License for the specific language governing permissions and limitations |
| 13 |
# under the License. |
| 14 |
|
| 15 |
from urllib import parse |
| 16 |
|
| 17 |
from adjutantclient.common import base |
| 18 |
|
| 19 |
|
| 20 |
class Notification(base.Resource): |
| 21 |
pass |
| 22 |
|
| 23 |
|
| 24 |
class NotificationManager(base.ManagerWithFind): |
| 25 |
resource_class = Notification |
| 26 |
|
| 27 |
def get(self, note_id): |
| 28 |
return self._get("/notifications/%s" % base.getid(note_id)) |
| 29 |
|
| 30 |
def list(self, **kwargs): |
| 31 |
"""Get a list of notifications. |
| 32 |
|
| 33 |
:rtype: list of :class:`Notification` |
| 34 |
""" |
| 35 |
url = '/notifications?%(params)s' % { |
| 36 |
'params': parse.urlencode(kwargs, True) |
| 37 |
} |
| 38 |
return self._list(url, 'notifications') |
| 39 |
|
| 40 |
def acknowledge(self, note_id=None, note_list=[]): |
| 41 |
"""Acknowledge a single notification or many.""" |
| 42 |
if note_id: |
| 43 |
data = {'acknowledged': True} |
| 44 |
url = 'notifications/%s' % note_id |
| 45 |
return self._post(url, data) |
| 46 |
elif note_list: |
| 47 |
data = {'notifications': note_list} |
| 48 |
return self._post('notifications', data) |