Class: ApnsKit::Response
- Inherits:
-
Object
- Object
- ApnsKit::Response
- Defined in:
- lib/apns_kit/response.rb
Constant Summary collapse
- STATUS_CODES =
{ 200 => "Success", 400 => "Bad request", 403 => "There was an error with the certificate", 405 => "The request used a bad :method value. Only POST requests are supported", 410 => "The device token is no longer active for the topic", 413 => "The notification payload was too large", 429 => "The server received too many requests for the same device token", 500 => "Internal server error", 503 => "The server is shutting down and unavailable", }.freeze
- INVALID_TOKEN_REASONS =
Set.new(["Unregistered", "BadDeviceToken", "DeviceTokenNotForTopic"]).freeze
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#notification ⇒ Object
Returns the value of attribute notification.
-
#raw_body ⇒ Object
Returns the value of attribute raw_body.
Instance Method Summary collapse
- #bad_device_token? ⇒ Boolean
- #body ⇒ Object
- #device_token_not_for_topic? ⇒ Boolean
- #failure_reason ⇒ Object
- #id ⇒ Object
- #inspect ⇒ Object
- #invalid_token? ⇒ Boolean
- #message ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
- #unregistered? ⇒ Boolean
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
20 21 22 |
# File 'lib/apns_kit/response.rb', line 20 def headers @headers end |
#notification ⇒ Object
Returns the value of attribute notification.
20 21 22 |
# File 'lib/apns_kit/response.rb', line 20 def notification @notification end |
#raw_body ⇒ Object
Returns the value of attribute raw_body.
20 21 22 |
# File 'lib/apns_kit/response.rb', line 20 def raw_body @raw_body end |
Instance Method Details
#bad_device_token? ⇒ Boolean
54 55 56 |
# File 'lib/apns_kit/response.rb', line 54 def bad_device_token? !success? && failure_reason == "BadDeviceToken" end |
#body ⇒ Object
38 39 40 |
# File 'lib/apns_kit/response.rb', line 38 def body @body ||= raw_body.nil? ? {} : JSON.load(raw_body) end |
#device_token_not_for_topic? ⇒ Boolean
58 59 60 |
# File 'lib/apns_kit/response.rb', line 58 def device_token_not_for_topic? !success? && failure_reason == "DeviceTokenNotForTopic" end |
#failure_reason ⇒ Object
42 43 44 |
# File 'lib/apns_kit/response.rb', line 42 def failure_reason body["reason"] end |
#id ⇒ Object
22 23 24 |
# File 'lib/apns_kit/response.rb', line 22 def id headers["apns-id"] end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/apns_kit/response.rb', line 66 def inspect "#<ApnsKit::Response:#{"0x00%x" % (object_id << 1)} #{to_s}>" end |
#invalid_token? ⇒ Boolean
46 47 48 |
# File 'lib/apns_kit/response.rb', line 46 def invalid_token? !success? && INVALID_TOKEN_REASONS.include?(failure_reason) end |
#message ⇒ Object
30 31 32 |
# File 'lib/apns_kit/response.rb', line 30 def STATUS_CODES[status] end |
#status ⇒ Object
26 27 28 |
# File 'lib/apns_kit/response.rb', line 26 def status headers[":status"].to_i end |
#success? ⇒ Boolean
34 35 36 |
# File 'lib/apns_kit/response.rb', line 34 def success? status == 200 end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/apns_kit/response.rb', line 62 def to_s "#{status} (#{}) notification=#{notification}" end |
#unregistered? ⇒ Boolean
50 51 52 |
# File 'lib/apns_kit/response.rb', line 50 def unregistered? !success? && failure_reason == "Unregistered" end |