Sha256: 608867b47754bd0140fc826e112d784a02ad08781963f2bc6506d0332216f244

Contents?: true

Size: 979 Bytes

Versions: 19

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

require 'active_support'

module LHC
  module BasicMethodsConcern
    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 unless request.response.present?
        end
        hydra.run
        requests.map(&:response)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lhc-11.0.1 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-11.0.0 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.5.4 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.5.3 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.5.2 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.5.1 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.5.0 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.4.3 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.4.2 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.4.1 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.4.0 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.3.0 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.2.1 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.2.0 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.1.8 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.1.7 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.1.6 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.1.5 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.1.3 lib/lhc/concerns/lhc/basic_methods_concern.rb