Class: Chef::REST::RESTRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/rest/rest_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, req_body, base_headers = {}) ⇒ RESTRequest

Returns a new instance of RESTRequest.



33
34
35
36
37
38
39
40
# File 'lib/chef/rest/rest_request.rb', line 33

def initialize(method, url, req_body, base_headers={})
  @method, @url = method, url
  @request_body = nil
  @cookies = CookieJar.instance
  configure_http_client
  build_headers(base_headers)
  configure_http_request(req_body)
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



31
32
33
# File 'lib/chef/rest/rest_request.rb', line 31

def headers
  @headers
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



31
32
33
# File 'lib/chef/rest/rest_request.rb', line 31

def http_client
  @http_client
end

#http_requestObject (readonly)

Returns the value of attribute http_request.



31
32
33
# File 'lib/chef/rest/rest_request.rb', line 31

def http_request
  @http_request
end

#methodObject (readonly)

Returns the value of attribute method.



31
32
33
# File 'lib/chef/rest/rest_request.rb', line 31

def method
  @method
end

#urlObject (readonly)

Returns the value of attribute url.



31
32
33
# File 'lib/chef/rest/rest_request.rb', line 31

def url
  @url
end

Instance Method Details

#callObject



58
59
60
61
62
63
64
65
66
# File 'lib/chef/rest/rest_request.rb', line 58

def call
  hide_net_http_bug do
    http_client.request(http_request) do |response|
      store_cookie(response)
      yield response if block_given?
      response
    end
  end
end

#configObject



68
69
70
# File 'lib/chef/rest/rest_request.rb', line 68

def config
  Chef::Config
end

#hostObject



42
43
44
# File 'lib/chef/rest/rest_request.rb', line 42

def host
  @url.host
end

#pathObject



54
55
56
# File 'lib/chef/rest/rest_request.rb', line 54

def path
  @url.path.empty? ? "/" : @url.path
end

#portObject



46
47
48
# File 'lib/chef/rest/rest_request.rb', line 46

def port
  @url.port
end

#queryObject



50
51
52
# File 'lib/chef/rest/rest_request.rb', line 50

def query
  @url.query
end