Skip to content

Commit eb76458

Browse files
committed
Use RST instead of Markdown for README
1 parent 158025c commit eb76458

5 files changed

Lines changed: 114 additions & 104 deletions

File tree

MANIFEST

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# file GENERATED by distutils, do NOT edit
2-
README.md
2+
README.rst
33
setup.py
44
gcm\__init__.py
55
gcm\gcm.py

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include README.md LICENSE
1+
include README.rst LICENSE

README.md

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

README.rst

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
python-gcm
2+
======================
3+
4+
.. image:: https://secure.travis-ci.org/geeknam/python-gcm.png?branch=master
5+
:alt: Build Status
6+
:target: http://travis-ci.org/geeknam/python-gcm
7+
8+
Python client for Google Cloud Messaging for Android (GCM)
9+
10+
Installation
11+
-------------
12+
13+
.. code-block:: bash
14+
15+
pip install python-gcm
16+
17+
Features
18+
------------
19+
20+
* Supports multicast message
21+
* Resend messages using exponential back-off
22+
* Proxy support
23+
* Easily handle errors
24+
25+
Usage
26+
------------
27+
28+
RTFM `here <http://developer.android.com/guide/google/gcm/gcm.html>`__
29+
30+
Basic
31+
32+
.. code-block:: python
33+
34+
from gcm import GCM
35+
36+
gcm = GCM(API_KEY)
37+
data = {'param1': 'value1', 'param2': 'value2'}
38+
39+
# Plaintext request
40+
reg_id = '12'
41+
gcm.plaintext_request(registration_id=reg_id, data=data)
42+
43+
# JSON request
44+
reg_ids = ['12', '34', '69']
45+
response = gcm.json_request(registration_ids=reg_ids, data=data)
46+
47+
# Extra arguments
48+
res = gcm.json_request(
49+
registration_ids=reg_ids, data=data,
50+
collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600
51+
)
52+
53+
Error handling
54+
55+
.. code-block:: python
56+
57+
# Plaintext request
58+
reg_id = '12345'
59+
try:
60+
canonical_id = gcm.plaintext_request(registration_id=reg_id, data=data)
61+
if canonical_id:
62+
# Repace reg_id with canonical_id in your database
63+
entry = entity.filter(registration_id=reg_id)
64+
entry.registration_id = canonical_id
65+
entry.save()
66+
except GCMNotRegisteredException:
67+
# Remove this reg_id from database
68+
entity.filter(registration_id=reg_id).delete()
69+
except GCMUnavailableException:
70+
# Resent the message
71+
72+
# JSON request
73+
reg_ids = ['12', '34', '69']
74+
response = gcm.json_request(registration_ids=reg_ids, data=data)
75+
76+
# Handling errors
77+
if 'errors' in response:
78+
for error, reg_ids in response['errors'].items():
79+
# Check for errors and act accordingly
80+
if error is 'NotRegistered':
81+
# Remove reg_ids from database
82+
for reg_id in reg_ids:
83+
entity.filter(registration_id=reg_id).delete()
84+
if 'canonical' in response:
85+
for reg_id, canonical_id in response['canonical'].items():
86+
# Repace reg_id with canonical_id in your database
87+
entry = entity.filter(registration_id=reg_id)
88+
entry.registration_id = canonical_id
89+
entry.save()
90+
91+
Exceptions
92+
------------
93+
Read more on response errors `here
94+
<http://developer.android.com/guide/google/gcm/gcm.html#success>`__
95+
96+
97+
* GCMMalformedJsonException
98+
* GCMConnectionException
99+
* GCMAuthenticationException
100+
* GCMTooManyRegIdsException
101+
* GCMNoCollapseKeyException
102+
* GCMInvalidTtlException
103+
* GCMMissingRegistrationException
104+
* GCMMismatchSenderIdException
105+
* GCMNotRegisteredException
106+
* GCMMessageTooBigException
107+
* GCMInvalidRegistrationException
108+
* GCMUnavailableException
109+
110+
.. image:: http://t.qkme.me/35gjhs.jpg
111+
:alt: Gotta catch them all

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
author_email='nam@namis.me',
1010
url='http://blog.namis.me/python-gcm/',
1111
description='Python client for Google Cloud Messaging for Android (GCM)',
12-
long_description=open('README.md').read(),
12+
long_description=open('README.rst').read(),
1313
keywords='android gcm push notification google cloud messaging',
1414
tests_require = ['mock'],
1515
)

0 commit comments

Comments
 (0)