apipony 0.0.9 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,42 +1,50 @@
1
1
  Apipony::Documentation.define do
2
- config do |c|
3
- c.title = 'API Documentation'
4
- c.base_url = '/api/v1'
2
+ configure do
3
+ title 'API Documentation'
4
+ base_url '/api/v1'
5
5
  end
6
6
 
7
7
  section 'Ponies' do
8
- endpoint 'get', '/ponies' do |e|
9
- e.description = 'Find ponies'
8
+ endpoint :get, '/ponies' do
9
+ description 'List ponies.'
10
10
 
11
11
  request_with do
12
- param :name, example: :applejack, required: true
12
+ headers do
13
+ {
14
+ 'Accept': 'application/json'
15
+ }
16
+ end
17
+
18
+ param :name, required: true, description: 'Name of pony.',
19
+ example: :fluttershy
13
20
  end
14
21
 
15
- response_with 200 do
16
- set :body, {
17
- :name => :applejack,
18
- :kind => :earth,
19
- :sex => :female,
20
- :occupation => :farmer
21
- }
22
+ response_with do
23
+ body do
24
+ [
25
+ {
26
+ name: 'Fluttershy',
27
+ kind: 'Pegasus'
28
+ }
29
+ ]
30
+ end
22
31
  end
23
32
  end
24
33
 
25
- endpoint 'post', '/ponies' do |e|
26
- e.description = 'Create pony'
34
+ endpoint :post, '/ponies' do
35
+ description 'Create new pony.'
27
36
 
28
37
  request_with do
29
- param :name, example: :fluttershy
38
+ param :name, required: true, example: :fluttershy
30
39
  param :kind, example: :pegasus
31
- param :sex, example: :female
32
- param :occupation, example: :caretaker
40
+ param :sex, required: true, example: :female
41
+ param :occupation, example: :caretaker,
42
+ description: 'What this pony do for living.'
33
43
  end
34
-
35
- response_with 200
36
44
  end
37
45
 
38
- endpoint 'put', '/ponies/:id' do |e|
39
- e.description = 'Update pony id'
46
+ endpoint :put, '/ponies/:id' do
47
+ description 'Update pony by id.'
40
48
 
41
49
  request_with do
42
50
  param :name
@@ -46,32 +54,41 @@ Apipony::Documentation.define do
46
54
  end
47
55
  end
48
56
 
49
- endpoint 'delete', '/ponies/:id' do |e|
50
- e.description = 'Delete pony by id'
51
-
52
- response_with 200
57
+ endpoint :delete, '/ponies/:id' do
58
+ description 'Delete pony by id.'
53
59
  end
54
60
  end
55
61
 
56
62
  section 'Places' do
57
- endpoint 'get', '/places' do |e|
58
- e.description = 'Get places'
63
+ endpoint :get, '/places' do
64
+ description 'List places.'
59
65
 
60
- response_with 200 do
61
- set :body, [
62
- {
63
- :id => 1,
64
- :name => :equestria
65
- },
66
- {
67
- :id => 2,
68
- :name => :ponyville
69
- },
66
+ response_with do
67
+ status 200
68
+
69
+ body do
70
+ [
71
+ {
72
+ name: 'Equestria'
73
+ },
74
+ {
75
+ name: 'Ponyville'
76
+ }
77
+ ]
78
+ end
79
+ end
80
+ end
81
+
82
+ endpoint :get, '/places/:id' do
83
+ response_with do
84
+ status 200
85
+
86
+ body do
70
87
  {
71
- :id => 3,
72
- :name => :canterlot
88
+ name: 'Crystal Empire',
89
+ population: 107706
73
90
  }
74
- ]
91
+ end
75
92
  end
76
93
  end
77
94
  end
@@ -10,11 +10,17 @@ module Apipony
10
10
  end
11
11
 
12
12
  def mount_engine
13
- insert_into_file "#{Rails.root}/config/routes.rb", :after => /routes.draw.do\n/ do
14
- %Q{ mount Apipony::Engine => '/apipony'
15
- }
13
+ insert_into_file routes_path, after: /routes.draw.do\n/ do
14
+ %( mount Apipony::Engine => '/apipony'
15
+ )
16
16
  end
