Created
April 9, 2012 10:20
-
-
Save Amokrane/2342744 to your computer and use it in GitHub Desktop.
Worker code for notifs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'iron_worker' | |
class C2dmIronWorker < IronWorker::Base | |
attr_accessor :auth_token | |
attr_accessor :c2dms | |
attr_accessor :params | |
def run | |
uri = URI.parse('https://android.clients.google.com/c2dm/send') | |
c2dms.each do |c| | |
data = {} | |
data['registration_id'] = c['c2dm']['registration_id'] | |
data['collapse_key'] = `uuidgen`.strip.gsub('-', '') | |
params.each do |k,v| | |
v = v.join(',') if v.is_a? Array | |
data["data.#{k.to_s}"] = v | |
end | |
req = Net::HTTP::Post.new uri.path, 'Authorization' => "GoogleLogin auth=#{auth_token}" | |
req.set_form_data data | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE; | |
response, body = http.request(req) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment