Class: Push0r::GcmPushMessage

Inherits:
PushMessage show all
Defined in:
lib/push0r/GCM/GcmPushMessage.rb

Overview

GcmPushMessage is a PushMessage implementation that encapsulates a single push notification to be sent to a single or multiple users.

Instance Attribute Summary

Attributes inherited from PushMessage

#identifier, #payload, #receiver_token, #time_to_live

Instance Method Summary collapse

Methods inherited from PushMessage

#attach

Constructor Details

#initialize(receiver_token, identifier = nil, time_to_live = nil) ⇒ GcmPushMessage

Returns a new GcmPushMessage instance that encapsulates a single push notification to be sent to a single or multiple users.

Parameters:

  • receiver_token (Array<String>)

    the apns push tokens (aka registration ids) to push the notification to

  • identifier (Fixnum) (defaults to: nil)

    a unique identifier to identify this push message during error handling. If nil, a random identifier is automatically generated.

  • time_to_live (Fixnum) (defaults to: nil)

    The time to live in seconds for this push messages. If nil, the time to live is set to four weeks.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/push0r/GCM/GcmPushMessage.rb', line 9

def initialize(receiver_token, identifier = nil, time_to_live = nil)
  if identifier.nil? ## make sure the message has an identifier
    identifier = Random.rand(2**32)
  end

  # for GCM the receiver_token is an array, so make sure we convert a single string to an array containing that string :-)
  if receiver_token.is_a?(String)
    receiver_token = [receiver_token]
  end

  super(receiver_token, identifier, time_to_live)

  if time_to_live && time_to_live.to_i >= 0
    self.attach({'time_to_live' => time_to_live.to_i})
  end
end