Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
315f10b
Pusher ctr now requires app_id, key, secret
leggetter Mar 31, 2015
5a14077
app_id, key, secret optional on Config ctr
leggetter Mar 31, 2015
a0d359e
Move authenticate_subscription. Config -> Pusher
leggetter Mar 31, 2015
547c752
authenticate_subscription -> authenticate
leggetter Mar 31, 2015
5bd4ac5
Config.validate_webhook -> Pusher.validate_webhook
leggetter Mar 31, 2015
2a54734
pusher.conf refs to pusher.config
leggetter Mar 31, 2015
5480d62
Merge branch '1.0.0' into simple-parameters
leggetter Mar 31, 2015
c836f1b
Use functions on Pusher and not Config
leggetter Mar 31, 2015
ec16a0d
Adding additional configuration docs
leggetter Mar 31, 2015
9b3439f
Move signature code into it's own module
zimbatm Apr 1, 2015
773950f
Remove artificial restriction on sync+SSL
zimbatm Apr 1, 2015
4a07ced
Move request_method to pusher.request module
zimbatm Apr 1, 2015
9c56cce
Get rid of the Config object
zimbatm Apr 1, 2015
90ab769
Keep all the @request_method together
zimbatm Apr 1, 2015
7e3fa88
Move errors into their own modules
zimbatm Apr 1, 2015
b0e2645
Move all the http abstractions into a single pusher.http module
zimbatm Apr 1, 2015
329a75d
Restore two-step adapter initialisation
zimbatm Apr 1, 2015
4941054
Global config timeout
zimbatm Apr 1, 2015
474a44c
Tornado cleanup
zimbatm Apr 1, 2015
d2004fc
Add timeout to requests adapter
zimbatm Apr 1, 2015
8fa7f44
Add timeout and Keep-Alive to the aiohttp adapter
zimbatm Apr 1, 2015
7a5161e
'Fixed' tests
jpatel531 Apr 6, 2015
2ef4de4
Make all the properties read-only
zimbatm Apr 8, 2015
ec1a9f0
Make requests the default backend
zimbatm Apr 8, 2015
e5ea615
Add keep-alive support to requests backend
zimbatm Apr 8, 2015
2614a62
Allow to pass options to Pusher.from_env and Pusher.from_url
zimbatm Apr 8, 2015
8e72996
Editorconfig
zimbatm Apr 8, 2015
3ee8aa9
Rework text handling
zimbatm Apr 8, 2015
259699c
Fix packages list in setup.py
zimbatm Apr 8, 2015
06b5d05
Remove Sync backend. Requests backend is enough
zimbatm Apr 8, 2015
6ce72d6
Fix tornado and asyncio backends
zimbatm Apr 8, 2015
2c9570d
Add trigger examples
zimbatm Apr 8, 2015
f6d0605
https
zimbatm Apr 8, 2015
b0970ab
Started adding tests for http adapters.
jpatel531 Apr 23, 2015
0b878fe
Fixes loading and testing issues in python 2.6
zimbatm Apr 24, 2015
a6e8e0e
Renamed package to pusher and updated version number
jpatel531 Apr 24, 2015
ba98601
Added urlfetch adapter
jpatel531 Apr 24, 2015
b0b40a5
Added tests for urlfetch adapter
jpatel531 Apr 24, 2015
ab6e93e
Amended .travis.yml to account for extras
jpatel531 Apr 24, 2015
3a92622
Renamed urlfetch adapter test and made it import unittest2 if v2.6
jpatel531 Apr 24, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

[*.py]
indent_style = space
indent_size = 4
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ python:
- "2.7"
# - "3.2"
- "3.3"
install: "python setup.py develop"
install:
- "python setup.py develop"
- "pip install aiohttp"
- "pip install tornado"
- "pip install urlfetch"
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2; fi
script: "python setup.py test"
48 changes: 35 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ constructor arguments which identify your Pusher app. You can find them by
going to "API Keys" on your app at https://app.pusher.com.

