Class: Embiggen::HttpClient
- Inherits:
-
Object
- Object
- Embiggen::HttpClient
- Defined in:
- lib/embiggen/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.
Instance Method Summary collapse
- #follow(timeout) ⇒ Object
-
#initialize(uri) ⇒ HttpClient
constructor
A new instance of HttpClient.
Constructor Details
#initialize(uri) ⇒ HttpClient
Returns a new instance of HttpClient.
8 9 10 11 12 |
# File 'lib/embiggen/http_client.rb', line 8 def initialize(uri) @uri = uri @http = ::Net::HTTP.new(uri.host, uri.port) @http.use_ssl = true if uri.scheme == 'https' end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
6 7 8 |
# File 'lib/embiggen/http_client.rb', line 6 def http @http end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
6 7 8 |
# File 'lib/embiggen/http_client.rb', line 6 def uri @uri end |
Instance Method Details
#follow(timeout) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/embiggen/http_client.rb', line 14 def follow(timeout) response = request(timeout) return unless response.is_a?(::Net::HTTPRedirection) response.fetch('Location') rescue StandardError, ::Timeout::Error => e raise NetworkError.new( "could not follow #{uri}: #{e.}", uri) end |