Class: CF::UAA::CurlCli
Instance Method Summary
collapse
Methods inherited from CommonCli
#askd, #auth_header, #clientid, #clientname, #clientsecret, #complain, #debug?, #handle_request, #passcode, #scim_common_list, #scim_get_object, #scim_request, #trace?, #update_target_info, #username, #userpwd, #verified_pwd
Methods inherited from Topic
#add_command, #ask, #ask_pwd, commands, define_option, desc, #gripe, #help_col_start, #initialize, #opt_help, #opt_strs, option_defs, #opts, #pp, #print_tree, #say, #say_cmd_helper, #say_command_help, #say_commands, #say_definition, #say_help, #terminal_columns, topic
Constructor Details
This class inherits a constructor from CF::UAA::Topic
Instance Method Details
#make_request(uri, options) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/uaa/cli/curl.rb', line 61
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
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
|
#parse_uri(path) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/uaa/cli/curl.rb', line 41
def parse_uri(path)
uri = URI.parse(path)
unless uri.host
uri = URI.parse("#{Config.target}#{path}")
end
uri
end
|
#print_request(request, uri, data, header) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/uaa/cli/curl.rb', line 49
def print_request(request, uri, data, )
say "#{request} #{uri.to_s}"
say "REQUEST BODY: \"#{data}\"" if data
if
say "REQUEST HEADERS:"
Array().each do |h|
say " #{h}"
end
end
say ""
end
|
#print_response(response) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/uaa/cli/curl.rb', line 79
def print_response(response)
say "#{response.code} #{response.message}"
say "RESPONSE HEADERS:"
response.each_capitalized do |key, value|
say " #{key}: #{value}"
end
say "RESPONSE BODY:"
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
|