class StellaGCM
Constants
- URL
Public Class Methods
new(private_key, option = nil)
click to toggle source
# File lib/stella_gcm.rb, line 6 def initialize(private_key, option = nil) @http = Net::HTTP::Persistent.new 'StellaGcm' @http.idle_timeout = option.nil? ? 1 :option[:idle_timeout] @http.open_timeout = option.nil? ? 30 :option[:open_timeout] @http.read_timeout = option.nil? ? 60 :option[:read_timeout] @http.headers['Authorization'] = "key=#{private_key}" @http.headers['Content-Type'] = "application/json" end
Public Instance Methods
body(ids, option)
click to toggle source
# File lib/stella_gcm.rb, line 39 def body(ids, option) {:registration_ids => ids}.merge!(option) end
send_notification(ids, option)
click to toggle source
# File lib/stella_gcm.rb, line 15 def send_notification(ids, option) gcm_server_uri = URI URL request = Net::HTTP::Post.new gcm_server_uri.path request.body = self.body(ids, option).to_json begin response = @http.request gcm_server_uri, request rescue return {:code => 404, :response => nil, :msg => 'GCM Server Not Connected.'} end begin body = ActiveSupport::JSON.decode(response.body).with_indifferent_access rescue return {:code => 500, :response => response, :msg => 'Json Parse failed Return Value.'} end {:code => 0, :response => body} end