Class: Embiggen::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/embiggen/http_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#httpObject (readonly)

Returns the value of attribute http.



6
7
8
# File 'lib/embiggen/http_client.rb', line 6

def http
  @http
end

#uriObject (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.message}", uri)
end