You are on page 1of 17

django-gcm-android-ios

Documentation
Release 1.0.0

Hugo Brilhante

February 24, 2017


Contents

1 Tutorial 3
1.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Sending messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Author 5

3 Main features 7

4 Links 9

5 References 11

6 License 13

i
ii
django-gcm-android-ios Documentation, Release 1.0.0

django-gcm-android-ios is a simple Django app to send a message using Google Cloud Messaging HTTP connection
server protocol. Contents:

Contents 1
django-gcm-android-ios Documentation, Release 1.0.0

2 Contents
CHAPTER 1

Tutorial

Installation

Install o django-gcm-android-ios:
pip install django-gcm-android-ios

Configuration

Configure django-gcm-android-ios in your settings.py file:


INSTALLED_APPS = (
...
'gcm',
)

GCM_DEVICE_MODEL = "<model.device>" # default gcm.Device


GCM_IOS_APIKEY = "<IOS_APIKEY>"
GCM_ANDROID_APIKEY = "<ANDROID_APIKEY>"

Add django-gcm-android-ios resources to your URL router:


from gcm.routers import router
urlpatterns = [
...
url(r'api/', include(router.urls)),
]

You can easily test if the endpoint is working by doing the following in your terminal
Register:
curl -X POST -H "Content-Type: application/json" -H "Authorization: " -d '{
"dev_id": "Device id",
"dev_type": "ANDROID or IOS",
"reg_id": "Register id"
}' 'http://localhost:8001/api/devices'

Unregister:

3
django-gcm-android-ios Documentation, Release 1.0.0

curl -X DELETE -H "Content-Type: application/json" -H "Authorization: "


'http://localhost:8001/api/devices/<id_device>'

Note: Authorization, see Django Rest Framework docs.

Sending messages

Using Django orm:


from gcm.utils import get_device_model
Device = get_device_model()

device = Device.objects.get(dev_id=<dev_id>)

device.send_message('my test message', collapse_key='something')

collapse_key parameter is optional (default message).


If you want to send additional arguments like delay_while_idle or other, add them as named variables:
device.send_message('my test message', delay_while_idle=True, time_to_live=5)

Note: For more information, see GCM Connection Server Reference docs.

Multicast message
django-gcm-android-ios supports sending message to multiple devices at once:
from gcm.utils import get_device_model
Device = get_device_model()

Device.objects.all().send_messages('my message')

Device.objects.filter(is_active=True).send_messages('my message', collapse_key='something')

Payload
django-gcm-android-ios supports sending payload:
from gcm.utils import get_device_model
Device = get_device_model()

device = Device.objects.get(dev_id=<dev_id>)

device.send_message(data={ "score": "4x8", "time": "15:16.2342" }, collapse_key='something', time_to_

4 Chapter 1. Tutorial
CHAPTER 2

Author

• Hugo Brilhante

5
django-gcm-android-ios Documentation, Release 1.0.0

6 Chapter 2. Author
CHAPTER 3

Main features

• Python: 2,7, 3.4.


• Django: 1.7, 1.8.
• API using Django Rest Framework django-rest-framework
• Requests processing http/https using the library requests.
• Excellent coverage tests (> 80%).

7
django-gcm-android-ios Documentation, Release 1.0.0

8 Chapter 3. Main features


CHAPTER 4

Links

• Github
• Travis CI
• Coveralls

9
django-gcm-android-ios Documentation, Release 1.0.0

10 Chapter 4. Links
CHAPTER 5

References

• Google Cloud Messaging

11
django-gcm-android-ios Documentation, Release 1.0.0

12 Chapter 5. References
CHAPTER 6

License

The MIT License (MIT)


Copyright (c) 2015 Hugo Brilhante
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documen-
tation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PAR-
TICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT-
WARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

13

You might also like