Class: Exponent::Push::ResponseHandler
- Inherits:
-
Object
- Object
- Exponent::Push::ResponseHandler
- Defined in:
- lib/expo-push.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#invalid_push_tokens ⇒ Object
readonly
Returns the value of attribute invalid_push_tokens.
-
#raw_errors ⇒ Object
readonly
Returns the value of attribute raw_errors.
-
#receipt_ids ⇒ Object
readonly
Returns the value of attribute receipt_ids.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #errors? ⇒ Boolean
-
#initialize(error_builder = ErrorBuilder.new) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
- #process_response(response) ⇒ Object
Constructor Details
#initialize(error_builder = ErrorBuilder.new) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
109 110 111 112 113 114 115 116 |
# File 'lib/expo-push.rb', line 109 def initialize(error_builder = ErrorBuilder.new) @error_builder = error_builder @response = nil @receipt_ids = [] @invalid_push_tokens = [] @errors = [] @raw_errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
107 108 109 |
# File 'lib/expo-push.rb', line 107 def errors @errors end |
#invalid_push_tokens ⇒ Object (readonly)
Returns the value of attribute invalid_push_tokens.
107 108 109 |
# File 'lib/expo-push.rb', line 107 def invalid_push_tokens @invalid_push_tokens end |
#raw_errors ⇒ Object (readonly)
Returns the value of attribute raw_errors.
107 108 109 |
# File 'lib/expo-push.rb', line 107 def raw_errors @raw_errors end |
#receipt_ids ⇒ Object (readonly)
Returns the value of attribute receipt_ids.
107 108 109 |
# File 'lib/expo-push.rb', line 107 def receipt_ids @receipt_ids end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
107 108 109 |
# File 'lib/expo-push.rb', line 107 def response @response end |
Instance Method Details
#errors? ⇒ Boolean
148 149 150 |
# File 'lib/expo-push.rb', line 148 def errors? @errors.any? end |
#process_response(response) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/expo-push.rb', line 118 def process_response(response) @response = response case response.code.to_s when '504' raise Exponent::Push::GatewayTimeoutError.new( "#{response.code} #{response.response_body}" ) when '503' raise Exponent::Push::UpstreamConnectError.new( "#{response.code} #{response.response_body}" ) when '502' # NOTE: Raise specific error so app knows to retry the request. raise Exponent::Push::BadGatewayError.new( "#{response.code} #{response.response_body}" ) when '400' # NOTE: The app will want to handle expo server error response differently. # Responding with an object that exposes what the expo server errored with. @raw_errors = body.fetch('errors', []) when /(^4|^5)/ # NOTE: Catch-all in case we do not get a 400 or 504 error. This will raise unknown # error with information on what the issue was. raise @error_builder.parse_response(response) else sort_results end end |