-
Notifications
You must be signed in to change notification settings - Fork 1
/
requester.rb
51 lines (32 loc) · 1.07 KB
/
requester.rb
1
2
3
4
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'typhoeus'
class Requester
def self.make_request(url, request_params, method)
hydra = Typhoeus::Hydra.new
request = Typhoeus::Request.new(url,
:timeout => 100000,
:cache_timeout => 60,
:method => method,
:verbose => true,
:params => request_params )
request.on_complete do |response|
if response.success?
return response.body
elsif response.code == 202
return response.body
elsif response.timed_out?
print "Server Response URL got a time out"
return false
elsif response.code == 0
# Could not get an http response, something's wrong
print "#{response.curl_error_message}"
return false
else
# Received a non-successful htpp response.
print "HTTP request failed: #{response.code.to_s}"
return false
end
end
hydra.queue(request)
hydra.run
end
end