django-gcm Documentation



Similar documents
Django Two-Factor Authentication Documentation

Django on AppEngine Documentation

latest Release 0.2.6

Nupic Web Application development

Introduction to FreeNAS development

Rapid Website Deployment With Django, Heroku & New Relic

SagePay payment gateway package for django-oscar Documentation

Slides from INF3331 lectures - web programming in Python

The Django web development framework for the Python-aware

Zinnia Drupal Documentation

depl Documentation Release depl contributors

Django FTP server Documentation

django-cron Documentation

Django Mail Queue Documentation

Django FTP Deploy Documentation

Django MSSQL Documentation

Introduction to web development with Python and Django Documentation

django-helpdesk Documentation

Effective Django. Build Nathan Yergler

django_saas Documentation

Using Python, Django and MySQL in a Database Course

Introduction to Django Web Framework

Django Web Framework. Zhaojie Zhang CSCI5828 Class Presenta=on 03/20/2012

Django MSSQL Documentation

DevKey Documentation. Release 0.1. Colm O Connor

DjNRO Release 0.9 July 14, 2015

django-project-portfolio Documentation

Test-Driven Development with Python

GCM for Android Setup Guide

Web [Application] Frameworks

Flask-SSO Documentation

Django tutorial. October 22, 2010

Absorb Single Sign-On (SSO) V3.0

Python Cryptography & Security. José Manuel

Satchmo Documentation

Mobile Push Architectures

Web Application Frameworks. Robert M. Dondero, Ph.D. Princeton University

The HTTP Plug-in. Table of contents

A WEB INTERFACE FOR NATURAL LANGUAGE PROCESSING DRIVEN FAQ WEBSITE. A Thesis. Presented to the. Faculty of. San Diego State University

Magento Search Extension TECHNICAL DOCUMENTATION

django-rest-auth Documentation

Module - Facebook PS Connect

Subversion Server for Windows

i5k_doc Documentation

Connecting to the Firewall Services Module and Managing the Configuration

Whisler 1 A Graphical User Interface and Database Management System for Documenting Glacial Landmarks

Table of Contents. Table of Contents

Memopol Documentation

skype ID: store.belvg US phone number:

Outline. Lecture 18: Ruby on Rails MVC. Introduction to Rails

How to configure the TopCloudXL WHMCS plugin (version 2+) Update: Version: 2.2

Administering Jive Mobile Apps

TEST AUTOMATION FRAMEWORK

KonyOne Server Installer - Linux Release Notes

NGASI Universal APP Panel Administration and User Guide WebAppShowcase DBA NGASI

flask-mail Documentation

Use Enterprise SSO as the Credential Server for Protected Sites

Web Framework Performance Examples from Django and Rails

DRUPAL COMMERCE YELLOWCUBE CONNECTOR

AuShadha Documentation

Integrity Checking and Monitoring of Files on the CASTOR Disk Servers

Enhanced Password Security - Phase I

User Management Tool 1.6

vmprof Documentation Release 0.1 Maciej Fijalkowski, Antonio Cuni, Sebastian Pawlus

Magento OpenERP Integration Documentation


Web [Application] Frameworks

socketio Documentation

Authentic2 Documentation

Using Toaster in a Production Environment

SSC - Communication and Networking Java Socket Programming (II)

Managing Qualys Scanners

WHMCS LUXCLOUD MODULE

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

TECHNICAL NOTE SETTING UP A STRM UPDATE SERVER. Configuring your Update Server

Creating a DUO MFA Service in AWS

DLP Quick Start

Pronestor Room & Catering

NetIQ Advanced Authentication Framework. FIDO U2F Authentication Provider Installation Guide. Version 5.1.0

INSTALLATION GUIDE El Jefe 2.1 Document version: June 2014

Python and Google App Engine

Step 2. Choose security level Step 2 of 3

1 Overview Configuration on MACH Web Portal 1

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

Workspot Configuration Guide for the Cisco Adaptive Security Appliance

Conference Controller Deployment Guide

SMSNotify Extension. User Documentation. Automated SMS sender and customer relationship tool. SMSNotify User Documentation 1

introducing The BlackBerry Collaboration Service

Certified The Grinder Testing Professional VS-1165

Application Note VAST Network settings

MyMoney Documentation

Security IIS Service Lesson 6

Central Administration QuickStart Guide

OpenShift on you own cloud. Troy Dawson OpenShift Engineer, Red Hat November 1, 2013

Django-nonrel Documentation

Learn More MaaS360 Cloud Extender Checklist (MDM for Blackberry)

Install Unique Entry: As -You-Type Duplicate Prevention. No Duplicates.

TaxonHub Client. What is Taxon? TaxonHub Client. The Open Source project. suggest-term. admin. Strategy for version numbers

Transcription:

django-gcm Documentation Release 0.9.3 Adam Bogdal August 23, 2015

Contents 1 Quickstart 3 2 Sending messages 5 2.1 Multicast message............................................ 5 3 Signals 7 4 Extending device model 9 4.1 Device model............................................... 9 4.2 Use your model.............................................. 9 5 Api key authentication 11 5.1 Adding user field............................................. 11 5.2 Resource class.............................................. 11 Python Module Index 13 i

