This gem is for sending C2DM message to an android device. It depends on gdata_19 gem.
Installation:
In the Gemfile:
gem 'gdata-c2dm'
Then run bundle install to install the gem.
The email and password details of the registered email should be stored in the
file google_data.yml in config/initializers directory.
Sample config/initializers/google_data.yml file.
defaults: &defaults
allow_dynamic_fields: true
development:
username: <email>
password: <password>
production:
username: <email>
password: <password>
The gem also makes use of a model to store the clientlogin token so that
it won't get a new one every time it is called. So create a model with the name
GoogleInfo
Create a file in app/models/google_info.rb with the following fields:
field :username, :type => String # Google username.
field :google_service, :type => String # Google service name. Ex: ac2dm, cl
field :clientauth_token, :type => String # Google client auth token for the service.
Sample file for Mongoid:
app/models/google_info.rb
class GoogleInfo
include Mongoid::Document
include Mongoid::Timestamps
field :username, :type => String # Google username.
field :google_service, :type => String # Google service name. Ex: ac2dm, cl
field :clientauth_token, :type => String # Google client auth token for the service.
validates_presence_of :username, :google_service, :clientauth_token
validates_uniqueness_of :username, :scope => :google_service
end
How to use?
# data_hash should be the data which is sent(Data should be sent in key value pairs to google)
data_hash = Hash.new
data_hash['timestamp'] = Time.now.to_s
data_hash['<key>'] = <value>
# To send the message:
sender = C2dmSender.new
data_hash = get_data_hash(message)
sender.notification(registration_ids, data_hash).deliver
FAQ:
1. Will it automatically obtain AuthToken and send C2DMessage?
Yes. It will manage the auth token lifecycle itself. For this we should supply GoogleInfo model.
2. AutoRenewal of AuthToken. Will it automatically fetch the new AuthToken if expired?
Yes. It will manage the auth token key itself.
3. Bulk message delivery?
Yes. Currently messages are delivered one by one in a loop.
This gem is still a work in progress. Will be adding lot many things as and when
need arises. You are free to adapt and contribute.
TODO:
1. Currently it will loop through the registration ids and send one msg at a time.
We should use multithreading to speed up the process.Project
gdata-c2dm
GData clone with C2DM included.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Development
Dependencies
Runtime
>= 0
Project Readme