Skip to content

Commit a49b73d

Browse files
committed
Merge pull request #45 from pusher/run-with-it
Run with it
2 parents ab3cc90 + 3a92622 commit a49b73d

25 files changed

+716
-532
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
[*.py]
12+
indent_style = space
13+
indent_size = 4

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@ python:
55
- "2.7"
66
# - "3.2"
77
- "3.3"
8-
install: "python setup.py develop"
8+
install:
9+
- "python setup.py develop"
10+
- "pip install aiohttp"
11+
- "pip install tornado"
12+
- "pip install urlfetch"
13+
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2; fi
914
script: "python setup.py test"

README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ constructor arguments which identify your Pusher app. You can find them by
3939
going to "API Keys" on your app at https://app.pusher.com.
4040

4141
```python
42-
from pusher import Config, Pusher
43-
pusher = Pusher(config=Config(app_id=u'4', key=u'key', secret=u'secret'))
42+
from pusher import Pusher
43+
pusher = Pusher(app_id=u'4', key=u'key', secret=u'secret')
4444
```
4545

4646
You can then trigger events to channels. Channel and event names may only
@@ -50,6 +50,31 @@ contain alphanumeric characters, `-` and `_`:
5050
pusher.trigger(u'a_channel', u'an_event', {u'some': u'data'})
5151
```
5252

53+
## Configuration
54+
55+
```python
56+
from pusher import Pusher
57+
pusher = Pusher(app_id, key, secret, config=None, backend=None)
58+
```
59+
60+
|Argument |Description |
61+
|:-:|:-:|
62+
|app_id `String` |**Required** <br> The Pusher application ID |
63+
|key `String` |**Required** <br> The Pusher application key |
64+
|secret `String` |**Required** <br> The Pusher application secret token |
65+
|host `String` | **Default:`None`** <br> The host to connect to |
66+
|port `int` | **Default:`None`** <br>Which port to connect to |
67+
|ssl `bool` | **Default:`False`** <br> Use HTTPS |
68+
|cluster `String` | **Default:`None`** <br> Convention for other clusters than the main Pusher-one. Eg: 'eu' will resolve to the api-eu.pusherapp.com host |
69+
|backend `Object` | an object that responds to the send_request(request) method. If none is provided, a `python.sync.SynchronousBackend` instance is created. |
70+
71+
##### Example
72+
73+
```py
74+
from pusher import Pusher, Config
75+
pusher = Pusher(app_id=u'4', key=u'key', secret=u'secret', Config(ssl=True, cluster=u'eu'))
76+
```
77+
5378
Triggering Events
5479
-----------------
5580

@@ -159,13 +184,13 @@ pusher.users_info(u'presence-chatroom')
159184
Authenticating Channel Subscription
160185
-----------------
161186

162-
#### `Config::authenticate_subscription`
187+
#### `Pusher::authenticate`
163188

164189
In order for users to subscribe to a private- or presence-channel, they must be authenticated by your server.
165190

166191
The client will make a POST request to an endpoint (either "/pusher/auth" or any which you specify) with a body consisting of the channel's name and socket_id.
167192

168-
Using your `Config` instance, with which you initialized `Pusher`, you can generate an authentication signature. Having responded to the request with this signature, the subscription will be authenticated.
193+
Using your `Pusher` instance, with which you initialized `Pusher`, you can generate an authentication signature. Having responded to the request with this signature, the subscription will be authenticated.
169194

170195
|Argument |Description |
171196
|:-:|:-:|
@@ -182,8 +207,7 @@ Using your `Config` instance, with which you initialized `Pusher`, you can gener
182207
###### Private Channels
183208

184209
```python
185-
config = pusher.config
186-
auth = config.authenticate_subscription(
210+
auth = pusher.authenticate_subscription(
187211

188212
channel=u"private-channel",
189213

@@ -195,9 +219,7 @@ auth = config.authenticate_subscription(
195219
###### Presence Channels
196220

197221
```python
198-
config = pusher.config
199-
200-
auth = config.authenticate_subscription(
222+
auth = pusher.authenticate_subscription(
201223

202224
channel=u"presence-channel",
203225

@@ -216,9 +238,9 @@ auth = config.authenticate_subscription(
216238
Receiving Webhooks
217239
-----------------
218240

219-
If you have webhooks set up to POST a payload to a specified endpoint, you may wish to validate that these are actually from Pusher. The `Config` object achieves this by checking the authentication signature in the request body using your application credentials.
241+
If you have webhooks set up to POST a payload to a specified endpoint, you may wish to validate that these are actually from Pusher. The `Pusher` object achieves this by checking the authentication signature in the request body using your application credentials.
220242

221-
#### `Config::validate_webhook`
243+
#### `Pusher::validate_webhook`
222244

223245
|Argument |Description |
224246
|:-:|:-:|
@@ -233,7 +255,7 @@ If you have webhooks set up to POST a payload to a specified endpoint, you may w
233255
##### Example
234256

235257
```python
236-
webhook = pusher.config.validate_webhook(
258+
webhook = pusher.validate_webhook(
237259

238260
key="key_sent_in_header",
239261

@@ -253,4 +275,4 @@ To run the tests run `python setup.py test`
253275
License
254276
-------
255277

256-
Copyright (c) 2014 Pusher Ltd. See LICENSE for details.
278+
Copyright (c) 2015 Pusher Ltd. See LICENSE for details.

pusher/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3-
from .config import Config
43
from .pusher import Pusher
54

65
__all__ = [
7-
'Config',
86
'Pusher',
97
]

pusher/aiohttp.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
# -*- coding: utf-8 -*-
22

33
import aiohttp
4-
import pusher
4+
import asyncio
55

6-
class AsyncIOBackend:
7-
"""Adapter for the aiohttp module.
8-
9-
This backend is only availble for python 3 users and doesn't support SSL.
6+
from pusher.http import process_response
107

11-
:param config: pusher.Config instance
12-
"""
8+
class AsyncIOBackend:
139
def __init__(self, config):
10+
"""Adapter for the requests module.
11+
12+
:param config: pusher.Pusher object
13+
"""
1414
self.config = config
15-
if config.ssl:
16-
raise NotImplementedError("SSL not supported for this backend")
15+
self.conn = aiohttp.TCPConnector()
1716

1817
def send_request(self, request):
1918
method = request.method
20-
url = "http://%s:%s%s" % (self.config.host, self.config.port, request.path)
19+
url = "%s%s" % (request.base_url, request.path)
2120
params = request.query_params
2221
data = request.body
2322
headers = request.headers
2423

25-
response = yield from aiohttp.request(method, url, params=params, data=data, headers=headers)
24+
response = yield from asyncio.wait_for(
25+
aiohttp.request(method, url, params=params, data=data, headers=headers, connector=self.conn),
26+
timeout=self.config.timeout
27+
)
2628
body = yield from response.read_and_close()
27-
return pusher.process_response(response.status, body.decode('utf8'))
29+
return process_response(response.status, body.decode('utf8'))

pusher/config.py

Lines changed: 0 additions & 193 deletions
This file was deleted.

pusher/errors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class PusherError(Exception):
4+
pass
5+
6+
class PusherBadRequest(PusherError):
7+
pass
8+
9+
class PusherBadAuth(PusherError):
10+
pass
11+
12+
class PusherForbidden(PusherError):
13+
pass
14+
15+
class PusherBadStatus(PusherError):
16+
pass

0 commit comments

Comments
 (0)