class Acfs::Adapter::Typhoeus
Public Class Methods
new(**kwargs)
click to toggle source
Calls superclass method
Acfs::Adapter::Base::new
# File lib/acfs/adapter/typhoeus.rb, line 16 def initialize(**kwargs) super extra_opts = kwargs.delete(:opts) @opts = DEFAULT_OPTIONS @opts = @opts.merge(extra_opts) if extra_opts @kwargs = kwargs end
Public Instance Methods
queue(request)
click to toggle source
# File lib/acfs/adapter/typhoeus.rb, line 39 def queue(request) hydra.queue convert_request request end
run(request)
click to toggle source
# File lib/acfs/adapter/typhoeus.rb, line 35 def run(request) convert_request(request).run end
start()
click to toggle source
# File lib/acfs/adapter/typhoeus.rb, line 26 def start hydra.run rescue StandardError @hydra = nil raise end
Protected Instance Methods
convert_request(req)
click to toggle source
# File lib/acfs/adapter/typhoeus.rb, line 49 def convert_request(req) opts = { method: req.method, params: req.params, headers: req.headers.merge( 'Expect' => '', 'Transfer-Encoding' => '', ), body: req.body, } request = ::Typhoeus::Request.new(req.url, **@opts, **opts) request.on_complete do |response| raise ::Acfs::TimeoutError.new(req) if response.timed_out? if response.code.zero? # Failed to get HTTP response raise ::Acfs::RequestError.new(req, response.return_message) end req.complete! convert_response(req, response) end request end
convert_response(request, response)
click to toggle source
# File lib/acfs/adapter/typhoeus.rb, line 76 def convert_response(request, response) Acfs::Response.new request, status: response.code, headers: response.headers, body: response.body end
hydra()
click to toggle source
# File lib/acfs/adapter/typhoeus.rb, line 45 def hydra @hydra ||= ::Typhoeus::Hydra.new(**@kwargs) end