Sha256: 44d3ac019a9ab542e87dbf676eb92dbcfe0209ad7b8d6bd3e75752832c99afc4

Contents?: true

Size: 834 Bytes

Versions: 6

Compression:

Stored size: 834 Bytes

Contents

require 'typhoeus'

module Acfs
  module Adapter

    # Adapter for Typhoeus.
    #
    class Typhoeus

      # Run all queued requests.
      #
      def run
        hydra.run
      end

      # Add a new request or URL to the queue.
      #
      def queue(req)
        hydra.queue convert_request(req)
      end

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

      def convert_request(req)
        request = ::Typhoeus::Request.new req.url, 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, response.code, response.headers, response.body)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
acfs-0.7.0 lib/acfs/adapter/typhoeus.rb
acfs-0.6.0 lib/acfs/adapter/typhoeus.rb
acfs-0.5.1 lib/acfs/adapter/typhoeus.rb
acfs-0.5.0 lib/acfs/adapter/typhoeus.rb
acfs-0.4.0 lib/acfs/adapter/typhoeus.rb
acfs-0.3.0 lib/acfs/adapter/typhoeus.rb