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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f25bb931fb9ce91753bde54f114a19362fbe8c46
4
- data.tar.gz: 50e7f9a59d248706bb4d6267da0d76d06f3d0931
3
+ metadata.gz: cd84bd9760c92a88f2a23058eef1a64956485505
4
+ data.tar.gz: d26fb09cef9bb1407466551d81a18a06f37029d4
5
5
  SHA512:
6
- metadata.gz: 82a11e37442205e9b68dd19c769768b499ba4f5248ef613a0eb1ad56d06463609d5d5e7b3a459a0292ab66475292cf79b52c4aa4b5dc9ffd35ee1068cb6cbb93
7
- data.tar.gz: 799ad9bdff0459e89d134597cdb60f553be337a6c5544581c0a11c2cd8bce704b57cb8332ea1231dcea4c41d1251cf400a34222caea8ba579889b9fc906c8693
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.1.2)
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
- # /users?filter=Testy&page=1&count=3
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
- # /users?name=Testy%20McTesterson&email=test%40email.com
173
+ # query:
174
+ # - name: Testy McTesterson
175
+ # - email: test@email.com
162
176
  # --- end
163
177
  ```
data/circle.yml ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ machine:
3
+ ruby:
4
+ version: 2.2.4p230
5
+ test:
6
+ post:
7
+ - bundle exec rake
8
+
data/documentary.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.license = 'MIT'
17
17
 
18
18
  s.add_dependency 'activesupport'
19
+ s.add_dependency 'builder'
19
20
  s.add_development_dependency 'minitest', '~> 5.4.3'
20
21
  s.add_development_dependency 'rake', '~> 10.3.2'
21
22
  end
@@ -1,3 +1,3 @@
1
1
  module Documentary
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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
- io.puts start_code_block
82
- io.puts "#{endpoint.verb} #{endpoint.example_request.strip}"
83
- io.puts end_code_block
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
@@ -12,6 +12,7 @@ module Documentary
12
12
  require 'erb'
13
13
  require 'json'
14
14
  require 'active_support/inflector'
15
+ require 'active_support/core_ext/hash'
15
16
 
16
17
  include View
17
18
 
@@ -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
- # /some/path?filter=Testy&page=1&count=3
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
@@ -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.1.2
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-21 00:00:00.000000000 Z
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