rspec_api_documentation 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,7 @@ module RspecApiDocumentation
27
27
  autoload :HtmlWriter
28
28
  autoload :WurlWriter
29
29
  autoload :JsonWriter
30
+ autoload :JsonIodocsWriter
30
31
  autoload :IndexWriter
31
32
  autoload :CombinedTextWriter
32
33
  autoload :CombinedJsonWriter
@@ -8,12 +8,16 @@ module RspecApiDocumentation
8
8
  f.print example.description
9
9
  f.print example.parameters
10
10
 
11
- example.requests.each do |request, response|
11
+ example.requests.each_with_index do |(request, response), i|
12
12
  f.puts "Request:"
13
13
  f.puts request
14
14
  f.puts
15
15
  f.puts "Response:"
16
16
  f.puts response
17
+
18
+ if i + 1 < example.requests.count
19
+ f.puts
20
+ end
17
21
  end
18
22
 
19
23
  unless rspec_example == index.examples.last
@@ -73,6 +73,7 @@ module RspecApiDocumentation
73
73
 
74
74
  def filename
75
75
  basename = description.downcase.gsub(/\s+/, '_').gsub(/[^a-z_]/, '')
76
+ basename = Digest::MD5.new.update(description).to_s if basename.blank?
76
77
  "#{basename}.html"
77
78
  end
78
79
 
@@ -0,0 +1,107 @@
1
+ module RspecApiDocumentation
2
+ class JsonIodocsWriter
3
+ attr_accessor :index, :configuration, :api_key
4
+ delegate :docs_dir, :to => :configuration
5
+
6
+ def initialize(index, configuration)
7
+ self.index = index
8
+ self.configuration = configuration
9
+ self.api_key = configuration.api_name.parameterize
10
+ end
11
+
12
+ def self.write(index, configuration)
13
+ writer = new(index, configuration)
14
+ writer.write
15
+ end
16
+
17
+ def write
18
+ File.open(docs_dir.join("apiconfig.json"), "w+") do |file|
19
+ file.write ApiConfig.new(configuration).to_json
20
+ end
21
+ File.open(docs_dir.join("#{api_key}.json"), "w+") do |file|
22
+ file.write JsonIndex.new(index, configuration).to_json
23
+ end
24
+ end
25
+ end
26
+
27
+ class JsonIndex
28
+ def initialize(index, configuration)
29
+ @index = index
30
+ @configuration = configuration
31
+ end
32
+
33
+ def sections
34
+ IndexWriter.sections(examples, @configuration)
35
+ end
36
+
37
+ def examples
38
+ @index.examples.map { |example| JsonExample.new(example, @configuration) }
39
+ end
40
+
41
+ def to_json
42
+ sections.inject({:endpoints => []}) do |h, section|
43
+ h[:endpoints].push(
44
+ :name => section[:resource_name],
45
+ :methods => section[:examples].map do |example|
46
+ example.to_json
47
+ end
48
+ )
49
+ h
50
+ end.to_json
51
+ end
52
+ end
53
+
54
+ class JsonExample
55
+ def initialize(example, configuration)
56
+ @example = example
57
+ end
58
+
59
+ def method_missing(method, *args, &block)
60
+ @example.send(method, *args, &block)
61
+ end
62
+
63
+ def parameters
64
+ params = []
65
+ if @example.respond_to?(:parameters)
66
+ @example.parameters.map do |param|
67
+ params << {
68
+ "Name" => param[:name],
69
+ "Description" => param[:description],
70
+ "Default" => "",
71
+ "Required" => param[:required] ? "Y" : "N"
72
+ }
73
+ end
74
+ end
75
+ params
76
+ end
77
+
78
+ def to_json
79
+ {
80
+ :MethodName => description,
81
+ :Synopsis => explanation,
82
+ :HTTPMethod => http_method,
83
+ :URI => (requests.first[:request_path] rescue ""),
84
+ :RequiresOAuth => "N",
85
+ :parameters => parameters
86
+ }
87
+ end
88
+ end
89
+
90
+ class ApiConfig
91
+ def initialize(configuration)
92
+ @configuration = configuration
93
+ @api_key = configuration.api_name.parameterize
94
+ end
95
+
96
+ def to_json
97
+ {
98
+ @api_key.to_sym => {
99
+ :name => @configuration.api_name,
100
+ :protocol => "http",
101
+ :publicPath => "",
102
+ :baseURL => @configuration.curl_host
103
+ }
104
+ }.to_json
105
+ end
106
+ end
107
+ end
@@ -2,6 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>{{resource_name}} API</title>
5
+ <meta charset="utf-8">
5
6
  <link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/bootstrap.css"/>
