Sha256: 1882fb1413f2d23ff6981bdd365b9c438d23a30dfb58d100053bfb1773d996b0

Contents?: true

Size: 888 Bytes

Versions: 10

Compression:

Stored size: 888 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 |options|
          request = LHC::Request.new(options, false)
          requests << request
          hydra.queue request.raw
        end
        hydra.run
        requests.map(&:response)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lhc-3.4.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.3.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.2.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.1.1 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.1.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-3.0.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-2.0.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-1.2.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-1.1.0 lib/lhc/concerns/lhc/basic_methods.rb
lhc-0.2.1 lib/lhc/concerns/lhc/basic_methods.rb