5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/itrigga/net_helper/typhoeus.rb', line 5
def self.get( opts={} )
opts[:timeout] ||= 30
opts[:timeout] *= 1000 opts[:follow_location] ||= true
opts[:disable_ssl_peer_verification] = true if opts[:disable_ssl_peer_verification].nil?
request = ::Typhoeus::Request.new(opts[:url], opts)
request.on_complete do |response|
if response.success?
return response.body
elsif response.timed_out?
raise ::TimeoutError.new("Timed out request to #{opts[:url]} after #{opts[:timeout]}ms")
elsif response.code == 0
raise IOError.new(response.curl_error_message)
else
raise IOError.new("HTTP request failed: " + response.code.to_s)
end
end
hydra = ::Typhoeus::Hydra.new
hydra.queue(request)
hydra.run
end
|