17
17
  end
18
+
19
+ private
20
+
21
+ def routes_path
22
+ "#{Rails.root}/config/routes.rb"
23
+ end
18
24
  end
19
25
  end
20
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipony
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Novikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-02 00:00:00.000000000 Z
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: faker
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -189,7 +203,6 @@ files:
189
203
  - app/assets/stylesheets/apipony/application.css
190
204
  - app/assets/stylesheets/apipony/styles.scss
191
205
  - app/controllers/apipony/application_controller.rb
192
- - app/views/apipony/application/_attribute.html.erb
193
206
  - app/views/apipony/application/_footer.html.erb
194
207
  - app/views/apipony/application/_header.html.erb
195
208
  - app/views/apipony/application/_method.html.erb
@@ -200,16 +213,15 @@ files:
200
213
  - app/views/layouts/apipony/application.html.erb
201
214
  - config/routes.rb
202
215
  - lib/apipony.rb
203
- - lib/apipony/base.rb
204
216
  - lib/apipony/documentation.rb
205
217
  - lib/apipony/endpoint.rb
206
218
  - lib/apipony/engine.rb
207
- - lib/apipony/example_response.rb
208
219
  - lib/apipony/parameter.rb
209
220
  - lib/apipony/request.rb
210
221
  - lib/apipony/response.rb
211
- - lib/apipony/response_attribute.rb
212
222
  - lib/apipony/section.rb
223
+ - lib/apipony/shared/description.rb
224
+ - lib/apipony/shared/headers.rb
213
225
  - lib/apipony/version.rb
214
226
  - lib/generators/apipony/install/templates/initializer.rb
215
227
  - lib/generators/apipony/install_generator.rb
@@ -228,12 +240,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
240
  version: '0'
229
241
  required_rubygems_version: !ruby/object:Gem::Requirement
230
242
  requirements:
231
- - - ">="
243
+ - - ">"
232
244
  - !ruby/object:Gem::Version
233
- version: '0'
245
+ version: 1.3.1
234
246
  requirements: []
235
247
  rubyforge_project:
236
- rubygems_version: 2.4.8
248
+ rubygems_version: 2.6.4
237
249
  signing_key:
238
250
  specification_version: 4
239
251
  summary: Easy Rails API documentation.
