4
4
division )
5
5
from pusher .http import GET , POST , Request , request_method
6
6
from pusher .signature import sign , verify
7
- from pusher .util import ensure_text , validate_channel , validate_socket_id , app_id_re , pusher_url_re , channel_name_re
7
+ from pusher .util import ensure_text , validate_channel , validate_socket_id , pusher_url_re , channel_name_re
8
+ from pusher .config import Config
9
+ from pusher .notification_client import NotificationClient
8
10
9
11
import collections
10
12
import hashlib
13
15
import re
14
16
import six
15
17
import time
18
+ import copy
16
19
17
20
def join_attributes (attributes ):
18
21
return six .text_type (',' ).join (attributes )
19
22
20
- class Pusher (object ):
23
+ class Pusher (Config ):
21
24
"""Client for the Pusher HTTP API.
22
25
23
26
This client supports various backend adapters to support various http
@@ -36,41 +39,25 @@ class Pusher(object):
36
39
:param backend_options: additional backend
37
40
"""
38
41
def __init__ (self , app_id , key , secret , ssl = True , host = None , port = None , timeout = 5 , cluster = None ,
39
- json_encoder = None , json_decoder = None , backend = None , ** backend_options ):
40
-
41
- if backend is None :
42
- from pusher .requests import RequestsBackend
43
- backend = RequestsBackend
44
-
45
- self ._app_id = ensure_text (app_id , "app_id" )
46
- if not app_id_re .match (self ._app_id ):
47
- raise ValueError ("Invalid app id" )
48
-
49
- self ._key = ensure_text (key , "key" )
50
- self ._secret = ensure_text (secret , "secret" )
51
-
52
- if not isinstance (ssl , bool ):
53
- raise TypeError ("SSL should be a boolean" )
54
- self ._ssl = ssl
55
-
42
+ json_encoder = None , json_decoder = None , backend = None , notification_host = None ,
43
+ notification_ssl = True , ** backend_options ):
44
+ super (Pusher , self ).__init__ (
45
+ app_id , key , secret , ssl ,
46
+ host , port , timeout , cluster ,
47
+ json_encoder , json_decoder , backend ,
48
+ ** backend_options )
56
49
if host :
57
50
self ._host = ensure_text (host , "host" )
58
51
elif cluster :
59
52
self ._host = six .text_type ("api-%s.pusher.com" ) % ensure_text (cluster , "cluster" )
60
53
else :
61
54
self ._host = six .text_type ("api.pusherapp.com" )
62
55
63
- if port and not isinstance (port , six .integer_types ):
64
- raise TypeError ("port should be an integer" )
65
- self ._port = port or (443 if ssl else 80 )
66
-
67
- if not isinstance (timeout , six .integer_types ):
68
- raise TypeError ("timeout should be an integer" )
69
- self ._timeout = timeout
70
- self ._json_encoder = json_encoder
71
- self ._json_decoder = json_decoder
72
-
73
- self .http = backend (self , ** backend_options )
56
+ self ._notification_client = NotificationClient (
57
+ app_id , key , secret , notification_ssl ,
58
+ notification_host , port , timeout , cluster ,
59
+ json_encoder , json_decoder , backend ,
60
+ ** backend_options )
74
61
75
62
@classmethod
76
63
def from_url (cls , url , ** options ):
@@ -116,7 +103,7 @@ def from_env(cls, env='PUSHER_URL', **options):
116
103
val = os .environ .get (env )
117
104
if not val :
118
105
raise Exception ("Environment variable %s not found" % env )
119
-
106
+
120
107
return cls .from_url (val , ** options )
121
108
122
109
@request_method
@@ -126,7 +113,7 @@ def trigger(self, channels, event_name, data, socket_id=None):
126
113
127
114
http://pusher.com/docs/rest_api#method-post-event
128
115
'''
129
-
116
+
130
117
if isinstance (channels , six .string_types ):
131
118
channels = [channels ]
132
119
@@ -280,36 +267,11 @@ def validate_webhook(self, key, signature, body):
280
267
return body_data
281
268
282
269
@property
283
- def app_id (self ):
284
- return self ._app_id
285
-
286
- @property
287
- def key (self ):
288
- return self ._key
289
-
290
- @property
291
- def secret (self ):
292
- return self ._secret
293
-
294
- @property
295
- def host (self ):
296
- return self ._host
297
-
298
- @property
299
- def port (self ):
300
- return self ._port
301
-
302
- @property
303
- def timeout (self ):
304
- return self ._timeout
270
+ def notification_client (self ):
271
+ return self ._notification_client
305
272
306
- @property
307
- def ssl (self ):
308
- return self ._ssl
309
-
310
- @property
311
- def scheme (self ):
312
- return 'https' if self .ssl else 'http'
273
+ def notify (self , interests , notification ):
274
+ self ._notification_client .notify (interests , notification )
313
275
314
276
def _data_to_string (self , data ):
315
277
if isinstance (data , six .string_types ):
0 commit comments