lib/chef-api/connection.rb in chef-api-0.2.1 vs lib/chef-api/connection.rb in chef-api-0.3.0
- old
+ new
@@ -35,18 +35,20 @@
end
include Logify
include ChefAPI::Configurable
- proxy :clients, 'Resource::Client'
- proxy :cookbooks, 'Resource::Cookbook'
- proxy :data_bags, 'Resource::DataBag'
- proxy :environments, 'Resource::Environment'
- proxy :nodes, 'Resource::Node'
- proxy :principals, 'Resource::Principal'
- proxy :roles, 'Resource::Role'
- proxy :users, 'Resource::User'
+ proxy :clients, 'Resource::Client'
+ proxy :cookbooks, 'Resource::Cookbook'
+ proxy :data_bags, 'Resource::DataBag'
+ proxy :environments, 'Resource::Environment'
+ proxy :nodes, 'Resource::Node'
+ proxy :partial_search, 'Resource::PartialSearch'
+ proxy :principals, 'Resource::Principal'
+ proxy :roles, 'Resource::Role'
+ proxy :search, 'Resource::Search'
+ proxy :users, 'Resource::User'
#
# Create a new ChefAPI Connection with the given options. Any options
# given take precedence over the default options.
#
@@ -108,42 +110,46 @@
# Make a HTTP POST request
#
# @param path (see Connection#request)
# @param [String, #read] data
# the body to use for the request
+ # @param [Hash] params
+ # the list of query params
#
# @raise (see Connection#request)
# @return (see Connection#request)
#
- def post(path, data)
- request(:post, path, data)
+ def post(path, data, params = {})
+ request(:post, path, data, params)
end
#
# Make a HTTP PUT request
#
# @param path (see Connection#request)
# @param data (see Connection#post)
+ # @param params (see Connection#post)
#
# @raise (see Connection#request)
# @return (see Connection#request)
#
- def put(path, data)
- request(:put, path, data)
+ def put(path, data, params = {})
+ request(:put, path, data, params)
end
#
# Make a HTTP PATCH request
#
# @param path (see Connection#request)
# @param data (see Connection#post)
+ # @param params (see Connection#post)
#
# @raise (see Connection#request)
# @return (see Connection#request)
#
- def patch(path, data)
- request(:patch, path, data)
+ def patch(path, data, params = {})
+ request(:patch, path, data, params)
end
#
# Make a HTTP DELETE request
#
@@ -170,20 +176,26 @@
# @param [String] path
# the absolute or relative path from {Defaults.endpoint} to make the
# request against
# @param [#read, Hash, nil] data
# the data to use (varies based on the +verb+)
+ # @param [Hash] params
+ # the params to use for :patch, :post, :put
#
# @return [String, Hash]
# the response body
#
- def request(verb, path, data = {})
+ def request(verb, path, data = {}, params = {})
log.info "#{verb.to_s.upcase} #{path}..."
log.debug "Chef flavor: #{flavor.inspect}"
# Build the URI and request object from the given information
- uri = build_uri(verb, path, data)
+ if [:delete, :get].include?(verb)
+ uri = build_uri(verb, path, data)
+ else
+ uri = build_uri(verb, path, params)
+ end
request = class_for_request(verb).new(uri.request_uri)
# Add request headers
add_request_headers(request)
@@ -276,16 +288,14 @@
#
def build_uri(verb, path, params = {})
log.info "Building URI..."
# Add any query string parameters
- if [:delete, :get].include?(verb)
- if querystring = to_query_string(params)
- log.debug "Detected verb deserves a querystring"
- log.debug "Building querystring using #{params.inspect}"
- log.debug "Compiled querystring is #{querystring.inspect}"
- path = [path, querystring].compact.join('?')
- end
+ if querystring = to_query_string(params)
+ log.debug "Detected verb deserves a querystring"
+ log.debug "Building querystring using #{params.inspect}"
+ log.debug "Compiled querystring is #{querystring.inspect}"
+ path = [path, querystring].compact.join('?')
end
# Parse the URI
uri = URI.parse(path)