haveapi 0.13.2 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/haveapi.gemspec +4 -4
- data/lib/haveapi/action.rb +1 -0
- data/lib/haveapi/resource.rb +7 -8
- data/lib/haveapi/server.rb +24 -0
- data/lib/haveapi/version.rb +1 -1
- data/lib/haveapi/views/version_page/auth_body.erb +48 -0
- data/lib/haveapi/views/version_page/client_auth.erb +2 -0
- data/lib/haveapi/views/version_page/client_example.erb +11 -0
- data/lib/haveapi/views/version_page/client_init.erb +2 -0
- data/lib/haveapi/views/version_page/resource_body.erb +163 -0
- data/lib/haveapi/views/version_page.erb +11 -260
- data/lib/haveapi/views/version_sidebar/auth_nav.erb +20 -0
- data/lib/haveapi/views/version_sidebar/resource_nav.erb +21 -0
- data/lib/haveapi/views/version_sidebar.erb +9 -38
- metadata +22 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05bae78d58ccbb9544d69219d3b34f1db107fc16931cbf0714d652ab8efb05f8
|
4
|
+
data.tar.gz: db18c21a2d73446645d9eba73b8fec50f209a893733c45b69c7d89a33dc96e83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69549de1aafe12d346343e1061c5c1513a56cb9d9b7f4f6452afb87d78764febb4a378805c69f55f9bd32db47e73b0b3680a4077bb055b295cc2b64db6935794
|
7
|
+
data.tar.gz: ed988016903b8d341118c42986e2786bd34609109dcbba31fde6097c9dd42e2370731503ee25498252cfe66b35dc0cd9360b67550e33830f7a33c3bf8d447676
|
data/haveapi.gemspec
CHANGED
@@ -17,12 +17,12 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_runtime_dependency 'require_all', '~> 2.0.0'
|
18
18
|
s.add_runtime_dependency 'json'
|
19
19
|
s.add_runtime_dependency 'activesupport', '>= 4.0'
|
20
|
-
s.add_runtime_dependency 'sinatra', '~> 2.0
|
21
|
-
s.add_runtime_dependency 'tilt', '~> 2.0.
|
22
|
-
s.add_runtime_dependency 'redcarpet', '~> 3.
|
20
|
+
s.add_runtime_dependency 'sinatra', '~> 2.1.0'
|
21
|
+
s.add_runtime_dependency 'tilt', '~> 2.0.10'
|
22
|
+
s.add_runtime_dependency 'redcarpet', '~> 3.5'
|
23
23
|
s.add_runtime_dependency 'rake'
|
24
24
|
s.add_runtime_dependency 'github-markdown'
|
25
25
|
s.add_runtime_dependency 'nesty', '~> 1.0'
|
26
|
-
s.add_runtime_dependency 'haveapi-client', '~> 0.
|
26
|
+
s.add_runtime_dependency 'haveapi-client', '~> 0.14.2'
|
27
27
|
s.add_runtime_dependency 'mail'
|
28
28
|
end
|
data/lib/haveapi/action.rb
CHANGED
data/lib/haveapi/resource.rb
CHANGED
@@ -14,6 +14,11 @@ module HaveAPI
|
|
14
14
|
subclass.instance_variable_set(:@obj_type, obj_type)
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.action_defined(klass)
|
18
|
+
@actions ||= []
|
19
|
+
@actions << klass
|
20
|
+
end
|
21
|
+
|
17
22
|
def self.params(name, &block)
|
18
23
|
if block
|
19
24
|
@params ||= {}
|
@@ -23,14 +28,8 @@ module HaveAPI
|
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
|
-
def self.actions
|
27
|
-
|
28
|
-
obj = const_get(c)
|
29
|
-
|
30
|
-
if obj.respond_to?(:obj_type) && obj.obj_type == :action
|
31
|
-
yield obj
|
32
|
-
end
|
33
|
-
end
|
31
|
+
def self.actions(&block)
|
32
|
+
(@actions || []).each(&block)
|
34
33
|
end
|
35
34
|
|
36
35
|
def self.resources
|
data/lib/haveapi/server.rb
CHANGED
@@ -121,6 +121,29 @@ module HaveAPI
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
module DocHelpers
|
125
|
+
def format_param_type(param)
|
126
|
+
return param[:type] if param[:type] != 'Resource'
|
127
|
+
"<a href=\"#root-#{param[:resource].join('-')}-show\">#{param[:type]}</a>"
|
128
|
+
end
|
129
|
+
|
130
|
+
def format_validators(validators)
|
131
|
+
ret = ''
|
132
|
+
return ret if validators.nil?
|
133
|
+
|
134
|
+
validators.each do |name, opts|
|
135
|
+
ret += "<h5>#{name.to_s.capitalize}</h5>"
|
136
|
+
ret += '<dl>'
|
137
|
+
opts.each do |k, v|
|
138
|
+
ret += "<dt>#{k}</dt><dd>#{v}</dd>"
|
139
|
+
end
|
140
|
+
ret += '</dl>'
|
141
|
+
end
|
142
|
+
|
143
|
+
ret
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
124
147
|
def initialize(module_name = HaveAPI.module_name)
|
125
148
|
@module_name = module_name
|
126
149
|
@allowed_headers = ['Content-Type']
|
@@ -176,6 +199,7 @@ module HaveAPI
|
|
176
199
|
end
|
177
200
|
|
178
201
|
helpers ServerHelpers
|
202
|
+
helpers DocHelpers
|
179
203
|
|
180
204
|
before do
|
181
205
|
@formatter = OutputFormatter.new
|
data/lib/haveapi/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
<h2 id="auth-<%= name %>"><%= name.to_s.humanize %></h2>
|
2
|
+
<hr>
|
3
|
+
|
4
|
+
<p><%= info[:description] %></p>
|
5
|
+
|
6
|
+
<% if name == :token %>
|
7
|
+
<dl>
|
8
|
+
<dt>HTTP header:</dt>
|
9
|
+
<dd><%= info[:http_header] %></dd>
|
10
|
+
<dt>Query parameter:</dt>
|
11
|
+
<dd><%= info[:query_parameter] %></dd>
|
12
|
+
</dl>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<% if info[:resources] %>
|
16
|
+
<h2>Resources</h2>
|
17
|
+
<% sort_hash(info[:resources]).each do |resource, desc| %>
|
18
|
+
<%= erb :"version_page/resource_body", locals: {resource: resource.to_s, info: desc, path: [], prefix: 'root', name: nil} %>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<% baseid = "auth-#{name}" %>
|
23
|
+
<div id="<%= baseid %>-tabbar"></div>
|
24
|
+
|
25
|
+
<div id="<%= baseid %>-examples">
|
26
|
+
<% HaveAPI::ClientExample.clients.each_with_index do |client, i| %>
|
27
|
+
<div id="<%= "#{baseid}-#{i}" %>">
|
28
|
+
<%= erb :"version_page/client_auth", locals: {client: client, method: name, desc: info} %>
|
29
|
+
</div>
|
30
|
+
<% end %>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<script type="text/javascript">
|
34
|
+
nojsTabs({
|
35
|
+
tabs: document.getElementById('<%= "#{baseid}-examples" %>'),
|
36
|
+
titleSelector: 'h4',
|
37
|
+
tabBar: document.getElementById('<%= "#{baseid}-tabbar" %>'),
|
38
|
+
hiddenClass: 'tab-hidden',
|
39
|
+
activeClass: 'active',
|
40
|
+
createElement: function (el) {
|
41
|
+
if (el.tagName == 'UL')
|
42
|
+
el.classList.add('nav', 'nav-tabs');
|
43
|
+
|
44
|
+
else if (el.tagName == 'LI')
|
45
|
+
el.setAttribute('role', 'presentation');
|
46
|
+
}
|
47
|
+
});
|
48
|
+
</script>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<h6><%= client.label %></h6>
|
2
|
+
<% sample = client.new(host, base_url, api_version, r_name, resource, a_name, action) %>
|
3
|
+
<% if sample.respond_to?(:example) %>
|
4
|
+
<pre><code class="<%= client.code %>"><%= sample.example(example) %></code></pre>
|
5
|
+
|
6
|
+
<% else %>
|
7
|
+
<h6>Request</h6>
|
8
|
+
<pre><code class="<%= client.code %>"><%= sample.request(example) %></code></pre>
|
9
|
+
<h6>Response</h6>
|
10
|
+
<pre><code class="<%= client.code %>"><%= sample.response(example) %></code></pre>
|
11
|
+
<% end %>
|
@@ -0,0 +1,163 @@
|
|
1
|
+
<% name ||= resource.humanize %>
|
2
|
+
<% resource_path = path.clone << resource %>
|
3
|
+
<% resource_info = info %>
|
4
|
+
<h2 class="resource" id="<%= "#{prefix}-#{resource}" %>"><%= resource.humanize %></h2>
|
5
|
+
<hr>
|
6
|
+
<div class="resource-body">
|
7
|
+
<p><%= info[:description] %></p>
|
8
|
+
|
9
|
+
<div class="actions">
|
10
|
+
<% sort_hash(info[:actions]).each do |action, info| %>
|
11
|
+
<h3 id="<%= "#{prefix}-#{resource}-#{action}" %>"><%= name %> # <%= action.capitalize %></h3>
|
12
|
+
<div class="action">
|
13
|
+
<dl>
|
14
|
+
<dt>Path:</dt>
|
15
|
+
<dd><%= info[:method] %> <%= info[:path] %></dd>
|
16
|
+
<dt>Description:</dt>
|
17
|
+
<dd><%= info[:description] %></dd>
|
18
|
+
<dt>Authentication required:</dt>
|
19
|
+
<dd><%= info[:auth] ? 'yes' : 'no' %></dd>
|
20
|
+
<dt>Aliases:</dt>
|
21
|
+
<dd><%= info[:aliases].join(', ') %></dd>
|
22
|
+
<dt>Blocking:</dt>
|
23
|
+
<dd><%= info[:blocking] ? 'yes' : 'no' %></dd>
|
24
|
+
</dl>
|
25
|
+
|
26
|
+
<h4>Input parameters</h4>
|
27
|
+
<div class="parameters">
|
28
|
+
<% if info[:input][:parameters].empty? %>
|
29
|
+
<p>No parameters.</p>
|
30
|
+
<% else %>
|
31
|
+
<dl>
|
32
|
+
<dt>Layout:</dt>
|
33
|
+
<dd><%= info[:input][:layout] %></dd>
|
34
|
+
<dt>Namespace:</dt>
|
35
|
+
<dd><%= info[:input][:namespace] %></dd>
|
36
|
+
</dl>
|
37
|
+
|
38
|
+
<table class="table table-striped table-hover table-bordered">
|
39
|
+
<tr>
|
40
|
+
<th>Label</th>
|
41
|
+
<th>Name</th>
|
42
|
+
<th>Required</th>
|
43
|
+
<th>Type</th>
|
44
|
+
<th>Validators</th>
|
45
|
+
<th>Default</th>
|
46
|
+
<th>Description</th>
|
47
|
+
</tr>
|
48
|
+
<% info[:input][:parameters].each do |param, info| %>
|
49
|
+
<tr>
|
50
|
+
<td><%= info[:label] %></td>
|
51
|
+
<td><%= param %></td>
|
52
|
+
<td><%= info[:required] ? 'yes' : 'no' %></td>
|
53
|
+
<td><%= format_param_type(info) %></td>
|
54
|
+
<td><%= format_validators(info[:validators]) %></td>
|
55
|
+
<td><%= info[:default] == :_nil ? '' : info[:default] %></td>
|
56
|
+
<td><%= info[:description] %></td>
|
57
|
+
</tr>
|
58
|
+
<% end %>
|
59
|
+
</table>
|
60
|
+
<% end %>
|
61
|
+
</div>
|
62
|
+
|
63
|
+
<h4>Output parameters</h4>
|
64
|
+
<div class="parameters">
|
65
|
+
<% if info[:output][:parameters].empty? && info[:output][:format].nil? %>
|
66
|
+
<p>No parameters.</p>
|
67
|
+
<% else %>
|
68
|
+
<dl>
|
69
|
+
<dt>Layout:</dt>
|
70
|
+
<dd><%= info[:output][:layout] %></dd>
|
71
|
+
<dt>Namespace:</dt>
|
72
|
+
<dd><%= info[:output][:namespace] %></dd>
|
73
|
+
</dl>
|
74
|
+
|
75
|
+
<table class="table table-striped table-hover table-bordered">
|
76
|
+
<tr>
|
77
|
+
<th>Label</th>
|
78
|
+
<th>Name</th>
|
79
|
+
<th>Type</th>
|
80
|
+
<th>Description</th>
|
81
|
+
</tr>
|
82
|
+
<% info[:output][:parameters].each do |param, info| %>
|
83
|
+
<tr>
|
84
|
+
<td><%= info[:label] %></td>
|
85
|
+
<td><%= param %></td>
|
86
|
+
<td><%= format_param_type(info) %></td>
|
87
|
+
<td><%= info[:description] %></td>
|
88
|
+
</tr>
|
89
|
+
<% end %>
|
90
|
+
</table>
|
91
|
+
<% end %>
|
92
|
+
</div>
|
93
|
+
|
94
|
+
<div class="action-self-description">
|
95
|
+
<h4>Self-description</h4>
|
96
|
+
<pre><code><%= JSON.pretty_generate(info) %></code></pre>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<% unless info[:examples].empty? %>
|
100
|
+
<h4>Examples</h4>
|
101
|
+
<% info[:examples].each_with_index do |example, i| %>
|
102
|
+
<h5><%= example[:title].empty? ? "Example ##{i}" : example[:title] %></h5>
|
103
|
+
<p><%= example[:comment] %></p>
|
104
|
+
|
105
|
+
<% baseid = "example-#{resource_path.join('.')}-#{action}-#{i}" %>
|
106
|
+
<%# placeholder for tabs %>
|
107
|
+
<div id="<%= "#{baseid}-tabbar" %>"></div>
|
108
|
+
|
109
|
+
<div id="<%= "#{baseid}-examples" %>">
|
110
|
+
<% HaveAPI::ClientExample.clients.each_with_index do |client, j| %>
|
111
|
+
<div id="<%= "#{baseid}-#{j}" %>">
|
112
|
+
<%=
|
113
|
+
erb :"version_page/client_example", locals: {
|
114
|
+
client: client,
|
115
|
+
r_name: resource_path,
|
116
|
+
resource: resource_info,
|
117
|
+
a_name: action,
|
118
|
+
action: info,
|
119
|
+
example: example,
|
120
|
+
}
|
121
|
+
%>
|
122
|
+
</div>
|
123
|
+
<% end %>
|
124
|
+
</div>
|
125
|
+
|
126
|
+
<script type="text/javascript">
|
127
|
+
nojsTabs({
|
128
|
+
tabs: document.getElementById('<%= "#{baseid}-examples" %>'),
|
129
|
+
titleSelector: 'h6',
|
130
|
+
tabBar: document.getElementById('<%= "#{baseid}-tabbar" %>'),
|
131
|
+
hiddenClass: 'tab-hidden',
|
132
|
+
activeClass: 'active',
|
133
|
+
createElement: function (el) {
|
134
|
+
if (el.tagName == 'UL')
|
135
|
+
el.classList.add('nav', 'nav-tabs');
|
136
|
+
|
137
|
+
else if (el.tagName == 'LI')
|
138
|
+
el.setAttribute('role', 'presentation');
|
139
|
+
}
|
140
|
+
});
|
141
|
+
</script>
|
142
|
+
<% end %>
|
143
|
+
<% end %>
|
144
|
+
|
145
|
+
</div>
|
146
|
+
<% end %>
|
147
|
+
</div>
|
148
|
+
|
149
|
+
<% unless info[:resources].empty? %>
|
150
|
+
<% sort_hash(info[:resources]).each do |r, i| %>
|
151
|
+
<%=
|
152
|
+
erb :"version_page/resource_body", locals: {
|
153
|
+
resource: r,
|
154
|
+
info: i,
|
155
|
+
path: resource_path,
|
156
|
+
prefix: "#{prefix}-#{resource}",
|
157
|
+
name: "#{name}.#{r.humanize}",
|
158
|
+
}
|
159
|
+
%>
|
160
|
+
<% end %>
|
161
|
+
<% end %>
|
162
|
+
|
163
|
+
</div> <!-- resource -->
|
@@ -1,260 +1,3 @@
|
|
1
|
-
<%
|
2
|
-
def format_param_type(param)
|
3
|
-
return param[:type] if param[:type] != 'Resource'
|
4
|
-
"<a href=\"#root-#{param[:resource].join('-')}-show\">#{param[:type]}</a>"
|
5
|
-
end
|
6
|
-
|
7
|
-
def format_validators(validators)
|
8
|
-
ret = ''
|
9
|
-
return ret if validators.nil?
|
10
|
-
|
11
|
-
validators.each do |name, opts|
|
12
|
-
ret += "<h5>#{name.to_s.capitalize}</h5>"
|
13
|
-
ret += '<dl>'
|
14
|
-
opts.each do |k, v|
|
15
|
-
ret += "<dt>#{k}</dt><dd>#{v}</dd>"
|
16
|
-
end
|
17
|
-
ret += '</dl>'
|
18
|
-
end
|
19
|
-
|
20
|
-
ret
|
21
|
-
end
|
22
|
-
%>
|
23
|
-
|
24
|
-
<% def render_auth_body(name, info) %>
|
25
|
-
<h2 id="auth-<%= name %>"><%= name.to_s.humanize %></h2>
|
26
|
-
<hr>
|
27
|
-
|
28
|
-
<p><%= info[:description] %></p>
|
29
|
-
|
30
|
-
<% if name == :token %>
|
31
|
-
<dl>
|
32
|
-
<dt>HTTP header:</dt>
|
33
|
-
<dd><%= info[:http_header] %></dd>
|
34
|
-
<dt>Query parameter:</dt>
|
35
|
-
<dd><%= info[:query_parameter] %></dd>
|
36
|
-
</dl>
|
37
|
-
<% end %>
|
38
|
-
|
39
|
-
<% if info[:resources] %>
|
40
|
-
<h2>Resources</h2>
|
41
|
-
<% sort_hash(info[:resources]).each do |resource, desc| %>
|
42
|
-
<% render_resource_body(resource.to_s, desc, 'auth') %>
|
43
|
-
<% end %>
|
44
|
-
<% end %>
|
45
|
-
|
46
|
-
<% baseid = "auth-#{name}" %>
|
47
|
-
<div id="<%= baseid %>-tabbar"></div>
|
48
|
-
|
49
|
-
<div id="<%= baseid %>-examples">
|
50
|
-
<% HaveAPI::ClientExample.clients.each_with_index do |client, i| %>
|
51
|
-
<div id="<%= "#{baseid}-#{i}" %>">
|
52
|
-
<% render_client_auth(client, name, info) %>
|
53
|
-
</div>
|
54
|
-
<% end %>
|
55
|
-
</div>
|
56
|
-
|
57
|
-
<script type="text/javascript">
|
58
|
-
nojsTabs({
|
59
|
-
tabs: document.getElementById('<%= "#{baseid}-examples" %>'),
|
60
|
-
titleSelector: 'h4',
|
61
|
-
tabBar: document.getElementById('<%= "#{baseid}-tabbar" %>'),
|
62
|
-
hiddenClass: 'tab-hidden',
|
63
|
-
activeClass: 'active',
|
64
|
-
createElement: function (el) {
|
65
|
-
if (el.tagName == 'UL')
|
66
|
-
el.classList.add('nav', 'nav-tabs');
|
67
|
-
|
68
|
-
else if (el.tagName == 'LI')
|
69
|
-
el.setAttribute('role', 'presentation');
|
70
|
-
}
|
71
|
-
});
|
72
|
-
</script>
|
73
|
-
<% end %>
|
74
|
-
|
75
|
-
<% def render_resource_body(resource, info, path = [], prefix='root', name=nil) %>
|
76
|
-
<% name ||= resource.humanize %>
|
77
|
-
<% resource_path = path.clone << resource %>
|
78
|
-
<% resource_info = info %>
|
79
|
-
<h2 class="resource" id="<%= "#{prefix}-#{resource}" %>"><%= resource.humanize %></h2>
|
80
|
-
<hr>
|
81
|
-
<div class="resource-body">
|
82
|
-
<p><%= info[:description] %></p>
|
83
|
-
|
84
|
-
<div class="actions">
|
85
|
-
<% sort_hash(info[:actions]).each do |action, info| %>
|
86
|
-
<h3 id="<%= "#{prefix}-#{resource}-#{action}" %>"><%= name %> # <%= action.capitalize %></h3>
|
87
|
-
<div class="action">
|
88
|
-
<dl>
|
89
|
-
<dt>Path:</dt>
|
90
|
-
<dd><%= info[:method] %> <%= info[:path] %></dd>
|
91
|
-
<dt>Description:</dt>
|
92
|
-
<dd><%= info[:description] %></dd>
|
93
|
-
<dt>Authentication required:</dt>
|
94
|
-
<dd><%= info[:auth] ? 'yes' : 'no' %></dd>
|
95
|
-
<dt>Aliases:</dt>
|
96
|
-
<dd><%= info[:aliases].join(', ') %></dd>
|
97
|
-
<dt>Blocking:</dt>
|
98
|
-
<dd><%= info[:blocking] ? 'yes' : 'no' %></dd>
|
99
|
-
</dl>
|
100
|
-
|
101
|
-
<h4>Input parameters</h4>
|
102
|
-
<div class="parameters">
|
103
|
-
<% if info[:input][:parameters].empty? %>
|
104
|
-
<p>No parameters.</p>
|
105
|
-
<% else %>
|
106
|
-
<dl>
|
107
|
-
<dt>Layout:</dt>
|
108
|
-
<dd><%= info[:input][:layout] %></dd>
|
109
|
-
<dt>Namespace:</dt>
|
110
|
-
<dd><%= info[:input][:namespace] %></dd>
|
111
|
-
</dl>
|
112
|
-
|
113
|
-
<table class="table table-striped table-hover table-bordered">
|
114
|
-
<tr>
|
115
|
-
<th>Label</th>
|
116
|
-
<th>Name</th>
|
117
|
-
<th>Required</th>
|
118
|
-
<th>Type</th>
|
119
|
-
<th>Validators</th>
|
120
|
-
<th>Default</th>
|
121
|
-
<th>Description</th>
|
122
|
-
</tr>
|
123
|
-
<% info[:input][:parameters].each do |param, info| %>
|
124
|
-
<tr>
|
125
|
-
<td><%= info[:label] %></td>
|
126
|
-
<td><%= param %></td>
|
127
|
-
<td><%= info[:required] ? 'yes' : 'no' %></td>
|
128
|
-
<td><%= format_param_type(info) %></td>
|
129
|
-
<td><%= format_validators(info[:validators]) %></td>
|
130
|
-
<td><%= info[:default] == :_nil ? '' : info[:default] %></td>
|
131
|
-
<td><%= info[:description] %></td>
|
132
|
-
</tr>
|
133
|
-
<% end %>
|
134
|
-
</table>
|
135
|
-
<% end %>
|
136
|
-
</div>
|
137
|
-
|
138
|
-
<h4>Output parameters</h4>
|
139
|
-
<div class="parameters">
|
140
|
-
<% if info[:output][:parameters].empty? && info[:output][:format].nil? %>
|
141
|
-
<p>No parameters.</p>
|
142
|
-
<% else %>
|
143
|
-
<dl>
|
144
|
-
<dt>Layout:</dt>
|
145
|
-
<dd><%= info[:output][:layout] %></dd>
|
146
|
-
<dt>Namespace:</dt>
|
147
|
-
<dd><%= info[:output][:namespace] %></dd>
|
148
|
-
</dl>
|
149
|
-
|
150
|
-
<table class="table table-striped table-hover table-bordered">
|
151
|
-
<tr>
|
152
|
-
<th>Label</th>
|
153
|
-
<th>Name</th>
|
154
|
-
<th>Type</th>
|
155
|
-
<th>Description</th>
|
156
|
-
</tr>
|
157
|
-
<% info[:output][:parameters].each do |param, info| %>
|
158
|
-
<tr>
|
159
|
-
<td><%= info[:label] %></td>
|
160
|
-
<td><%= param %></td>
|
161
|
-
<td><%= format_param_type(info) %></td>
|
162
|
-
<td><%= info[:description] %></td>
|
163
|
-
</tr>
|
164
|
-
<% end %>
|
165
|
-
</table>
|
166
|
-
<% end %>
|
167
|
-
</div>
|
168
|
-
|
169
|
-
<div class="action-self-description">
|
170
|
-
<h4>Self-description</h4>
|
171
|
-
<pre><code><%= JSON.pretty_generate(info) %></code></pre>
|
172
|
-
</div>
|
173
|
-
|
174
|
-
<% unless info[:examples].empty? %>
|
175
|
-
<h4>Examples</h4>
|
176
|
-
<% info[:examples].each_with_index do |example, i| %>
|
177
|
-
<h5><%= example[:title].empty? ? "Example ##{i}" : example[:title] %></h5>
|
178
|
-
<p><%= example[:comment] %></p>
|
179
|
-
|
180
|
-
<% baseid = "example-#{resource_path.join('.')}-#{action}-#{i}" %>
|
181
|
-
<%# placeholder for tabs %>
|
182
|
-
<div id="<%= "#{baseid}-tabbar" %>"></div>
|
183
|
-
|
184
|
-
<div id="<%= "#{baseid}-examples" %>">
|
185
|
-
<% HaveAPI::ClientExample.clients.each_with_index do |client, j| %>
|
186
|
-
<div id="<%= "#{baseid}-#{j}" %>">
|
187
|
-
<%
|
188
|
-
render_client_example(
|
189
|
-
client,
|
190
|
-
resource_path,
|
191
|
-
resource_info,
|
192
|
-
action,
|
193
|
-
info,
|
194
|
-
example
|
195
|
-
)
|
196
|
-
%>
|
197
|
-
</div>
|
198
|
-
<% end %>
|
199
|
-
</div>
|
200
|
-
|
201
|
-
<script type="text/javascript">
|
202
|
-
nojsTabs({
|
203
|
-
tabs: document.getElementById('<%= "#{baseid}-examples" %>'),
|
204
|
-
titleSelector: 'h6',
|
205
|
-
tabBar: document.getElementById('<%= "#{baseid}-tabbar" %>'),
|
206
|
-
hiddenClass: 'tab-hidden',
|
207
|
-
activeClass: 'active',
|
208
|
-
createElement: function (el) {
|
209
|
-
if (el.tagName == 'UL')
|
210
|
-
el.classList.add('nav', 'nav-tabs');
|
211
|
-
|
212
|
-
else if (el.tagName == 'LI')
|
213
|
-
el.setAttribute('role', 'presentation');
|
214
|
-
}
|
215
|
-
});
|
216
|
-
</script>
|
217
|
-
<% end %>
|
218
|
-
<% end %>
|
219
|
-
|
220
|
-
</div>
|
221
|
-
<% end %>
|
222
|
-
</div>
|
223
|
-
|
224
|
-
<% unless info[:resources].empty? %>
|
225
|
-
<% sort_hash(info[:resources]).each do |r, i| %>
|
226
|
-
<% render_resource_body(r, i, resource_path, "#{prefix}-#{resource}", "#{name}.#{r.humanize}") %>
|
227
|
-
<% end %>
|
228
|
-
<% end %>
|
229
|
-
|
230
|
-
</div> <!-- resource -->
|
231
|
-
<% end %>
|
232
|
-
|
233
|
-
<% def render_client_init(client) %>
|
234
|
-
<h4><%= client.label %></h4>
|
235
|
-
<pre><code class="<%= client.code %>"><%= client.init(host, base_url, api_version) %></code></pre>
|
236
|
-
<% end %>
|
237
|
-
|
238
|
-
<% def render_client_auth(client, method, desc) %>
|
239
|
-
<h4><%= client.label %></h4>
|
240
|
-
<pre><code class="<%= client.code %>"><%= client.auth(host, base_url, api_version, method, desc) %></code></pre>
|
241
|
-
<% end %>
|
242
|
-
|
243
|
-
<% def render_client_example(client, r_name, resource, a_name, action, example) %>
|
244
|
-
<h6><%= client.label %></h6>
|
245
|
-
<% sample = client.new(host, base_url, api_version, r_name, resource, a_name, action) %>
|
246
|
-
<% if sample.respond_to?(:example) %>
|
247
|
-
<pre><code class="<%= client.code %>"><%= sample.example(example) %></code></pre>
|
248
|
-
|
249
|
-
<% else %>
|
250
|
-
<h6>Request</h6>
|
251
|
-
<pre><code class="<%= client.code %>"><%= sample.request(example) %></code></pre>
|
252
|
-
<h6>Response</h6>
|
253
|
-
<pre><code class="<%= client.code %>"><%= sample.response(example) %></code></pre>
|
254
|
-
<% end %>
|
255
|
-
<% end %>
|
256
|
-
|
257
|
-
|
258
1
|
<h1 id="api">API v<%= @v %></h1>
|
259
2
|
|
260
3
|
<ol class="breadcrumb">
|
@@ -295,7 +38,7 @@ end
|
|
295
38
|
<div id="init-examples">
|
296
39
|
<% HaveAPI::ClientExample.clients.each_with_index do |client, i| %>
|
297
40
|
<div id="<%= "init-#{i}" %>">
|
298
|
-
|
41
|
+
<%= erb :"version_page/client_init", locals: {client: client} %>
|
299
42
|
</div>
|
300
43
|
<% end %>
|
301
44
|
</div>
|
@@ -319,14 +62,22 @@ nojsTabs({
|
|
319
62
|
|
320
63
|
<h1 id="auth">Authentication methods</h1>
|
321
64
|
<% @help[:authentication].each do |name, info| %>
|
322
|
-
|
65
|
+
<%= erb :"version_page/auth_body", locals: {name: name, info: info} %>
|
323
66
|
<% end %>
|
324
67
|
|
325
68
|
<h1 id="resources">Resources</h1>
|
326
69
|
<p>Follows a list of all resources in this API and their actions.</p>
|
327
70
|
|
328
71
|
<% sort_hash(@help[:resources]).each do |resource, info| %>
|
329
|
-
|
72
|
+
<%=
|
73
|
+
erb :"version_page/resource_body", locals: {
|
74
|
+
resource: resource,
|
75
|
+
info: info,
|
76
|
+
path: [],
|
77
|
+
prefix: 'root',
|
78
|
+
name: nil,
|
79
|
+
}
|
80
|
+
%>
|
330
81
|
<% end %>
|
331
82
|
</div>
|
332
83
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<ul>
|
2
|
+
<% methods.each do |method, info| %>
|
3
|
+
<li>
|
4
|
+
<a href="#auth-<%= method %>"><%= method.to_s.humanize %></a>
|
5
|
+
<% if info[:resources] %>
|
6
|
+
<ul>
|
7
|
+
<% sort_hash(info[:resources]).each do |resource, info| %>
|
8
|
+
<%=
|
9
|
+
erb :"version_sidebar/resource_nav", locals: {
|
10
|
+
resource: resource.to_s,
|
11
|
+
info: info,
|
12
|
+
prefix: "auth-#{method}",
|
13
|
+
}
|
14
|
+
%>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
17
|
+
<% end %>
|
18
|
+
</li>
|
19
|
+
<% end %>
|
20
|
+
</ul>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<li>
|
2
|
+
<a href="#<%= "#{prefix}-#{resource}" %>">.<%= resource.humanize %></a>
|
3
|
+
|
4
|
+
<ul>
|
5
|
+
<% sort_hash(info[:actions]).each do |action, info| %>
|
6
|
+
<li>
|
7
|
+
<a href="#<%= "#{prefix}-#{resource}-#{action}" %>">#<%= action.capitalize %></a>
|
8
|
+
</li>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<% sort_hash(info[:resources]).each do |r, i| %>
|
12
|
+
<%=
|
13
|
+
erb :"version_sidebar/resource_nav", locals: {
|
14
|
+
resource: r,
|
15
|
+
info: i,
|
16
|
+
prefix: "#{prefix}-#{resource}",
|
17
|
+
}
|
18
|
+
%>
|
19
|
+
<% end %>
|
20
|
+
</ul>
|
21
|
+
</li>
|
@@ -1,38 +1,3 @@
|
|
1
|
-
<% def render_auth_nav(methods) %>
|
2
|
-
<ul>
|
3
|
-
<% methods.each do |method, info| %>
|
4
|
-
<li>
|
5
|
-
<a href="#auth-<%= method %>"><%= method.to_s.humanize %></a>
|
6
|
-
<% if info[:resources] %>
|
7
|
-
<ul>
|
8
|
-
<% sort_hash(info[:resources]).each do |resource, info| %>
|
9
|
-
<% render_resource_nav(resource.to_s, info, "auth-#{method}") %>
|
10
|
-
<% end %>
|
11
|
-
</ul>
|
12
|
-
<% end %>
|
13
|
-
</li>
|
14
|
-
<% end %>
|
15
|
-
</ul>
|
16
|
-
<% end %>
|
17
|
-
|
18
|
-
<% def render_resource_nav(resource, info, prefix='root') %>
|
19
|
-
<li>
|
20
|
-
<a href="#<%= "#{prefix}-#{resource}" %>">.<%= resource.humanize %></a>
|
21
|
-
|
22
|
-
<ul>
|
23
|
-
<% sort_hash(info[:actions]).each do |action, info| %>
|
24
|
-
<li>
|
25
|
-
<a href="#<%= "#{prefix}-#{resource}-#{action}" %>">#<%= action.capitalize %></a>
|
26
|
-
</li>
|
27
|
-
<% end %>
|
28
|
-
|
29
|
-
<% sort_hash(info[:resources]).each do |r, i| %>
|
30
|
-
<% render_resource_nav(r, i, "#{prefix}-#{resource}") %>
|
31
|
-
<% end %>
|
32
|
-
</ul>
|
33
|
-
</li>
|
34
|
-
<% end %>
|
35
|
-
|
36
1
|
<h1>Authentication</h1>
|
37
2
|
<p class="authentication">
|
38
3
|
<% if current_user %>
|
@@ -54,11 +19,17 @@
|
|
54
19
|
<li><a href="#api">API v<%= @v %></a></li>
|
55
20
|
<li>
|
56
21
|
<a href="#auth">Authentication</a>
|
57
|
-
|
22
|
+
<%= erb :"version_sidebar/auth_nav", locals: {methods: @help[:authentication]} %>
|
58
23
|
</li>
|
59
24
|
<li><a href="#resources">Resources</a></li>
|
60
|
-
|
61
|
-
|
25
|
+
<% sort_hash(@help[:resources]).each do |resource, info| %>
|
26
|
+
<%=
|
27
|
+
erb :"version_sidebar/resource_nav", locals: {
|
28
|
+
resource: resource,
|
29
|
+
info: info,
|
30
|
+
prefix: 'root',
|
31
|
+
}
|
32
|
+
%>
|
62
33
|
<% end %>
|
63
34
|
</ul>
|
64
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haveapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Skokan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: require_all
|
@@ -58,42 +58,42 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.0
|
61
|
+
version: 2.1.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.0
|
68
|
+
version: 2.1.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: tilt
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.0.
|
75
|
+
version: 2.0.10
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.0.
|
82
|
+
version: 2.0.10
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: redcarpet
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
89
|
+
version: '3.5'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3.
|
96
|
+
version: '3.5'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 0.14.2
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 0.14.2
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: mail
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -268,7 +268,14 @@ files:
|
|
268
268
|
- lib/haveapi/views/index.erb
|
269
269
|
- lib/haveapi/views/main_layout.erb
|
270
270
|
- lib/haveapi/views/version_page.erb
|
271
|
+
- lib/haveapi/views/version_page/auth_body.erb
|
272
|
+
- lib/haveapi/views/version_page/client_auth.erb
|
273
|
+
- lib/haveapi/views/version_page/client_example.erb
|
274
|
+
- lib/haveapi/views/version_page/client_init.erb
|
275
|
+
- lib/haveapi/views/version_page/resource_body.erb
|
271
276
|
- lib/haveapi/views/version_sidebar.erb
|
277
|
+
- lib/haveapi/views/version_sidebar/auth_nav.erb
|
278
|
+
- lib/haveapi/views/version_sidebar/resource_nav.erb
|
272
279
|
- shell.nix
|
273
280
|
- spec/action/dsl_spec.rb
|
274
281
|
- spec/authorization_spec.rb
|
@@ -289,11 +296,11 @@ files:
|
|
289
296
|
- spec/validators/length_spec.rb
|
290
297
|
- spec/validators/numericality_spec.rb
|
291
298
|
- spec/validators/presence_spec.rb
|
292
|
-
homepage:
|
299
|
+
homepage:
|
293
300
|
licenses:
|
294
301
|
- MIT
|
295
302
|
metadata: {}
|
296
|
-
post_install_message:
|
303
|
+
post_install_message:
|
297
304
|
rdoc_options: []
|
298
305
|
require_paths:
|
299
306
|
- lib
|
@@ -308,9 +315,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
308
315
|
- !ruby/object:Gem::Version
|
309
316
|
version: '0'
|
310
317
|
requirements: []
|
311
|
-
|
312
|
-
|
313
|
-
signing_key:
|
318
|
+
rubygems_version: 3.2.26
|
319
|
+
signing_key:
|
314
320
|
specification_version: 4
|
315
321
|
summary: Framework for creating self-describing APIs
|
316
322
|
test_files: []
|