```python
from pusher import Config, Pusher
pusher = Pusher(config=Config(app_id=u'4', key=u'key', secret=u'secret'))
from pusher import Pusher
pusher = Pusher(app_id=u'4', key=u'key', secret=u'secret')
```

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

## Configuration

```python
from pusher import Pusher
pusher = Pusher(app_id, key, secret, config=None, backend=None)
```

|Argument |Description |
|:-:|:-:|
|app_id `String` |**Required** <br> The Pusher application ID |
|key `String` |**Required** <br> The Pusher application key |
|secret `String` |**Required** <br> The Pusher application secret token |
|host `String` | **Default:`None`** <br> The host to connect to |
|port `int` | **Default:`None`** <br>Which port to connect to |
|ssl `bool` | **Default:`False`** <br> Use HTTPS |
|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 |
|backend `Object` | an object that responds to the send_request(request) method. If none is provided, a `python.sync.SynchronousBackend` instance is created. |

##### Example

```py
from pusher import Pusher, Config
pusher = Pusher(app_id=u'4', key=u'key', secret=u'secret', Config(ssl=True, cluster=u'eu'))
```

Triggering Events
-----------------

Expand Down Expand Up @@ -159,13 +184,13 @@ pusher.users_info(u'presence-chatroom')
Authenticating Channel Subscription
-----------------

#### `Config::authenticate_subscription`
#### `Pusher::authenticate`

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

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.

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.
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.

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

```python
config = pusher.config
auth = config.authenticate_subscription(
auth = pusher.authenticate_subscription(

channel=u"private-channel",

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

```python
config = pusher.config

auth = config.authenticate_subscription(
auth = pusher.authenticate_subscription(

channel=u"presence-channel",

Expand All @@ -216,9 +238,9 @@ auth = config.authenticate_subscription(
Receiving Webhooks
-----------------

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.
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.

#### `Config::validate_webhook`
#### `Pusher::validate_webhook`

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

```python
webhook = pusher.config.validate_webhook(
webhook = pusher.validate_webhook(

key="key_sent_in_header",

Expand All @@ -253,4 +275,4 @@ To run the tests run `python setup.py test`
License
-------

Copyright (c) 2014 Pusher Ltd. See LICENSE for details.
Copyright (c) 2015 Pusher Ltd. See LICENSE for details.
2 changes: 0 additions & 2 deletions pusher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-

from .config import Config
from .pusher import Pusher

__all__ = [
'Config',
'Pusher',
]
26 changes: 14 additions & 12 deletions pusher/aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# -*- coding: utf-8 -*-

import aiohttp
import pusher
import asyncio

class AsyncIOBackend:
"""Adapter for the aiohttp module.

This backend is only availble for python 3 users and doesn't support SSL.
from pusher.http import process_response

:param config: pusher.Config instance
"""
class AsyncIOBackend:
def __init__(self, config):
"""Adapter for the requests module.

:param config: pusher.Pusher object
"""
self.config = config
if config.ssl:
raise NotImplementedError("SSL not supported for this backend")
self.conn = aiohttp.TCPConnector()

def send_request(self, request):
method = request.method
url = "http://%s:%s%s" % (self.config.host, self.config.port, request.path)
url = "%s%s" % (request.base_url, request.path)
params = request.query_params
data = request.body
headers = request.headers

response = yield from aiohttp.request(method, url, params=params, data=data, headers=headers)
response = yield from asyncio.wait_for(
aiohttp.request(method, url, params=params, data=data, headers=headers, connector=self.conn),
timeout=self.config.timeout
)
body = yield from response.read_and_close()
return pusher.process_response(response.status, body.decode('utf8'))
return process_response(response.status, body.decode('utf8'))
193 changes: 0 additions & 193 deletions pusher/config.py

This file was deleted.

16 changes: 16 additions & 0 deletions pusher/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-

class PusherError(Exception):
pass

class PusherBadRequest(PusherError):
pass

class PusherBadAuth(PusherError):
pass

class PusherForbidden(PusherError):
pass

class PusherBadStatus(PusherError):
pass
Loading