33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/web_service_documenter.rb', line 33
def to_s
body = ""
url = "http://#{@base_uri}#{@endpoint}"
uri = URI.parse(url)
result = if @method =~ /post/
if @multipart == true
request = Net::HTTP::Post::Multipart.new uri.path, transform_multipart_example_params
Net::HTTP.start(uri.host, uri.port) do |http|
http.request(request)
end
else
Net::HTTP.post_form(uri, @example_params)
end
else
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.path)
request.set_form_data(@example_params)
request = Net::HTTP::Get.new("#{uri.path}?#{request.body}")
http.request(request)
end
if !result.kind_of?(Net::HTTPOK)
raise "Couldn't perform request with url: #{url}"
end
json_response = JSON.parse(result.body)
body << "\n"
body << "==================================================\n"
body << "URL: #{@endpoint} (#{@method.upcase})\n"
body << "\n"
body << "DESCRIPTION: #{@description}" << "\n \n" if @description
body << "Request Params: \n"
body << "\n"
if @params && @params.any?
@params.each do |key, value|
body << " #{key} \n"
@params[key].each do |k,v|
body << " #{k}: #{v} \n"
end
end
else
body << " None"
end
body << "\n"
body << "Response: \n"
body << "\n"
body << JSON.pretty_generate(json_response)
body << "\n"
body << "\n"
body
end
|