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.



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

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.



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

def headers
  @headers
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



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

def http_client
  @http_client
end

#http_requestObject (readonly)

Returns the value of attribute http_request.



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

def http_request
  @http_request
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#callObject



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

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

#configObject



65
66
67
# File 'lib/chef/rest/rest_request.rb', line 65

def config
  Chef::Config
end

#hostObject



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

def host
  @url.host
end

#pathObject



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

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

#portObject



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

def port
  @url.port
end

#queryObject



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

def query
  @url.query
end