class Gilgamesh
Constants
- VERSION
Attributes
api_key[RW]
response[R]
Public Class Methods
new(api_key, default_icon:, api_url: "http://gcm-http.googleapis.com/gcm/send")
click to toggle source
# File lib/gilgamesh.rb, line 9 def initialize(api_key, default_icon:, api_url: "http://gcm-http.googleapis.com/gcm/send") @api_key = api_key @api_url = api_url @default_icon = default_icon end
Public Instance Methods
conn()
click to toggle source
# File lib/gilgamesh.rb, line 15 def conn @conn ||= Faraday.new(url: api_url) do |faraday| faraday.adapter Faraday.default_adapter end end
push(registration_token, title:, body:, click_action: nil, icon: nil)
click to toggle source
# File lib/gilgamesh.rb, line 21 def push(registration_token, title:, body:, click_action: nil, icon: nil) body = { to: registration_token, notification: { title: title, body: body, icon: icon || default_icon } } body[:notification].merge!(click_action: click_action) unless click_action.nil? @response = conn.post do |req| req.headers['Authorization'] = "key=#{api_key}" req.headers['Content-Type'] = 'application/json' req.body = body.to_json end case response.status when 200 "Success" when 400 "INVALID_REGISTRATION: registration_token is not valid" when 401 "Unauthorized: API key is not valid" end end