Sha256: 99c244bf6a1a5937ff89ff87028546bfd5adb98bbdfc174f99f3cd7015e9b323

Contents?: true

Size: 948 Bytes

Versions: 13

Compression:

Stored size: 948 Bytes

Contents

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

13 entries across 13 versions & 1 rubygems

Version Path
lhc-10.1.2 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.1.1 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.1.0 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.0.2 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-9.4.4 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.0.1 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-10.0.0 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-9.4.3 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-9.4.2 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-9.4.1 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-9.4.0 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-9.3.1 lib/lhc/concerns/lhc/basic_methods_concern.rb
lhc-9.3.0 lib/lhc/concerns/lhc/basic_methods_concern.rb