class Lowdown::Response

An object that represents a response from the Apple Push Notification service for a single notification delivery.

@see developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html

@attr [Hash] headers

The HTTP response headers from the service.

@attr [String] raw_body

The JSON encoded response body from the service.

Constants

INVALID_TOKEN_REASONS

The reasons that indicate a device token not being valid besides just being unregistered.

STATUS_CODES

Public Instance Methods

activity_last_checked_at() click to toggle source

@return [Time, nil]

in case of an inactive token, the time at which the service last verified it.
# File lib/lowdown/response.rb, line 97
def activity_last_checked_at
  Time.at(body["timestamp"].to_i / 1000) if inactive_token?
end
body() click to toggle source

@return [Hash, nil]

the response payload from the service, which is empty in the case of a successful delivery.
# File lib/lowdown/response.rb, line 69
def body
  JSON.parse(raw_body) if raw_body
end
failure_reason() click to toggle source

@return [String, nil]

the reason for a failed delivery.
# File lib/lowdown/response.rb, line 76
def failure_reason
  body["reason"] unless success?
end
id() click to toggle source

@return [String]

either the {Notification#id} or, if none was provided, an ID generated by the service.
# File lib/lowdown/response.rb, line 37
def id
  headers["apns-id"]
end
inactive_token?() click to toggle source

@return [Boolean]

whether or not the delivery has failed due to a token no longer being active.
# File lib/lowdown/response.rb, line 90
def inactive_token?
  status == 410
end
inspect() click to toggle source

@return [String]

a formatted description of the response used for debugging.
# File lib/lowdown/response.rb, line 113
def inspect
  "#<Lowdown::Connection::Response #{to_s}>"
end
invalid_token?() click to toggle source

@return [Boolean]

whether or not the token is invalid for any of the reasons listed in {INVALID_TOKEN_REASONS}.
# File lib/lowdown/response.rb, line 83
def invalid_token?
  !success? && INVALID_TOKEN_REASONS.include?(failure_reason)
end
message() click to toggle source

@return [String]

the message belonging to the {#status} returned by the service.

@see Response::STATUS_CODES

# File lib/lowdown/response.rb, line 55
def message
  STATUS_CODES[status]
end
status() click to toggle source

@return [Integer]

the HTTP status returned by the service.

@see Response::STATUS_CODES

# File lib/lowdown/response.rb, line 46
def status
  headers[":status"].to_i
end
success?() click to toggle source

@return [Boolean]

whether or not the notification has been delivered.
# File lib/lowdown/response.rb, line 62
def success?
  status == 200
end
to_s() click to toggle source

@return [String]

a formatted description of the response.
# File lib/lowdown/response.rb, line 104
def to_s
  reason = ": #{failure_reason}" unless success?
  last_check = " last checked at #{activity_last_checked_at}" if inactive_token?
  "#{status} (#{message})#{reason}#{last_check}"
end