Class: ProxyFetcher::HTTPClient
- Inherits:
-
Object
- Object
- ProxyFetcher::HTTPClient
- Defined in:
- lib/proxy_fetcher/utils/http_client.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
- #https? ⇒ Boolean
-
#initialize(url) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
Constructor Details
#initialize(url) ⇒ HTTPClient
Returns a new instance of HTTPClient.
5 6 7 8 9 10 11 12 |
# File 'lib/proxy_fetcher/utils/http_client.rb', line 5 def initialize(url) @uri = URI.parse(url) @http = Net::HTTP.new(@uri.host, @uri.port) return unless https? @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_NONE end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
3 4 5 |
# File 'lib/proxy_fetcher/utils/http_client.rb', line 3 def http @http end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/proxy_fetcher/utils/http_client.rb', line 3 def uri @uri end |
Class Method Details
.fetch(url) ⇒ Object
27 28 29 |
# File 'lib/proxy_fetcher/utils/http_client.rb', line 27 def fetch(url) new(url).fetch end |
Instance Method Details
#fetch ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/proxy_fetcher/utils/http_client.rb', line 14 def fetch request = Net::HTTP::Get.new(@uri.to_s) request['Connection'] = 'keep-alive' request['User-Agent'] = ProxyFetcher.config.user_agent response = @http.request(request) response.body end |
#https? ⇒ Boolean
22 23 24 |
# File 'lib/proxy_fetcher/utils/http_client.rb', line 22 def https? @uri.is_a?(URI::HTTPS) end |