Skip to content

Commit 36555b6

Browse files
authored
Merge pull request #36 from web-push-libs/feat/35
Convert README from markdown to restructured text
2 parents 65954b1 + 8ff7c68 commit 36555b6

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

README.rst

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
|Build\_Status| [|Requirements Status|]
2+
3+
Webpush Data encryption library for Python
4+
==========================================
5+
6+
This is a work in progress. This library is available on `pypi as
7+
pywebpush <https://pypi.python.org/pypi/pywebpush>`__. Source is
8+
available on `github <https://github.com/jrconlin/pywebpush>`__
9+
10+
Installation
11+
------------
12+
13+
You'll need to run ``python virtualenv``. Then
14+
15+
::
16+
17+
bin/pip install -r requirements.txt
18+
bin/python setup.py develop
19+
20+
Usage
21+
-----
22+
23+
In the browser, the promise handler for
24+
`registration.pushManager.subscribe() <https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe>`__
25+
returns a
26+
`PushSubscription <https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription>`__
27+
object. This object has a .toJSON() method that will return a JSON
28+
object that contains all the info we need to encrypt and push data.
29+
30+
As illustration, a subscription info object may look like:
31+
32+
::
33+
34+
{"endpoint": "https://updates.push.services.mozilla.com/push/v1/gAA...", "keys": {"auth": "k8J...", "p256dh": "BOr..."}}
35+
36+
How you send the PushSubscription data to your backend, store it
37+
referenced to the user who requested it, and recall it when there's new
38+
a new push subscription update is left as an excerise for the reader.
39+
40+
The data can be any serial content (string, bit array, serialized JSON,
41+
etc), but be sure that your receiving application is able to parse and
42+
understand it. (e.g. ``data = "Mary had a little lamb."``)
43+
44+
gcm\_key is the API key obtained from the Google Developer Console. It
45+
is only needed if endpoint is https://android.googleapis.com/gcm/send
46+
47+
``headers`` is a ``dict``\ ionary of additional HTTP header values (e.g.
48+
`VAPID <https://github.com/mozilla-services/vapid/tree/master/python>`__
49+
self identification headers). It is optional and may be omitted.
50+
51+
to send:
52+
53+
::
54+
55+
WebPusher(subscription_info).send(data, headers)
56+
57+
to send for Chrome:
58+
59+
::
60+
61+
WebPusher(subscription_info).send(data, headers, ttl, gcm_key)
62+
63+
You can also simply encode the data to send later by calling
64+
65+
::
66+
67+
encoded = WebPush(subscription_info).encode(data)
68+
69+
.. |Build\_Status| image:: https://travis-ci.org/jrconlin/pywebpush.svg?branch=master
70+
:target: https://travis-ci.org/jrconlin/pywebpush
71+
.. |Requirements Status| image:: https://requires.io/github/web-push-libs/pywebpush/requirements.svg?branch=master
72+

convert_readme.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pandoc --from=markdown --to=rst --output README.rst README.md

pywebpush/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ def send(self, data, headers=None, ttl=0, gcm_key=None, reg_id=None):
198198
data['registration_ids'] = reg_ids
199199
data['raw_data'] = base64.b64encode(
200200
encoded.get('body')).decode('utf8')
201-
data['time_to_live'] = int(headers['ttl'] if 'ttl' in headers else ttl)
201+
data['time_to_live'] = int(
202+
headers['ttl'] if 'ttl' in headers else ttl)
202203
encoded_data = json.dumps(data)
203204
headers.update({
204205
'Authorization': 'key='+gcm_key,

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from setuptools import find_packages, setup
55

6-
__version__ = "0.6.1"
6+
__version__ = "0.6.2"
77

88

99
def read_from(file):
@@ -19,7 +19,7 @@ def read_from(file):
1919

2020

2121
here = os.path.abspath(os.path.dirname(__file__))
22-
with io.open(os.path.join(here, 'README.md'), encoding='utf8') as f:
22+
with io.open(os.path.join(here, 'README.rst'), encoding='utf8') as f:
2323
README = f.read()
2424
with io.open(os.path.join(here, 'CHANGELOG.md'), encoding='utf8') as f:
2525
CHANGES = f.read()

0 commit comments

Comments
 (0)