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.23.2.b200 lib/acfs/adapter/typhoeus.rb
acfs-0.23.2.b199 lib/acfs/adapter/typhoeus.rb
acfs-0.23.2 lib/acfs/adapter/typhoeus.rb
acfs-0.23.1.b198 lib/acfs/adapter/typhoeus.rb
acfs-0.23.1 lib/acfs/adapter/typhoeus.rb
acfs-0.23.0.b197 lib/acfs/adapter/typhoeus.rb
acfs-0.22.2.b196 lib/acfs/adapter/typhoeus.rb
acfs-0.23.0 lib/acfs/adapter/typhoeus.rb
acfs-0.22.2.b194 lib/acfs/adapter/typhoeus.rb
acfs-0.22.2.b193 lib/acfs/adapter/typhoeus.rb
acfs-0.22.2 lib/acfs/adapter/typhoeus.rb
acfs-0.22.1.b192 lib/acfs/adapter/typhoeus.rb
acfs-0.22.1 lib/acfs/adapter/typhoeus.rb
acfs-0.22.0.b191 lib/acfs/adapter/typhoeus.rb
acfs-0.22.0.b190 lib/acfs/adapter/typhoeus.rb
acfs-0.22.0 lib/acfs/adapter/typhoeus.rb
acfs-0.21.1.b189 lib/acfs/adapter/typhoeus.rb
acfs-0.21.1.rc1.b188 lib/acfs/adapter/typhoeus.rb
acfs-0.21.1 lib/acfs/adapter/typhoeus.rb
acfs-0.21.0.rc1.b187 lib/acfs/adapter/typhoeus.rb