Class: Miteru::HTTP::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/miteru/http.rb

Overview

HTTP client factory

Constant Summary collapse

USER_AGENT =
"miteru/#{Miteru::VERSION}".freeze

Class Method Summary collapse

Class Method Details

.build(headers: {}, timeout: nil, raise_exception: true) ⇒ ::HTTP::Client

Parameters:

  • timeout (Integer, nil) (defaults to: nil)
  • headers (Hash) (defaults to: {})
  • raise_exception (Boolean) (defaults to: true)
  • raise_exception (Object) (defaults to: true)

Returns:

  • (::HTTP::Client)


39
40
41
42
43
44
45
46
47
# File 'lib/miteru/http.rb', line 39

def build(headers: {}, timeout: nil, raise_exception: true)
  client = raise_exception ? ::HTTP.use(:better_error) : ::HTTP

  headers["User-Agent"] ||= USER_AGENT

  client = client.headers(headers)
  client = client.timeout(timeout) unless timeout.nil?
  client
end