ii

django-gcm Documentation, Release 0.9.3 Django-gcm is a reusable application. It serves as a server for the GCM service and allows you to register devices and send messages to them. Contents: Contents 1

django-gcm Documentation, Release 0.9.3 2 Contents

CHAPTER 1 Quickstart 1. Install package via pip: $ pip install django-gcm 2. Add django-gcm resources to your URL router: # urls.py from django.conf.urls import include, patterns, url urlpatterns = patterns('', url(r'', include('gcm.urls')), ) To check gcm urls just use the following command: $ python manage.py gcm_urls GCM urls: * Register device /gcm/v1/device/register/ * Unregister device /gcm/v1/device/unregister/ 3. Configure django-gcm in your settings.py file: INSTALLED_APPS = [ #... 'gcm', ] GCM_APIKEY = "<api_key>" Note: To obtain api key go to https://code.google.com/apis/console and grab the key for the server app. 3

django-gcm Documentation, Release 0.9.3 4 Chapter 1. Quickstart

CHAPTER 2 Sending messages Using console: # Get the list of devices $ python manage.py gcm_messenger --devices > Devices list: > (#1) My phone # python manage.py gcm_messenger <device_id> <message> [--collapse-key <key>] $ python manage.py gcm_messenger 1 'my test message' Using Django orm: from gcm.models import get_device_model Device = get_device_model() my_phone = Device.objects.get(name='My phone') my_phone.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 e.g.: my_phone.send_message('my test message', delay_while_idle=true, time_to_live=5) Note: For more information, see Lifetime of a Message and Sending a downstream message docs. 2.1 Multicast message django-gcm supports sending message to multiple devices at once. E.g.: from gcm.models import get_device_model Device = get_device_model() Device.objects.all().send_message('my message') 5

django-gcm Documentation, Release 0.9.3 6 Chapter 2. Sending messages

CHAPTER 3 Signals gcm.signals.device_registered Sent when a device is registered. Provides the following arguments: sender The resource class used to register the device. device An instance of gcm.models.device (see Extending device model) represents the registered device. request The HttpRequest in which the device was registered. gcm.signals.device_unregistered Sent when a device is unregistered. Provides the following arguments: sender The resource class used to unregister the device. device An instance of gcm.models.device (see Extending device model) represents the unregistered device. request The HttpRequest in which the device was unregistered. 7

django-gcm Documentation, Release 0.9.3 8 Chapter 3. Signals

CHAPTER 4 Extending device model Allows you to store additional data in the device model (e.g. foreign key to the user) 4.1 Device model In your application, you need to create your own Device model. This model has to inherit from gcm.models.abstractdevice. # import the AbstractDevice class to inherit from from gcm.models import AbstractDevice class MyDevice(AbstractDevice): pass 4.2 Use your model In the end, you have to inform django-gcm where it can find your model. Add appropriate path to the settings.py file: GCM_DEVICE_MODEL = 'your_app.models.mydevice' 9

django-gcm Documentation, Release 0.9.3 10 Chapter 4. Extending device model

CHAPTER 5 Api key authentication Allows you to manage access to the GCM api using one of the available tastypie authentication methods - ApiKeyAuthentication. Note: I strongly recommend see django-tastypie Authentication docs. Adding authentication requires tastypie added to your INSTALLED_APPS in the settings.py file: INSTALLED_APPS = [... 'gcm', 'tastypie', ] 5.1 Adding user field You need to extend Device model and add user field. (See Extending device model) # your_app/models.py from django.conf import settings from django.db import models from gcm.models import AbstractDevice class MyDevice(AbstractDevice): user = models.foreignkey(settings.auth_user_model) Add appropriate path to the settings.py file: GCM_DEVICE_MODEL = 'your_app.models.mydevice' 5.2 Resource class In your application, you need to create your own Resource class. It has to inherit from gcm.resources.deviceresource. # your_app/resources.py from gcm.resources import DeviceResource from tastypie.authentication import ApiKeyAuthentication 11

django-gcm Documentation, Release 0.9.3 class AuthResource(DeviceResource): class Meta(DeviceResource.Meta): authentication = ApiKeyAuthentication() def get_queryset(self): qs = super(authresource, self).get_queryset() # to make sure that user can update only his own devices return qs.filter(user=self.request.user) def form_valid(self, form): form.instance.user = self.request.user return super(authresource, self).form_valid(form) You need to hook your resource class up in your urls.py file: # your_app/urls.py from django.conf.urls import patterns, include, url from tastypie.api import Api from.resources import AuthResource gcm_api = Api(api_name='v1') gcm_api.register(authresource()) urlpatterns = patterns('', url(r'^gcm/', include(gcm_api.urls)), ) Include your urls.py file in the main URL router: # urls.py from django.conf.urls import include, patterns, url urlpatterns = patterns('', url(r'', include('your_app.urls')), ) Note: See an example project gcm/example/apikeyauth_project 12 Chapter 5. Api key authentication

Python Module Index g gcm.signals, 7 13

django-gcm Documentation, Release 0.9.3 14 Python Module Index

Index D device_registered (in module gcm.signals), 7 device_unregistered (in module gcm.signals), 7 G gcm.signals (module), 7 15