Class: GCM::Connection
- Inherits:
-
Object
- Object
- GCM::Connection
- Defined in:
- lib/mercurius/gcm/connection.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(host, key) ⇒ Connection
constructor
A new instance of Connection.
- #write(json) ⇒ Object
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
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/mercurius/gcm/connection.rb', line 4 def host @host end |
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/mercurius/gcm/connection.rb', line 4 def key @key end |
Instance Method Details
#client ⇒ Object
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 |