Sha256: 2c3e00bf2ceac7b41998350acc2c73760891946b0cac268571d743958998f2f1

Contents?: true

Size: 1.14 KB

Versions: 95

Compression:

Stored size: 1.14 KB

Contents

require 'typhoeus'

module Acfs
  module Adapter

    # Adapter for Typhoeus.
    #
    class Typhoeus < Base

      def start
        hydra.run
      end

      def abort
        hydra.abort
      end

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

      def queue(request)
        hydra.queue convert_request request
      end

    protected
      def hydra
        @hydra ||= ::Typhoeus::Hydra.new
      end

      def convert_request(req)
        request = ::Typhoeus::Request.new req.url,
                                          method: req.method,
                                          params: req.params,
                                          headers: req.headers,
                                          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

95 entries across 95 versions & 1 rubygems

Version Path
acfs-0.21.1.rc1 lib/acfs/adapter/typhoeus.rb
acfs-0.21.0.rc1 lib/acfs/adapter/typhoeus.rb
acfs-0.22.0.rc1.b186 lib/acfs/adapter/typhoeus.rb
acfs-0.21.0.b185 lib/acfs/adapter/typhoeus.rb
acfs-0.20.0.dev.b184 lib/acfs/adapter/typhoeus.rb
acfs-0.21.0 lib/acfs/adapter/typhoeus.rb
acfs-0.20.0.dev.b183 lib/acfs/adapter/typhoeus.rb
acfs-0.20.0.dev.b182 lib/acfs/adapter/typhoeus.rb
acfs-0.20.0.dev.b181 lib/acfs/adapter/typhoeus.rb
acfs-0.20.0 lib/acfs/adapter/typhoeus.rb
acfs-0.19.0 lib/acfs/adapter/typhoeus.rb
acfs-0.18.0 lib/acfs/adapter/typhoeus.rb
acfs-0.17.0 lib/acfs/adapter/typhoeus.rb
acfs-0.16.0 lib/acfs/adapter/typhoeus.rb
acfs-0.15.0 lib/acfs/adapter/typhoeus.rb