Class: Pushr::Daemon::GcmSupport::ResponseHandler
- Inherits:
-
Object
- Object
- Pushr::Daemon::GcmSupport::ResponseHandler
- Defined in:
- lib/pushr/daemon/gcm_support/response_handler.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #handle ⇒ Object
- #handle_single(result, registration_id) ⇒ Object
-
#initialize(response, message) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
Constructor Details
#initialize(response, message) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
6 7 8 9 |
# File 'lib/pushr/daemon/gcm_support/response_handler.rb', line 6 def initialize(response, ) self.response = response self. = end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/pushr/daemon/gcm_support/response_handler.rb', line 5 def end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/pushr/daemon/gcm_support/response_handler.rb', line 5 def response @response end |
Instance Method Details
#handle ⇒ Object
11 12 13 14 15 16 |
# File 'lib/pushr/daemon/gcm_support/response_handler.rb', line 11 def handle hsh = MultiJson.load(response.body) hsh['results'].each_with_index do |result, index| handle_single(result, .registration_ids[index]) end end |
#handle_single(result, registration_id) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pushr/daemon/gcm_support/response_handler.rb', line 18 def handle_single(result, registration_id) if result.key?('error') if result['error'] == 'NotRegistered' || result['error'] == 'InvalidRegistration' Pushr::FeedbackGcm.create(app: .app, failed_at: Time.now, device: registration_id, follow_up: 'delete') end if result['error'] == 'Unavailable' # TODO: If it is Unavailable, you could retry to send it in another request m = .clone m.registration_ids = [registration_id] m.save end # Pushr::Daemon.logger.error("[#{@name}] Error received.") # fail Pushr::Daemon::DeliveryError.new(@response.code, nil, msg, 'GCM', false) elsif result.key?('registration_id') # success, but update device token hsh = { app: .app, failed_at: Time.now, device: registration_id, follow_up: 'update', update_to: result['registration_id'] } Pushr::FeedbackGcm.create(hsh) end end |