Sha256: b1bcd380e8da89abb5df3dbd80fd8ec56643b152e29f4cf41023db0ccfb474ae

Contents?: true

Size: 1.17 KB

Versions: 19

Compression:

Stored size: 1.17 KB

Contents

require 'typhoeus'

module Acfs
  module Adapter
    # Adapter for Typhoeus.
    #
    class Typhoeus < Base
      def initialize(**kwargs)
        @options = kwargs
      end

      def start
        hydra.run
      rescue
        @hydra = nil
        raise
      end

      delegate :abort, to: :hydra

      def run(request)
        convert_request(request).run
      end

      def queue(request)
        hydra.queue convert_request request
      end

      protected

      def hydra
        @hydra ||= ::Typhoeus::Hydra.new(**@options)
      end

      def convert_request(req)
        request = ::Typhoeus::Request.new req.url,
          method: req.method,
          params: req.params,
          headers: req.headers.merge(
            'Expect'            => '',
            'Transfer-Encoding' => ''
          ),
          body: req.body

        request.on_complete do |response|
          req.complete! convert_response(req, response)
        end

        request
      end

      def convert_response(request, response)
        Acfs::Response.new request,
          status: response.code,
          headers: response.headers,
          body: response.body
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
acfs-1.3.2 lib/acfs/adapter/typhoeus.rb
acfs-1.3.1 lib/acfs/adapter/typhoeus.rb
acfs-1.3.0 lib/acfs/adapter/typhoeus.rb
acfs-1.2.1 lib/acfs/adapter/typhoeus.rb
acfs-0.50.0 lib/acfs/adapter/typhoeus.rb
acfs-1.2.0 lib/acfs/adapter/typhoeus.rb
acfs-0.49.1 lib/acfs/adapter/typhoeus.rb
acfs-1.1.1 lib/acfs/adapter/typhoeus.rb
acfs-0.49.0 lib/acfs/adapter/typhoeus.rb
acfs-1.1.0 lib/acfs/adapter/typhoeus.rb
acfs-0.48.2 lib/acfs/adapter/typhoeus.rb
acfs-1.0.1 lib/acfs/adapter/typhoeus.rb
acfs-0.48.1 lib/acfs/adapter/typhoeus.rb
acfs-1.0.0 lib/acfs/adapter/typhoeus.rb
acfs-0.48.0 lib/acfs/adapter/typhoeus.rb
acfs-0.47.0 lib/acfs/adapter/typhoeus.rb
acfs-0.46.0 lib/acfs/adapter/typhoeus.rb
acfs-0.45.0 lib/acfs/adapter/typhoeus.rb
acfs-0.44.0 lib/acfs/adapter/typhoeus.rb