Class: Pigeon::Http::Request

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

Constant Summary collapse

VALID_PARAMETERS =
%w[headers query body form auth timeout open_timeout ssl_timeout read_timeout max_redirects ssl_verify]
DEFAULT_HEADERS =
{ 'User-Agent' => 'HTTP Client API/1.0' }
VALID_VERBS =
[GET, HEAD, PUT, POST, DELETE, OPTIONS, TRACE]
VALID_SSL_VERIFICATIONS =
[SSL_VERIFY_NONE, SSL_VERIFY_PEER]

Instance Method Summary collapse

Constructor Details

#initialize(verb, uri, args = {}) ⇒ Request

Returns a new instance of Request.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pigeon/http.rb', line 25

def initialize verb, uri, args = {}
  args.each do |k, v|
    raise Error::Argument, "unknown argument #{k}" unless VALID_PARAMETERS.include?(k.to_s)
  end

  uri       = parse_uri!(uri)
  @delegate = create_request_delegate(verb, uri, args)

  # set timeout
  @open_timeout = args[:open_timeout] if args[:open_timeout]
  @read_timeout = args[:read_timeout] if args[:read_timeout]
  @ssl_timeout  = args[:ssl_timeout]  if args[:ssl_timeout]
  @ssl_verify   = args.fetch(:ssl_verify, SSL_VERIFY_PEER)

  # handle basic auth
  if (auth = args[:auth])
    @delegate.basic_auth(auth.fetch(:username), auth.fetch(:password))
  end

  if uri.user && uri.password
    @delegate.basic_auth(uri.user, uri.password)
  end
end

Instance Method Details

#executeObject



49
50
51
52
# File 'lib/pigeon/http.rb', line 49

def execute
  response = request!(uri, @delegate)
  Response.new(response, uri)
end