web_service_documenter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/web_service_documenter +4 -0
- data/lib/web_service_documenter.rb +108 -0
- metadata +71 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'cgi'
|
6
|
+
|
7
|
+
class WebServiceDocumenter
|
8
|
+
class Service
|
9
|
+
def initialize(base_uri, options)
|
10
|
+
@base_uri = base_uri
|
11
|
+
@endpoint = options["endpoint"]
|
12
|
+
@params = options["params"]
|
13
|
+
@method = (options["method"] || "get").downcase
|
14
|
+
@example_params = create_example_params
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
body = ""
|
19
|
+
|
20
|
+
url = "http://#{@base_uri}#{@endpoint}"
|
21
|
+
uri = URI.parse(url)
|
22
|
+
|
23
|
+
result = if @method =~ /post/
|
24
|
+
Net::HTTP.post_form(uri, @example_params)
|
25
|
+
else
|
26
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
27
|
+
request = Net::HTTP::Get.new(uri.path)
|
28
|
+
request.set_form_data(@example_params)
|
29
|
+
|
30
|
+
request = Net::HTTP::Get.new("#{uri.path}?#{request.body}")
|
31
|
+
http.request(request)
|
32
|
+
end
|
33
|
+
|
34
|
+
if !result.kind_of?(Net::HTTPOK)
|
35
|
+
raise "Couldn't perform request with url: #{url}"
|
36
|
+
end
|
37
|
+
|
38
|
+
json_response = JSON.parse(result.body)
|
39
|
+
|
40
|
+
body << "\n"
|
41
|
+
body << "==================================================\n"
|
42
|
+
|
43
|
+
body << "URL: #{@endpoint} (#{@method.upcase})\n"
|
44
|
+
body << "\n"
|
45
|
+
|
46
|
+
body << "Request Params: \n"
|
47
|
+
body << "\n"
|
48
|
+
|
49
|
+
if @params && @params.any?
|
50
|
+
@params.each do |key, value|
|
51
|
+
body << " #{key} \n"
|
52
|
+
|
53
|
+
@params[key].each do |k,v|
|
54
|
+
body << " #{k}: #{v} \n"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
body << " None"
|
59
|
+
end
|
60
|
+
|
61
|
+
body << "\n"
|
62
|
+
body << "Response: \n"
|
63
|
+
body << "\n"
|
64
|
+
body << JSON.pretty_generate(json_response)
|
65
|
+
body << "\n"
|
66
|
+
body << "\n"
|
67
|
+
body
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def create_example_params
|
73
|
+
hash = {}
|
74
|
+
|
75
|
+
@params.each do |key, value|
|
76
|
+
hash[key] = value["example_value"]
|
77
|
+
end
|
78
|
+
|
79
|
+
hash
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.generate(path_to_web_services)
|
84
|
+
new.generate(path_to_web_services)
|
85
|
+
end
|
86
|
+
|
87
|
+
def generate(path_to_web_services)
|
88
|
+
@yml_file = YAML.load_file(path_to_web_services)
|
89
|
+
@web_services = @yml_file["web_services"]
|
90
|
+
@base_uri = @yml_file["settings"]["base_uri"]
|
91
|
+
|
92
|
+
curl_services
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def curl_services
|
98
|
+
body = ""
|
99
|
+
|
100
|
+
@web_services.each do |web_service|
|
101
|
+
service = Service.new(@base_uri, web_service)
|
102
|
+
body << service.to_s
|
103
|
+
body << " \n"
|
104
|
+
end
|
105
|
+
|
106
|
+
print body
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: web_service_documenter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Scott Taylor
|
14
|
+
- Stephen Schor
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-06-10 00:00:00 -04:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description:
|
24
|
+
email:
|
25
|
+
- scott@railsnewbie.com
|
26
|
+
- beholdthepanda@gmail.com
|
27
|
+
executables:
|
28
|
+
- web_service_documenter
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- bin/web_service_documenter
|
35
|
+
- lib/web_service_documenter.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: https://github.com/eastmedia/web_services_documenter
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: nowarning
|
66
|
+
rubygems_version: 1.3.7
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Deploy with masculine confidence
|
70
|
+
test_files: []
|
71
|
+
|