6
7
  <link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/codemirror.css"/>
7
8
  <link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/application.css"/>
@@ -2,6 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>{{ api_name }}</title>
5
+ <meta charset="utf-8">
5
6
  <link rel="stylesheet" href="{{ url_prefix }}/assets/stylesheets/bootstrap.css"/>
6
7
  </head>
7
8
  <body>
@@ -1,6 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <head>
3
3
  <title>{{resource_name}} API</title>
4
+ <meta charset="utf-8">
4
5
  <link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/bootstrap.css"/>
5
6
  <link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/codemirror.css"/>
6
7
  <link rel="stylesheet" href="{{url_prefix}}/assets/stylesheets/application.css"/>
@@ -2,6 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>{{ api_name }}</title>
5
+ <meta charset="utf-8">
5
6
  <link rel="stylesheet" href="{{ url_prefix }}/assets/stylesheets/bootstrap.css"/>
6
7
  </head>
7
8
  <body>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_api_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-03 00:00:00.000000000Z
14
+ date: 2012-08-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
18
- requirement: &70135105134860 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: 2.6.0
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70135105134860
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: 2.6.0
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: activesupport
29
- requirement: &70135105133960 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ! '>='
@@ -34,10 +39,15 @@ dependencies:
34
39
  version: 3.0.0
35
40
  type: :runtime
36
41
  prerelease: false
37
- version_requirements: *70135105133960
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: i18n
40
- requirement: &70135105132820 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ! '>='
@@ -45,10 +55,15 @@ dependencies:
45
55
  version: 0.1.0
46
56
  type: :runtime
47
57
  prerelease: false
48
- version_requirements: *70135105132820
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 0.1.0
49
64
  - !ruby/object:Gem::Dependency
50
65
  name: mustache
51
- requirement: &70135105131980 !ruby/object:Gem::Requirement
66
+ requirement: !ruby/object:Gem::Requirement
52
67
  none: false
53
68
  requirements:
54
69
  - - ! '>='
@@ -56,10 +71,15 @@ dependencies:
56
71
  version: 0.99.4
57
72
  type: :runtime
58
73
  prerelease: false
59
- version_requirements: *70135105131980
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: 0.99.4
60
80
  - !ruby/object:Gem::Dependency
61
81
  name: webmock
62
- requirement: &70135105130500 !ruby/object:Gem::Requirement
82
+ requirement: !ruby/object:Gem::Requirement
63
83
  none: false
64
84
  requirements:
65
85
  - - ! '>='
@@ -67,10 +87,15 @@ dependencies:
67
87
  version: 1.7.0
68
88
  type: :runtime
69
89
  prerelease: false
70
- version_requirements: *70135105130500
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: 1.7.0
71
96
  - !ruby/object:Gem::Dependency
72
97
  name: json
73
- requirement: &70135105129420 !ruby/object:Gem::Requirement
98
+ requirement: !ruby/object:Gem::Requirement
74
99
  none: false
75
100
  requirements:
76
101
  - - ! '>='
@@ -78,10 +103,15 @@ dependencies:
78
103
  version: 1.4.6
79
104
  type: :runtime
80
105
  prerelease: false
81
- version_requirements: *70135105129420
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: 1.4.6
82
112
  - !ruby/object:Gem::Dependency
83
113
  name: fakefs
84
- requirement: &70135105128660 !ruby/object:Gem::Requirement
114
+ requirement: !ruby/object:Gem::Requirement
85
115
  none: false
86
116
  requirements:
87
117
  - - ! '>='
@@ -89,10 +119,15 @@ dependencies:
89
119
  version: '0'
