Class: GCM::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/mercurius/gcm/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, key) ⇒ Connection

Returns a new instance of Connection.



6
7
8
9
# File 'lib/mercurius/gcm/connection.rb', line 6

def initialize(host, key)
  @host = host
  @key = key
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/mercurius/gcm/connection.rb', line 4

def host
  @host
end

#keyObject

Returns the value of attribute key.



4
5
6
# File 'lib/mercurius/gcm/connection.rb', line 4

def key
  @key
end

Instance Method Details

#clientObject



15
16
17
18
19
20
21
# File 'lib/mercurius/gcm/connection.rb', line 15

def client
  @_client ||= Faraday.new(host) do |http|
    http.headers['Authorization'] = "key=#{key}"
    http.request :json
    http.adapter :net_http
  end
end

#write(json) ⇒ Object



11
12
13
# File 'lib/mercurius/gcm/connection.rb', line 11

def write(json)
  client.post '/gcm/send', json
end