class CFAdmin::Curl
Public Instance Methods
curl()
click to toggle source
# File lib/admin/curl.rb, line 17 def curl mode = input[:mode].upcase path = input[:path] body = input[:body] headers = {} input[:headers].each do |h| k, v = h.split(/\s*:\s*/, 2) headers[k.downcase] = v end content = headers["content-type"] accept = headers["accept"] content ||= :json if body accept ||= :json unless %w(DELETE HEAD).include?(mode) req, res = client.base.rest_client.request( mode, remove_leading_slash(path), :headers => headers, :accept => accept, :payload => body, :content => body && content) body = res[:body] type = res[:headers]["content-type"] if type && type.include?("application/json") json = MultiJson.load(body) puts MultiJson.dump(json, :pretty => true) else puts body end end
precondition()
click to toggle source
# File lib/admin/curl.rb, line 7 def precondition check_target end
remove_leading_slash(path)
click to toggle source
# File lib/admin/curl.rb, line 55 def remove_leading_slash(path) path.sub(%r{^/}, '') end