Class: Push::MessageApns

Inherits:
Message
  • Object
show all
Defined in:
lib/push/message_apns.rb

Constant Summary collapse

SELECT_TIMEOUT =
0.2
ERROR_TUPLE_BYTES =
6
APN_ERRORS =
{
  1 => "Processing error",
  2 => "Missing device token",
  3 => "Missing topic",
  4 => "Missing payload",
  5 => "Missing token size",
  6 => "Missing topic size",
  7 => "Missing payload size",
  8 => "Invalid token",
  255 => "None (unknown error)"
}

Instance Method Summary collapse

Instance Method Details

#alertObject



42
43
44
45
# File 'lib/push/message_apns.rb', line 42

def alert
  string_or_json = properties[:alert]
  MultiJson.load(string_or_json) rescue string_or_json
end

#alert=(alert) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/push/message_apns.rb', line 34

def alert=(alert)
  if alert.is_a?(Hash)
    properties[:alert] = MultiJson.dump(alert)
  else
    properties[:alert] = alert
  end
end

#attributes_for_deviceObject



30
31
32
# File 'lib/push/message_apns.rb', line 30

def attributes_for_device
  MultiJson.load(properties[:attributes_for_device]) if properties[:attributes_for_device]
end

#attributes_for_device=(attrs) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
# File 'lib/push/message_apns.rb', line 25

def attributes_for_device=(attrs)
  raise ArgumentError, "attributes_for_device must be a Hash" if !attrs.is_a?(Hash)
  properties[:attributes_for_device] = MultiJson.dump(attrs)
end

#payloadObject



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

def payload
  MultiJson.dump(as_json)
end

#payload_sizeObject



62
63
64
# File 'lib/push/message_apns.rb', line 62

def payload_size
  payload.bytesize
end

#to_message(options = {}) ⇒ Object



49
50
51
52
# File 'lib/push/message_apns.rb', line 49

def to_message(options = {})
  id_for_pack = options[:for_validation] ? 0 : id
  [1, id_for_pack, expiry, 0, 32, device, payload_size, payload].pack("cNNccH*na*")
end

#use_connectionObject



54
55
56
# File 'lib/push/message_apns.rb', line 54

def use_connection
  Push::Daemon::ApnsSupport::ConnectionApns
end