Module: Typhoeus::Request::Callbacks
- Included in:
- Typhoeus::Request
- Defined in:
- lib/typhoeus/request/callbacks.rb
Overview
Note:
If you’re using the Hydra to execute multiple requests, then callbacks are delaying the request execution.
This module contains the logic for the response callbacks. The on_complete callback is the only one at the moment.
You can set multiple callbacks, which are then executed in the same order.
request.on_complete { |response| p 1 }
request.on_complete { |response| p 2 }
request.execute_callbacks
#=> 1
#=> 2
You can clear the callbacks:
request.on_complete { |response| p 1 }
request.on_complete { |response| p 2 }
request.on_complete.clear
request.execute_callbacks
#=> []
Defined Under Namespace
Modules: Types
Instance Method Summary collapse
-
#execute_callbacks ⇒ void
private
Execute nessecary callback and yields response.
Instance Method Details
#execute_callbacks ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Execute nessecary callback and yields response. This include in every case on_complete, on_success if successful and on_failure if not.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/typhoeus/request/callbacks.rb', line 89 def execute_callbacks callbacks = Typhoeus.on_complete + on_complete if response && response.success? callbacks += Typhoeus.on_success + on_success elsif response callbacks += Typhoeus.on_failure + on_failure end callbacks.map do |callback| self.response.handled_response = callback.call(self.response) end end |