Class: Push0r::PushMessage Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/push0r/PushMessage.rb

Overview

This class is abstract.

PushMessage is the base class for all implemented push message types. A PushMessage encapsulates values like the notification’s payload, its receiver, etc.

Direct Known Subclasses

ApnsPushMessage, GcmPushMessage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Creates a new PushMessage instance

Parameters:

  • receiver_token (String, Array)

    the receiver’s push token. Some subclasses might also accept an Array of tokens.

  • 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 depends on the service used to transmit the message.



15
16
17
18
19
20
# File 'lib/push0r/PushMessage.rb', line 15

def initialize(receiver_token, identifier = nil, time_to_live = nil)
  @receiver_token = receiver_token
  @identifier = identifier
  @time_to_live = time_to_live
  @payload = {}
end

Instance Attribute Details

#identifierFixnum (readonly)

the unique identifier for this push message

Returns:

  • (Fixnum)

    the current value of identifier



8
9
10
# File 'lib/push0r/PushMessage.rb', line 8

def identifier
  @identifier
end

#payloadHash (readonly)

the payload for this push message

Returns:

  • (Hash)

    the current value of payload



8
9
10
# File 'lib/push0r/PushMessage.rb', line 8

def payload
  @payload
end

#receiver_tokenString, Array (readonly)

the receiver’s push token

Returns:

  • (String, Array)

    the current value of receiver_token



8
9
10
# File 'lib/push0r/PushMessage.rb', line 8

def receiver_token
  @receiver_token
end

#time_to_liveFixnum (readonly)

the time to live in seconds for this push message

Returns:

  • (Fixnum)

    the current value of time_to_live



8
9
10
# File 'lib/push0r/PushMessage.rb', line 8

def time_to_live
  @time_to_live
end

Instance Method Details

#attach(payload = {}) ⇒ self

Note:

attaching is done using the merge! method of the Hash class, i.e. be careful not to overwrite previously set Hash keys.

Attaches the given payload to the push message.

Parameters:

  • payload (Hash) (defaults to: {})

    the payload to attach to the message.

Returns:

  • (self)

    self



26
27
28
29
# File 'lib/push0r/PushMessage.rb', line 26

def attach(payload = {})
  @payload.merge!(payload)
  return self
end