Class: ProxyFetcher::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_fetcher/utils/http_fetcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ HTTPClient

Returns a new instance of HTTPClient.



5
6
7
8
9
# File 'lib/proxy_fetcher/utils/http_fetcher.rb', line 5

def initialize(url)
  @uri = URI.parse(url)
  @http = Net::HTTP.new(@uri.host, @uri.port)
  @http.use_ssl = true if @uri.scheme.downcase == 'https'
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



3
4
5
# File 'lib/proxy_fetcher/utils/http_fetcher.rb', line 3

def http
  @http
end

Class Method Details

.fetch(url) ⇒ Object



19
20
21
# File 'lib/proxy_fetcher/utils/http_fetcher.rb', line 19

def fetch(url)
  new(url).fetch
end

Instance Method Details

#fetchObject



11
12
13
14
15
16
# File 'lib/proxy_fetcher/utils/http_fetcher.rb', line 11

def fetch
  request = Net::HTTP::Get.new(@uri.to_s)
  request['Connection'] = 'keep-alive'
  response = @http.request(request)
  response.body
end