Class: GCM::Service

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/mercurius/gcm/service.rb

Constant Summary collapse

BATCH_SIZE =
999

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeService

Returns a new instance of Service.



10
11
12
13
14
15
16
# File 'lib/mercurius/gcm/service.rb', line 10

def initialize(*)
  super
  @host ||= GCM.host
  @key  ||= GCM.key
  @connection = GCM::Connection.new(@host, @key)
  @attempts = 0
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



8
9
10
# File 'lib/mercurius/gcm/service.rb', line 8

def attempts
  @attempts
end

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/mercurius/gcm/service.rb', line 8

def connection
  @connection
end

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#keyObject

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

#deliver(notification, *tokens, topic: nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/mercurius/gcm/service.rb', line 18

def deliver(notification, *tokens, topic: nil)
  responses = GCM::ResponseCollection.new(notification)
  responses << deliver_to_tokens(notification, tokens)
  responses << deliver_to_topic(notification, topic) if topic
  responses
end