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.34.0.1.b287 lib/acfs/adapter/typhoeus.rb
acfs-0.34.0.1.b286 lib/acfs/adapter/typhoeus.rb
acfs-0.34.0 lib/acfs/adapter/typhoeus.rb
acfs-0.33.1.1.b285 lib/acfs/adapter/typhoeus.rb
acfs-0.33.1.1.b281 lib/acfs/adapter/typhoeus.rb
acfs-0.33.1 lib/acfs/adapter/typhoeus.rb
acfs-0.33.0.1.b278 lib/acfs/adapter/typhoeus.rb
acfs-0.33.0 lib/acfs/adapter/typhoeus.rb
acfs-0.32.1.1.b277 lib/acfs/adapter/typhoeus.rb
acfs-0.32.1.1.b276 lib/acfs/adapter/typhoeus.rb
acfs-0.32.1.1.b275 lib/acfs/adapter/typhoeus.rb
acfs-0.32.1.1.b274 lib/acfs/adapter/typhoeus.rb
acfs-0.32.1.1.b272 lib/acfs/adapter/typhoeus.rb
acfs-0.32.1 lib/acfs/adapter/typhoeus.rb
acfs-0.32.0.1.b270 lib/acfs/adapter/typhoeus.rb
acfs-0.31.0.1.b269 lib/acfs/adapter/typhoeus.rb
acfs-0.32.0 lib/acfs/adapter/typhoeus.rb
acfs-0.31.0.1.b265 lib/acfs/adapter/typhoeus.rb
acfs-0.31.0.1.b263 lib/acfs/adapter/typhoeus.rb
acfs-0.31.0 lib/acfs/adapter/typhoeus.rb