6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/twitterscraper/http.rb', line 6
def get(url, = {}, proxy = nil, timeout = nil)
timeout ||= 3
if proxy
ip, port = proxy.split(':')
http_class = Net::HTTP::Proxy(ip, port.to_i)
else
http_class = Net::HTTP
end
uri = URI.parse(url)
http = http_class.new(uri.host, uri.port)
http.use_ssl = true if url.match?(/^https/)
http.open_timeout = timeout
http.read_timeout = timeout
req = Net::HTTP::Get.new(uri)
.each do |key, value|
req[key] = value
end
res = http.start { http.request(req) }
res.body
end
|