9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/c2dm_on_rails/libs/connection.rb', line 9
def send_notification(noty, token)
= { "Content-Type" => "application/x-www-form-urlencoded",
"Authorization" => "GoogleLogin auth=#{token}" }
message_data = noty.data.map{|k, v| "&data.#{k}=#{URI.escape(v)}"}.reduce{|k, v| k + v}
data = "registration_id=#{noty.device.registration_id}&collapse_key=#{noty.collapse_key}#{message_data}"
data = data + "&delay_while_idle" if noty.delay_while_idle
url_string = configatron.c2dm.api_url
url=URI.parse url_string
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
resp, dat = http.post(url.path, data, )
return {:code => resp.code.to_i, :message => dat}
end
|