class CF::UAA::CurlCli
Public Instance Methods
Source
# File lib/uaa/cli/curl.rb, line 63 def make_request(uri, options) http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == "https" http.use_ssl = true if options[:insecure] http.verify_mode = OpenSSL::SSL::VERIFY_NONE elsif options[:cacert] http.ca_file = File.expand_path(options[:cacert]) http.verify_mode = OpenSSL::SSL::VERIFY_PEER end end request_class = Net::HTTP.const_get("#{options[:request][0]}#{options[:request][1..-1].downcase}") req = request_class.new(uri.request_uri) req["Authorization"] = "Bearer #{Config.value(:access_token)}" Array(options[:header]).each do |h| key, value = h.split(":") req[key] = value end http.request(req, options[:data]) end
Source
# File lib/uaa/cli/curl.rb, line 43 def parse_uri(path) uri = URI.parse(path) unless uri.host uri = URI.parse("#{Config.target}#{path}") end uri end
Source
# File lib/uaa/cli/curl.rb, line 51 def print_request(request, uri, data, header, bodyonly) say_it("#{request} #{uri.to_s}", bodyonly) say_it("REQUEST BODY: \"#{data}\"", bodyonly) if data if header say_it("REQUEST HEADERS:", bodyonly) Array(header).each do |h| say_it(" #{h}", bodyonly) end end say_it("", bodyonly) end
Source
# File lib/uaa/cli/curl.rb, line 84 def print_response(response, bodyonly) say_it("#{response.code} #{response.message}", bodyonly) say_it("RESPONSE HEADERS:", bodyonly) response.each_capitalized do |key, value| say_it(" #{key}: #{value}", bodyonly) end say_it("RESPONSE BODY:", bodyonly) if !response['Content-Type'].nil? && response['Content-Type'].include?('application/json') parsed = JSON.parse(response.body) formatted = JSON.pretty_generate(parsed) say(formatted) else say(response.body) end end
Source
# File lib/uaa/cli/curl.rb, line 101 def say_it(text, bodyonly) if !bodyonly say text end end