Class: Pushr::Daemon::FcmSupport::ResponseHandler
- Inherits:
-
Object
- Object
- Pushr::Daemon::FcmSupport::ResponseHandler
- Defined in:
- lib/pushr/daemon/fcm_support/response_handler.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#response ⇒ Object
Returns the value of attribute response.
-
#retry_count ⇒ Object
Returns the value of attribute retry_count.
Instance Method Summary collapse
- #handle ⇒ Object
-
#handle_error_5xx_response ⇒ Object
sleep if there is a Retry-After header.
- #handle_success_response ⇒ Object
-
#initialize(response, data, retry_count) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
Constructor Details
#initialize(response, data, retry_count) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
6 7 8 9 10 |
# File 'lib/pushr/daemon/fcm_support/response_handler.rb', line 6 def initialize(response, data, retry_count) @response = response @data = data @retry_count = retry_count end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/pushr/daemon/fcm_support/response_handler.rb', line 5 def data @data end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/pushr/daemon/fcm_support/response_handler.rb', line 5 def response @response end |
#retry_count ⇒ Object
Returns the value of attribute retry_count.
5 6 7 |
# File 'lib/pushr/daemon/fcm_support/response_handler.rb', line 5 def retry_count @retry_count end |
Instance Method Details
#handle ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pushr/daemon/fcm_support/response_handler.rb', line 12 def handle case @response.code.to_i when 200 handle_success_response when 400 # Pushr::Daemon.logger.error("[#{@name}] JSON formatting exception received.") Pushr::Daemon::DeliveryError.new(@response.code, @data, 'JSON formatting exception', 'FCM', false) when 401 # Pushr::Daemon.logger.error("[#{@name}] Authentication exception received.") Pushr::Daemon::DeliveryError.new(@response.code, @data, 'Authentication exception', 'FCM', false) when 500..599 # internal error FCM server || service unavailable: exponential back-off handle_error_5xx_response() else # Pushr::Daemon.logger.error("[#{@name}] Unknown error: #{@response.code} #{response.message}") Pushr::Daemon::DeliveryError.new(@response.code, @data, "Unknown error: #{response.}", 'FCM', false) end end |
#handle_error_5xx_response ⇒ Object
sleep if there is a Retry-After header
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pushr/daemon/fcm_support/response_handler.rb', line 32 def handle_error_5xx_response value = @response.header['Retry-After'] if value && value.to_i.positive? sleep value.to_i # Retry-After: 3600 elsif value && Date.rfc2822(value) # Retry-After: Fri, 31 Dec 1999 23:59:59 GMT sleep Time.now.utc - Date.rfc2822(value).to_time.utc else sleep 2**@retry_count end end |
#handle_success_response ⇒ Object
43 44 45 |
# File 'lib/pushr/daemon/fcm_support/response_handler.rb', line 43 def handle_success_response() puts @response.body.inspect end |