class Iconik::HttpClient

Attributes

url[R]

Public Class Methods

new(url) click to toggle source
# File lib/iconik/http_client.rb, line 7
def initialize(url)
  @url = url
end

Public Instance Methods

response_body() click to toggle source
# File lib/iconik/http_client.rb, line 11
def response_body
  get_response(url)
end

Private Instance Methods

get_response(arg_url, limit = 10) click to toggle source
# File lib/iconik/http_client.rb, line 22
def get_response(arg_url, limit = 10)
  valid_url(arg_url)
  response = ::Net::HTTP.get_response(URI.parse(arg_url))
  case response
  when ::Net::HTTPSuccess
    response.body
  when ::Net::HTTPRedirection
    get_response(response['location'], limit - 1)
  else
    response.value
  end
end
valid_url(arg_url) click to toggle source
# File lib/iconik/http_client.rb, line 17
def valid_url(arg_url)
  uri = ::URI.parse(arg_url)
  raise Iconik::InvalidURIError.new unless [::URI::HTTP, ::URI::HTTPS].any? { |k| uri.kind_of?(k) }
end