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.
14 15 16 17 18 |
# File 'lib/embiggen/http_client.rb', line 14 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.
12 13 14 |
# File 'lib/embiggen/http_client.rb', line 12 def http @http end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/embiggen/http_client.rb', line 12 def uri @uri end |
Instance Method Details
#follow(timeout) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/embiggen/http_client.rb', line 20 def follow(timeout) response = request(timeout) return unless response.is_a?(::Net::HTTPRedirection) response.fetch('Location') rescue ::Timeout::Error => e raise NetworkError.new( "Timeout::Error: could not follow #{uri}: #{e.}", uri ) rescue StandardError => e raise NetworkError.new( "StandardError: could not follow #{uri}: #{e.}", uri ) end |