class GCM::Client

Attributes

auth_token[R]
uri[R]

Public Class Methods

new(uri, auth_key) click to toggle source
# File lib/gcm/client.rb, line 10
def initialize(uri, auth_key)
  @uri = URI.parse(uri)
  @auth_key = auth_key
end

Public Instance Methods

notify(device, notification) click to toggle source

Send a notification to a device

# File lib/gcm/client.rb, line 18
def notify(device, notification)
  response = make_request(:notify, {:device => device, :data => notification.data})
  NotificationResponse.new(response)
end

Private Instance Methods

make_request(method, payload = {}) click to toggle source

Make an HTTP request

# File lib/gcm/client.rb, line 27
def make_request(method, payload = {})
  request = Net::HTTP::Post.new("/api/#{method}")
  request.body = payload.merge({:auth_key => @auth_key}).to_json
  request.add_field 'User-Agent', "GCM Ruby Client Library/#{GCM::VERSION}"
  connection = Net::HTTP.new(@uri.host, @uri.port)
  if @uri.is_a?(URI::HTTPS)
    connection.use_ssl = true
    connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  result = connection.request(request)
  Response.new(result)
end