17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/admin-cf-plugin/curl.rb', line 17
def curl
mode = input[:mode].upcase
path = input[:path]
body = input[:body]
= {}
input[:headers].each do |h|
k, v = h.split(/\s*:\s*/, 2)
[k.downcase] = v
end
content = ["content-type"]
accept = ["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 => ,
: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
|