|
1 | | -from .config import Config |
| 1 | +from .client import Client |
2 | 2 | from .http import POST, Request, request_method |
3 | 3 | from .util import ensure_text |
4 | 4 |
|
|
9 | 9 | GCM_TTL = 241920 |
10 | 10 | WEBHOOK_LEVELS = ['INFO', 'DEBUG', ''] |
11 | 11 |
|
12 | | -class NotificationClient(Config): |
13 | | - |
14 | | - def __init__(self, app_id, key, secret, ssl=True, host=None, port=None, timeout=5, cluster=None, |
15 | | - json_encoder=None, json_decoder=None, backend=None, **backend_options): |
16 | | - |
17 | | - super(NotificationClient, self).__init__( |
18 | | - app_id, key, secret, ssl, |
19 | | - host, port, timeout, cluster, |
20 | | - json_encoder, json_decoder, backend, |
21 | | - **backend_options) |
22 | | - |
23 | | - if host: |
24 | | - self._host = ensure_text(host, "host") |
25 | | - else: |
26 | | - self._host = DEFAULT_HOST |
27 | | - |
28 | | - |
29 | | - @request_method |
30 | | - def notify(self, interests, notification): |
31 | | - if not isinstance(interests, list) and not isinstance(interests, set): |
32 | | - raise TypeError("Interests must be a list or a set") |
33 | | - |
34 | | - if len(interests) is 0: |
35 | | - raise ValueError("Interests must not be empty") |
36 | | - |
37 | | - if not isinstance(notification, dict): |
38 | | - raise TypeError("Notification must be a dictionary") |
39 | | - |
40 | | - params = { |
41 | | - 'interests': interests, |
42 | | - } |
43 | | - params.update(notification) |
44 | | - path = "/%s/%s/apps/%s/notifications" % (API_PREFIX, API_VERSION, self.app_id) |
45 | | - return Request(self, POST, path, params) |
| 12 | +class NotificationClient(Client): |
| 13 | + def __init__(self, app_id, key, secret, ssl=True, host=None, port=None, timeout=5, cluster=None, |
| 14 | + json_encoder=None, json_decoder=None, backend=None, **backend_options): |
| 15 | + super(NotificationClient, self).__init__( |
| 16 | + app_id, key, secret, ssl, |
| 17 | + host, port, timeout, cluster, |
| 18 | + json_encoder, json_decoder, backend, |
| 19 | + **backend_options) |
| 20 | + |
| 21 | + if host: |
| 22 | + self._host = ensure_text(host, "host") |
| 23 | + else: |
| 24 | + self._host = DEFAULT_HOST |
| 25 | + |
| 26 | + |
| 27 | + @request_method |
| 28 | + def notify(self, interests, notification): |
| 29 | + if not isinstance(interests, list) and not isinstance(interests, set): |
| 30 | + raise TypeError("Interests must be a list or a set") |
| 31 | + |
| 32 | + if len(interests) is 0: |
| 33 | + raise ValueError("Interests must not be empty") |
| 34 | + |
| 35 | + if not isinstance(notification, dict): |
| 36 | + raise TypeError("Notification must be a dictionary") |
| 37 | + |
| 38 | + params = { |
| 39 | + 'interests': interests, |
| 40 | + } |
| 41 | + params.update(notification) |
| 42 | + path = "/%s/%s/apps/%s/notifications" % (API_PREFIX, API_VERSION, self.app_id) |
| 43 | + return Request(self, POST, path, params) |
0 commit comments