Class: FetchUtil::Regulatory::HttpClient

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

Constant Summary collapse

DEFAULT_ACCEPT =
"text/html,application/json,text/plain,*/*"

Instance Method Summary collapse

Constructor Details

#initialize(timeout:, user_agent:, redirect_client: nil) ⇒ HttpClient

Returns a new instance of HttpClient.



105
106
107
108
# File 'lib/fetch_util/regulatory/http_client.rb', line 105

def initialize(timeout:, user_agent:, redirect_client: nil)
  @user_agent = user_agent.to_s.strip
  @redirect_client = redirect_client || FetchUtil::HttpRedirectClient.new(timeout: timeout, headers: request_headers)
end

Instance Method Details

#get(url, limit: FetchUtil::HttpRedirectClient::REDIRECT_LIMIT) ⇒ Object



110
111
112
113
114
# File 'lib/fetch_util/regulatory/http_client.rb', line 110

def get(url, limit: FetchUtil::HttpRedirectClient::REDIRECT_LIMIT)
  build_response(redirect_client.get(url, limit: limit))
rescue URI::InvalidURIError
  raise ArgumentError, "unsupported url: #{url}"
end