@@ -1,42 +0,0 @@
1
- <li class="attribute-container">
2
- <div class="attribute">
3
- <div class="attribute-name name">
4
- <%= attribute.name %>
5
- </div>
6
-
7
- <div class="attribute-type type">
8
- <% if attribute.is_subtype? %>
9
- <%= link_to root_path(:anchor => "subtype-#{attribute.type}") do %>
10
- <%= attribute.type %>
11
- <% end %>
12
- <% else %>
13
- <%= attribute.type %>
14
- <% end %>
15
- </div>
16
-
17
- <% if attribute.description %>
18
- <div class="attribute-description"><%= attribute.description %></div>
19
- <% end %>
20
- </div>
21
-
22
- <% if attribute.is_enum? %>
23
- <ul class="attribute-enum-list">
24
- <div class="title">Possible values</div>
25
- <% attribute.choices.each do |choice| %>
26
- <li class="attribute-enum-member">
27
- <div class="attribute-enum-member-name"><%= choice.name %></div>
28
- <div class="attribute-enum-member-description"><%= choice.description %></div>
29
- </li>
30
- <% end %>
31
- </ul>
32
- <% end %>
33
-
34
- <% if attribute.is_object? %>
35
- <ul class="attribute-object-list">
36
- <div class="title">Child attributes</div>
37
- <%= render partial: "attribute",
38
- collection: attribute.attributes,
39
- as: :attribute %>
40
- </ul>
41
- <% end %>
42
- </li>
data/lib/apipony/base.rb DELETED
@@ -1,7 +0,0 @@
1
- class Apipony::Base
2
- private
3
-
4
- def set(variable, value)
5
- instance_variable_set("@#{ variable }", value)
6
- end
7
- end
@@ -1,9 +0,0 @@
1
- ##
2
- # Display an example response to help with understanding of the API.
3
- class Apipony::ExampleResponse < Apipony::Base
4
- attr_accessor :headers, :body
5
- def initialize(&block)
6
- instance_eval(&block) if block_given?
7
- end
8
-
9
- end
@@ -1,130 +0,0 @@
1
- ##
2
- # A class used to describe an attribute in a response.
3
- class Apipony::ResponseAttribute
4
- @type_definitions = {}
5
- ##
6
- # Allow a common subobject definition for code reuse.
7
- # Probably use the `subtype` method in the `subtype` method of the DSL
8
- # `define` DSL instead.
9
- def self.define_type(name, type)
10
- @type_definitions[name] = type
11
- end
12
-
13
- ##
14
- # Get a list of predefined subtypes.
15
- # Probably use the `
16
- def self.defined_subtypes
17
- @type_definitions
18
- end
19
- ##
20
- # Get a subtype with the given name.
21
- def self.get_defined(name)
22
- @type_definitions[name]
23
- end
24
-
25
- attr_accessor :name, :type, :description, :attributes, :choices
26
- def initialize(name,
27
- type: :string,
28
- description: "",
29
- array: false,
30
- example: nil,
31
- &block)
32
- @name = name
33
- @description = description
34
- @type = type
35
- @array = array
36
- @example = example
37
- if block_given?
38
- instance_eval(&block)
39
- ## This attribute is of a predefined subtype
40
- elsif (subtype = self.class.get_defined(@type))
41
- @attributes = subtype.attributes
42
- # If the subtype is an array, this is also an array
43
- @array = subtype.is_array? unless @array
44
- @is_subtype = true
45
- end
46
- end
47
-
48
- ##
49
- # Build an example from this object
50
- def example
51
- sub = nil
52
- if is_object? || is_subtype?
53
- sub = Hash[@attributes.select(&:example).map{|a| [a.name, a.example]}]
54
- elsif is_enum?
55
- sub = choices.first.name
56
- else
57
- sub = @example
58
- end
59
- ##
60
- # If we have an example an are an array
61
- if sub and is_array?
62
- [sub]
63
- else
64
- sub
65
- end
66
- end
67
- ##
68
- # Is this attribute an array?
69
- # Note that marking an attribute as an array does not over-ride the top-level
70
- # type. For example, a definition like:
71
- # attribute :aliases, type: :string, array: true
72
- # denotates an array of strings. Also note that subattributes are not
73
- # over-ridden. This lets you make an array of objects.
74
- # attribute :users, type: :object, array: true do
75
- # attribute :id, type: :integer
76
- # attribute :name, type: :integer
77
- # end
78
- #
79
- def is_array?
80
- !! @array
81
- end
82
-
83
- ##
84
- # See if this attribute is a reference to a predefined subtype.
85
- def is_subtype?
86
- !! @is_subtype
87
- end
88
-
89
- def use_defined(type)
90
- a = self.class.get_defined(name)
91
- raise "Tried to use an undefined subtype" unless a
92
- ##
93
- # Shallow clone so we can alias the name
94
- a = a.clone
95
- a.name = as
96
- add_subattribute a
97
- end
98
-
99
- def attribute(name, **params, &block)
100
- add_subattribute self.class.new(name, **params, &block)
101
- end
102
-
103
- def is_object?
104
- @type == :object
105
- end
106
-
107
- def is_enum?
108
- @type == :enum
109
- end
110
-
111
- def choice(name, **params)
112
- @choices ||= []
113
- @type = :enum
114
- @choices << EnumChoice.new(name, **params)
115
- end
116
-
117
- class EnumChoice
118
- attr_accessor :name, :description
119
- def initialize(name, description: "")
120
- @name = name
121
- @description = description
122
- end
123
- end
124
- private
125
- def add_subattribute atr
126
- @attributes ||= []
127
- @type = :object
128
- @attributes << atr
129
- end
130
- end