Sha256: 6f171516a16d9062e5d045a046bb03ac8152964cac5e9ded048aecbc22a9ee1b

Contents?: true

Size: 900 Bytes

Versions: 21

Compression:

Stored size: 900 Bytes

Contents

require 'active_support'

module LHC
  module BasicMethods
    extend ActiveSupport::Concern

    module ClassMethods
      def request(options)
        if options.is_a? Array
          parallel_requests(options)
        else
          LHC::Request.new(options).response
        end
      end

      [:get, :post, :put, :delete].each do |http_method|
        define_method(http_method) do |url, options = {}|
          request(options.merge(
                    url: url,
                    method: http_method
          ))
        end
      end

      private

      def parallel_requests(options)
        hydra = Typhoeus::Hydra.hydra
        requests = []
        options.each do |option|
          request = LHC::Request.new(option, false)
          requests << request
          hydra.queue request.raw
        end
        hydra.run
        requests.map(&:response)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
lhc-5.0.1 lib/lhc/concerns/lhc/basic_methods.rb
lhc-5.0.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-4.0.2 lib/lhc/concerns/lhc/basic_methods.rb
lhc-4.0.1 lib/lhc/concerns/lhc/basic_methods.rb
lhc-4.0.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.8.1 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.8.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.7.3 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.7.2 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.7.2.1 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.7.1 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.7.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.7.0.pre1 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.6.1 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.6.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.5.5 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.5.4 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.5.3 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.5.2 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.5.1 lib/lhc/concerns/lhc/basic_methods.rb