c2dm sends push notifications to Android devices via Google c2dm.
$ gem install c2dm
An Android device running 2.2 or newer, its registration token, and a Google account registered for c2dm.
First you will need to authorize with google to get your ClientLogin auth token.
Use the credentials for the app you've registered with Google.
C2DM.authorize("pat@gmail.com", "password")
This sets auth_token
for future requests.
You can also use cURL to get the AUTH= parameter:
# curl -X POST https://www.google.com/accounts/ClientLogin -d Email=<email> -d Passwd=<password> -d accountType=HOSTED_OR_GOOGLE -d service=ac2dm
We suggest you store the token and set it in your config files:
C2DM.auth_token = "YOUR_AUTH_TOKEN"
You can also set it in your environment:
ENV["C2DM_AUTH_TOKEN"] = "YOUR_AUTH_TOKEN"
If you'd like to set a custom source
param for debugging, set:
ENV["C2DM_AUTH_TOKEN"] = "CompanyName-AppName-1.0"
Send a single notification:
C2DM.send_notification({
:registration_id => "...",
:message => "Hi!",
:extra_data => 42,
:collapse_key => "some-collapse-key"
})
The only required key is :registration_id
. You may also pass
:collapse_key
, but it's optional.
All other keys will be sent as "data.<key>"
. This is the payload of your notification.
You can also send multiple notifications at once.
notifications = [
{
:registration_id => "...",
:message => "Hi!",
:extra_data => 42
},
{
:registration_id => "...",
:message => "Bye!",
:extra_data => "BOOM",
:collapse_key => "some-collapse-key"
},
...
]
C2DM.send_notifications(notifications)
- Send multiple notifications concurrently using Typhoeus::Hyrda
- Copyright (c) 2010 Amro Mousa, (c) 2011 Brandon Keene. See LICENSE.txt for details.