Skip to content

Instantly share code, notes, and snippets.

@Amokrane
Created April 9, 2012 11:57
Show Gist options
  • Save Amokrane/2343035 to your computer and use it in GitHub Desktop.
Save Amokrane/2343035 to your computer and use it in GitHub Desktop.
New Iron Worker
puts "IronWorker::Starting C2dmIronWorker at #{Time.now}"
puts "IronWorker::We got following params #{params}"
uri = URI.parse('https://android.clients.google.com/c2dm/send')
params['c2dms'].each do |c|
data = {}
data['registration_id'] = c['c2dm']['registration_id']
data['collapse_key'] = `uuidgen`.strip.gsub('-', '')
params['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=#{params['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)
if(response.code.to_i == 200)
puts "Response code is 200"
puts body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment