Class: GCM::Service
- Inherits:
-
Object
- Object
- GCM::Service
- Includes:
- ActiveModel::Model
- Defined in:
- lib/mercurius/gcm/service.rb
Constant Summary collapse
- MAX_NUMBER_OF_RETRIES =
3- MAX_DEVICES_AT_ONCE =
999
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#host ⇒ Object
Returns the value of attribute host.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #deliver(notification, *device_tokens) ⇒ Object
-
#initialize ⇒ Service
constructor
A new instance of Service.
Constructor Details
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
9 10 11 |
# File 'lib/mercurius/gcm/service.rb', line 9 def attempts @attempts end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
9 10 11 |
# File 'lib/mercurius/gcm/service.rb', line 9 def connection @connection end |
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/mercurius/gcm/service.rb', line 8 def host @host end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/mercurius/gcm/service.rb', line 8 def key @key end |
Instance Method Details
#deliver(notification, *device_tokens) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/mercurius/gcm/service.rb', line 19 def deliver(notification, *device_tokens) result = GCM::Result.new(notification) device_tokens = Array(device_tokens).flatten device_tokens.each_slice(MAX_DEVICES_AT_ONCE) do |tokens| payload = notification.to_h.merge registration_ids: tokens result.process_response connection.write(payload), tokens end result end |