class Embiggen::HttpClient

Attributes

http[R]
uri[R]

Public Class Methods

new(uri) click to toggle source
# 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

Public Instance Methods

follow(timeout) click to toggle source
# 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 StandardError, ::Timeout::Error => e
  raise NetworkError.new(
    "could not follow #{uri}: #{e.message}", uri)
end

Private Instance Methods

request(timeout) click to toggle source
# File lib/embiggen/http_client.rb, line 32
def request(timeout)
  request = GetWithoutBody.new(uri.request_uri)
  http.open_timeout = timeout
  http.read_timeout = timeout

  http.request(request)
end