documentary 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +16 -2
- data/circle.yml +8 -0
- data/documentary.gemspec +1 -0
- data/lib/documentary/version.rb +1 -1
- data/lib/documentary/view/helpers.rb +28 -3
- data/lib/documentary.rb +1 -0
- data/test/fixtures/kitchen_sink.txt +13 -1
- data/test/integration_test.rb +6 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd84bd9760c92a88f2a23058eef1a64956485505
|
4
|
+
data.tar.gz: d26fb09cef9bb1407466551d81a18a06f37029d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7df9aeb71f78599ababe886fccf93dee670295419949cf8e382d2d41f53be7eca3c43449214a4c3043daee4bc2f8c3d74475d6b779297f0667808c5f2f06349
|
7
|
+
data.tar.gz: 9b23ee2f9dd9d27354207c6526bf799c2446237ecbd47393b55d1529fbdd01569a94cc38db47d5b9e87947ae8724b582ddaf74909a2f5e8a14cfd6ccb2839504
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
documentary (0.
|
4
|
+
documentary (0.2.0)
|
5
5
|
activesupport
|
6
|
+
builder
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -13,6 +14,7 @@ GEM
|
|
13
14
|
minitest (~> 5.1)
|
14
15
|
thread_safe (~> 0.3, >= 0.3.4)
|
15
16
|
tzinfo (~> 1.1)
|
17
|
+
builder (3.2.2)
|
16
18
|
byebug (9.0.5)
|
17
19
|
i18n (0.7.0)
|
18
20
|
json (1.8.3)
|
data/README.md
CHANGED
@@ -123,7 +123,19 @@ Of course not all enpoints are this simple, for `GET` requests especially you ma
|
|
123
123
|
# notes: >
|
124
124
|
# The filter for a specific user to find for example: `filter=Testy`
|
125
125
|
# example_request: >
|
126
|
-
#
|
126
|
+
# query:
|
127
|
+
# - filter: Testy
|
128
|
+
# - page: 1
|
129
|
+
# - count: 3
|
130
|
+
# body:
|
131
|
+
# - content_type: json
|
132
|
+
# payload:
|
133
|
+
# some:
|
134
|
+
# body: attributes
|
135
|
+
# - content_type: xml
|
136
|
+
# payload:
|
137
|
+
# some:
|
138
|
+
# body: attributes
|
127
139
|
# example_response:
|
128
140
|
# page: 1
|
129
141
|
# total_pages: 1
|
@@ -158,6 +170,8 @@ There is a common practice on create and update (`POST` and `PUT`/`PATCH`) to re
|
|
158
170
|
# notes: >
|
159
171
|
# The email of the user
|
160
172
|
# example_request: >
|
161
|
-
#
|
173
|
+
# query:
|
174
|
+
# - name: Testy McTesterson
|
175
|
+
# - email: test@email.com
|
162
176
|
# --- end
|
163
177
|
```
|
data/circle.yml
ADDED
data/documentary.gemspec
CHANGED
data/lib/documentary/version.rb
CHANGED
@@ -78,9 +78,20 @@ module Documentary
|
|
78
78
|
io.puts new_line
|
79
79
|
io.puts '#### Example Request'
|
80
80
|
io.puts new_line
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
example_request = YAML.load(endpoint.example_request)
|
82
|
+
if example_request['query']
|
83
|
+
io.puts start_code_block
|
84
|
+
io.puts "#{endpoint.verb} #{endpoint.endpoint}" << '?' << query_params(example_request['query'])
|
85
|
+
io.puts end_code_block
|
86
|
+
end
|
87
|
+
if example_request['body']
|
88
|
+
io.puts start_code_block
|
89
|
+
example_request['body'].each do |b|
|
90
|
+
io.puts request_payload(b)
|
91
|
+
io.puts new_line
|
92
|
+
end
|
93
|
+
io.puts start_code_block
|
94
|
+
end
|
84
95
|
end
|
85
96
|
if endpoint.example_response
|
86
97
|
io.puts new_line
|
@@ -104,6 +115,20 @@ module Documentary
|
|
104
115
|
"[#{title}](##{title.downcase.gsub(' ', '-')})"
|
105
116
|
end
|
106
117
|
|
118
|
+
def query_params(params)
|
119
|
+
p = params.map {|p| "#{p.keys.first}=#{p[p.keys.first]}"}.join('&')
|
120
|
+
URI.escape(p)
|
121
|
+
end
|
122
|
+
|
123
|
+
def request_payload(payload)
|
124
|
+
case payload['content_type']
|
125
|
+
when 'json'
|
126
|
+
JSON.pretty_generate(payload['payload'])
|
127
|
+
when 'xml'
|
128
|
+
payload['payload'].to_xml
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
107
132
|
def resource_attributes(resource, io)
|
108
133
|
io.puts '#### Attributes'
|
109
134
|
io.puts new_line
|
data/lib/documentary.rb
CHANGED
@@ -48,7 +48,19 @@
|
|
48
48
|
# notes: >
|
49
49
|
# The filter for a specific user to find for example: `filter=Testy`
|
50
50
|
# example_request: >
|
51
|
-
#
|
51
|
+
# query:
|
52
|
+
# - filter: Testy
|
53
|
+
# - page: 1
|
54
|
+
# - count: 3
|
55
|
+
# body:
|
56
|
+
# - content_type: json
|
57
|
+
# payload:
|
58
|
+
# some:
|
59
|
+
# body: attributes
|
60
|
+
# - content_type: xml
|
61
|
+
# payload:
|
62
|
+
# some:
|
63
|
+
# body: attributes
|
52
64
|
# example_response:
|
53
65
|
# page: 1
|
54
66
|
# total_pages: 1
|
data/test/integration_test.rb
CHANGED
@@ -69,10 +69,15 @@ class Documentary::IntegrationTest < MiniTest::Test
|
|
69
69
|
assert_includes generated_docs, 'filter | false | The filter for a specific user to find for example: `filter=Testy`'
|
70
70
|
end
|
71
71
|
|
72
|
-
test 'enpoint example request is generated' do
|
72
|
+
test 'enpoint example request with query params is generated' do
|
73
73
|
assert_includes generated_docs, "```\nGET /some/path?filter=Testy&page=1&count=3\n```"
|
74
74
|
end
|
75
75
|
|
76
|
+
test 'enpoint example request with a JSON body is generated' do
|
77
|
+
assert_includes generated_docs, "{\n \"some\": {\n \"body\": \"attributes\"\n }\n}\n"
|
78
|
+
assert_includes generated_docs, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <some>\n <body>attributes</body>\n </some>\n</hash>\n"
|
79
|
+
end
|
80
|
+
|
76
81
|
test 'enpoint example response is generated' do
|
77
82
|
assert_includes generated_docs, "#### Example Response\n\n```\n"
|
78
83
|
assert_includes generated_docs, "\"page\": 1,\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: documentary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Kennedy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: builder
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,6 +79,7 @@ files:
|
|
65
79
|
- README.md
|
66
80
|
- Rakefile
|
67
81
|
- bin/documentary
|
82
|
+
- circle.yml
|
68
83
|
- documentary.gemspec
|
69
84
|
- lib/default_layout.erb
|
70
85
|
- lib/documentary.rb
|