playground.html.erb
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<h1>API Playground</h1>
<script>
<% prefix = Noosfero::API::API.prefix %>
var prefix = <%= prefix.to_json %>;
var endpoints = <%=
endpoints.map do |endpoint|
app = endpoint.options[:app].to_s
unless app.blank?
endpoint.routes.map do |route|
{
method: route.route_method,
path: route.route_path.gsub(':version', route.route_version).split('(').first
}
end
end
end.flatten.compact.sort{|a,b|
a[:path]=="#{prefix}/v1/login" ? -1 :
b[:path]=="#{prefix}/v1/login" ? 1 :
a[:path] <=> b[:path]
}.to_json %>;
</script>
<form id="api-form">
<label id="endpoint">Endpoint:
<select name="endpoint" onchange="playground.selEndpoint()"></select>
</label>
<label id="api-token">Token:
<%= tag :input, size: 32, placeholder: _('Use the login endpoint') %>
</label>
</form>
<div id="playground-ctrl">
<button onclick="playground.addFormParam()"><%=_('Add parameter')%></button>
<button onclick="playground.run()" style="font-weight:bold"> <%=_('Run')%> </button>
</div>
<pre id="api-response" class="empty"></pre>
<%= javascript_include_tag 'api-playground' %>