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