90
120
  type: :development
91
121
  prerelease: false
92
- version_requirements: *70135105128660
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
93
128
  - !ruby/object:Gem::Dependency
94
129
  name: sinatra
95
- requirement: &70135105127860 !ruby/object:Gem::Requirement
130
+ requirement: !ruby/object:Gem::Requirement
96
131
  none: false
97
132
  requirements:
98
133
  - - ! '>='
@@ -100,10 +135,15 @@ dependencies:
100
135
  version: '0'
101
136
  type: :development
102
137
  prerelease: false
103
- version_requirements: *70135105127860
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
104
144
  - !ruby/object:Gem::Dependency
105
145
  name: aruba
106
- requirement: &70135105115500 !ruby/object:Gem::Requirement
146
+ requirement: !ruby/object:Gem::Requirement
107
147
  none: false
108
148
  requirements:
109
149
  - - ! '>='
@@ -111,10 +151,15 @@ dependencies:
111
151
  version: '0'
112
152
  type: :development
113
153
  prerelease: false
114
- version_requirements: *70135105115500
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
115
160
  - !ruby/object:Gem::Dependency
116
161
  name: capybara
117
- requirement: &70135105114560 !ruby/object:Gem::Requirement
162
+ requirement: !ruby/object:Gem::Requirement
118
163
  none: false
119
164
  requirements:
120
165
  - - ! '>='
@@ -122,10 +167,15 @@ dependencies:
122
167
  version: '0'
123
168
  type: :development
124
169
  prerelease: false
125
- version_requirements: *70135105114560
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
126
176
  - !ruby/object:Gem::Dependency
127
177
  name: rake
128
- requirement: &70135105112420 !ruby/object:Gem::Requirement
178
+ requirement: !ruby/object:Gem::Requirement
129
179
  none: false
130
180
  requirements:
131
181
  - - ! '>='
@@ -133,10 +183,15 @@ dependencies:
133
183
  version: '0'
134
184
  type: :development
135
185
  prerelease: false
136
- version_requirements: *70135105112420
186
+ version_requirements: !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
137
192
  - !ruby/object:Gem::Dependency
138
193
  name: rack-test
139
- requirement: &70135105111420 !ruby/object:Gem::Requirement
194
+ requirement: !ruby/object:Gem::Requirement
140
195
  none: false
141
196
  requirements:
142
197
  - - ! '>='
@@ -144,10 +199,15 @@ dependencies:
144
199
  version: 0.5.5
145
200
  type: :development
146
201
  prerelease: false
147
- version_requirements: *70135105111420
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: 0.5.5
148
208
  - !ruby/object:Gem::Dependency
149
209
  name: rack-oauth2
150
- requirement: &70135105110060 !ruby/object:Gem::Requirement
210
+ requirement: !ruby/object:Gem::Requirement
151
211
  none: false
152
212
  requirements:
153
213
  - - ! '>='
@@ -155,7 +215,12 @@ dependencies:
155
215
  version: 0.14.4
156
216
  type: :development
157
217
  prerelease: false
158
- version_requirements: *70135105110060
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ! '>='
222
+ - !ruby/object:Gem::Version
223
+ version: 0.14.4
159
224
  description: Generate API docs from your test suite
160
225
  email:
161
226
  - chris@smartlogicsolutions.com
@@ -181,6 +246,7 @@ files:
181
246
  - lib/rspec_api_documentation/html_writer.rb
182
247
  - lib/rspec_api_documentation/index.rb
183
248
  - lib/rspec_api_documentation/index_writer.rb
249
+ - lib/rspec_api_documentation/json_iodocs_writer.rb
184
250
  - lib/rspec_api_documentation/json_writer.rb
185
251
  - lib/rspec_api_documentation/oauth2_mac_client.rb
186
252
  - lib/rspec_api_documentation/rack_test_client.rb
@@ -230,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
296
  version: 1.3.6
231
297
  requirements: []
232
298
  rubyforge_project:
233
- rubygems_version: 1.8.10
299
+ rubygems_version: 1.8.24
234
300
  signing_key:
235
301
  specification_version: 3
236
302
  summary: A double black belt for your docs