Class: APNs4r::Notification

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, payload) ⇒ Notification

Returns a new instance of Notification.


43
44
45
# File 'lib/apncore.rb', line 43

def initialize token, payload
  @token, @payload = token, payload
end

Class Method Details

.create(token, payload) ⇒ Object

Creates new notification with given token and payload APNs4r::Notification.create 'e754dXXXX…', { :aps => => “Hey, dude!”, :badge => 1, :custom_data => “asd” }

Parameters:

  • token (String, Fixnum)

    APNs token of device to notify

  • payload (Hash, String)

    attached payload


52
53
54
# File 'lib/apncore.rb', line 52

def Notification.create(token, payload)
  Notification.new token.kind_of?(String) ? token.delete(' ') : token.to_s(16) , payload.kind_of?(Hash) ? payload.to_payload : payload
end

.parse(bitstring) ⇒ Notification

Counterpart of #to_s - parses from binary string

Parameters:

  • bitstring (String)

    string to parse

Returns:


65
66
67
68
# File 'lib/apncore.rb', line 65

def Notification.parse bitstring
  command, tokenlen, token, payloadlen, payload = bitstring.unpack("CnH64na*")
  Notification.new(token, payload)
end

Instance Method Details

#to_sString

Converts to binary string wich can be writen directly into socket

Returns:

  • (String)

    binary string representation


58
59
60
# File 'lib/apncore.rb', line 58

def to_s
  [0, 32, @token, @payload.length, @payload ].pack("CnH*na*")
end