api_taster 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +40 -21
- data/app/assets/javascripts/api_taster/app.js +24 -12
- data/app/assets/stylesheets/api_taster/layout.css.scss +41 -4
- data/app/views/api_taster/routes/_param_form_legend.html.erb +1 -1
- data/app/views/api_taster/routes/index.html.erb +22 -18
- data/app/views/api_taster/routes/show.html.erb +13 -5
- data/app/views/layouts/api_taster/application.html.erb +1 -1
- data/lib/api_taster/version.rb +1 -1
- data/spec/dummy/config/routes.rb +4 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A quick and easy way to visually test out your application's API.
|
4
4
|
|
5
|
-

|
6
6
|
|
7
7
|
## Why?
|
8
8
|
|
@@ -19,17 +19,17 @@ API Taster compared to alternatives, have the following advantages:
|
|
19
19
|
Add API Taster in your gemfile:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
gem 'api_taster'
|
22
|
+
gem 'api_taster', :group => :development
|
23
23
|
```
|
24
24
|
Mount API Taster, this will allow you to visit API Taster from within your app. For example:
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
Rails.application.routes.draw do
|
28
|
-
mount ApiTaster::Engine => "/api_taster"
|
28
|
+
mount ApiTaster::Engine => "/api_taster" if Rails.env.development?
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
-
Add API Taster into the autoload paths in `
|
32
|
+
Add API Taster into the autoload paths in `development.rb`:
|
33
33
|
|
34
34
|
```ruby
|
35
35
|
config.autoload_paths += %W(
|
@@ -40,33 +40,52 @@ config.autoload_paths += %W(
|
|
40
40
|
In `routes.rb`, define parameters for each API endpoint after the normal routes definition block. For example:
|
41
41
|
|
42
42
|
```ruby
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
:
|
43
|
+
if Rails.env.development?
|
44
|
+
ApiTaster.routes do
|
45
|
+
get '/users'
|
46
|
+
|
47
|
+
post '/users', {
|
48
|
+
:user => {
|
49
|
+
:name => 'Fred'
|
50
|
+
}
|
49
51
|
}
|
50
|
-
}
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
get '/users/:id', {
|
54
|
+
:id => 1
|
55
|
+
}
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
put '/users/:id', {
|
58
|
+
:id => 1, :user => {
|
59
|
+
:name => 'Awesome'
|
60
|
+
}
|
59
61
|
}
|
60
|
-
}
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
delete '/users/:id', {
|
64
|
+
:id => 1
|
65
|
+
}
|
66
|
+
end
|
65
67
|
end
|
66
68
|
```
|
67
69
|
|
68
70
|
That's it! Enjoy! :)
|
69
71
|
|
72
|
+
## Use with an Engine
|
73
|
+
|
74
|
+
Rails Engines are largely self contained and separated from your main app. Therefore, to use API Taster with an Engine, you would need some extra efforts:
|
75
|
+
|
76
|
+
In your app Gemfile, you would also need:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
gem "jquery-rails"
|
80
|
+
gem "bootstrap-sass"
|
81
|
+
```
|
82
|
+
|
83
|
+
If you are hand-picking Rails components, make sure in your `application.rb` you have Sprockets enabled:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
require "sprockets/railtie"
|
87
|
+
```
|
88
|
+
|
70
89
|
## License
|
71
90
|
|
72
91
|
This gem is released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
@@ -1,10 +1,10 @@
|
|
1
1
|
var ApiTaster = {
|
2
2
|
formAction: '',
|
3
3
|
disableUrlParams: function() {
|
4
|
-
$("
|
4
|
+
$("fieldset[ref=url-params] input").prop("disabled", true);
|
5
5
|
},
|
6
6
|
enableUrlParams: function() {
|
7
|
-
$("
|
7
|
+
$("fieldset[ref=url-params] input").prop("disabled", false);
|
8
8
|
},
|
9
9
|
storeFormActionFor: function(form) {
|
10
10
|
ApiTaster.formAction = form.attr("action")
|
@@ -32,6 +32,23 @@ $.fn.extend({
|
|
32
32
|
form.attr("action", replacedAction);
|
33
33
|
}
|
34
34
|
});
|
35
|
+
},
|
36
|
+
enableNavTabsFor: function(contentElement) {
|
37
|
+
var container = this;
|
38
|
+
|
39
|
+
$("ul.nav-tabs a", container).click(function(e) {
|
40
|
+
e.preventDefault();
|
41
|
+
|
42
|
+
$(this).parent().siblings().removeClass("active");
|
43
|
+
$(this).parent().addClass("active");
|
44
|
+
|
45
|
+
$(contentElement, container).hide();
|
46
|
+
$(contentElement + "[ref=" + $(this).attr("id") + "]", container).show();
|
47
|
+
});
|
48
|
+
},
|
49
|
+
displayOnlySelectedParamsFieldset: function() {
|
50
|
+
$("fieldset", this).hide();
|
51
|
+
$("fieldset[ref=" + $("ul.nav-tabs li.active a").attr("id") + "]", this).show();
|
35
52
|
}
|
36
53
|
});
|
37
54
|
|
@@ -42,8 +59,11 @@ jQuery(function($) {
|
|
42
59
|
$("a.show-api").parent().removeClass("active");
|
43
60
|
$(this).parent().addClass("active");
|
44
61
|
|
45
|
-
$("#show-api-div").load(this.href, function() {
|
62
|
+
$("#show-api-div .div-container").load(this.href, function() {
|
46
63
|
prettyPrint();
|
64
|
+
|
65
|
+
$("#show-api-div form").enableNavTabsFor("fieldset");
|
66
|
+
$("#show-api-div form").displayOnlySelectedParamsFieldset();
|
47
67
|
});
|
48
68
|
});
|
49
69
|
|
@@ -74,15 +94,7 @@ jQuery(function($) {
|
|
74
94
|
prettyPrint();
|
75
95
|
});
|
76
96
|
|
77
|
-
$("#show-api-response-div
|
78
|
-
e.preventDefault();
|
79
|
-
|
80
|
-
$(this).parent().siblings().removeClass("active");
|
81
|
-
$(this).parent().addClass("active");
|
82
|
-
|
83
|
-
$("pre", "#show-api-response-div").hide();
|
84
|
-
$("pre[ref=" + $(this).attr("id") + "]", "#show-api-response-div").show();
|
85
|
-
});
|
97
|
+
$("#show-api-response-div").enableNavTabsFor("pre");
|
86
98
|
});
|
87
99
|
});
|
88
100
|
|
@@ -3,11 +3,38 @@
|
|
3
3
|
$colour_text: #333;
|
4
4
|
$colour_grey: #999;
|
5
5
|
|
6
|
+
// layout
|
7
|
+
|
8
|
+
body, html {
|
9
|
+
height: 100%;
|
10
|
+
overflow: hidden;
|
11
|
+
}
|
12
|
+
|
6
13
|
body {
|
7
|
-
padding-top: 50px;
|
8
|
-
padding-bottom: 50px;
|
9
14
|
}
|
10
15
|
|
16
|
+
#wrapper {
|
17
|
+
height: 100%;
|
18
|
+
|
19
|
+
#main-container {
|
20
|
+
height: 100%;
|
21
|
+
overflow: hidden;
|
22
|
+
padding-top: 50px;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
#list-api-div,
|
27
|
+
#show-api-div {
|
28
|
+
height: 100%;
|
29
|
+
overflow: auto;
|
30
|
+
|
31
|
+
.div-container {
|
32
|
+
padding-bottom: 50px;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
// elements
|
37
|
+
|
11
38
|
.hidden {
|
12
39
|
display: none;
|
13
40
|
}
|
@@ -22,11 +49,21 @@ legend {
|
|
22
49
|
font-weight: bold;
|
23
50
|
color: $colour_grey;
|
24
51
|
|
25
|
-
&.
|
26
|
-
|
52
|
+
&.compact-legend {
|
53
|
+
padding: 0;
|
54
|
+
font-size: 12px;
|
55
|
+
line-height: 24px;
|
27
56
|
}
|
28
57
|
}
|
29
58
|
|
59
|
+
.nav-label {
|
60
|
+
padding: 8px 12px;
|
61
|
+
line-height: 18px;
|
62
|
+
margin-right: 5px;
|
63
|
+
font-weight: bold;
|
64
|
+
color: $colour_grey;
|
65
|
+
}
|
66
|
+
|
30
67
|
.label-api {
|
31
68
|
display: inline-block;
|
32
69
|
padding-right: 5px;
|
@@ -1 +1 @@
|
|
1
|
-
<legend><%= label %></legend>
|
1
|
+
<legend class="compact-legend"><%= label %></legend>
|
@@ -1,24 +1,28 @@
|
|
1
|
-
<div class="row">
|
2
|
-
<div class="span5">
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
<
|
9
|
-
<
|
10
|
-
<
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
<div id="main-container" class="row">
|
2
|
+
<div id="list-api-div" class="span5">
|
3
|
+
<div class="div-container">
|
4
|
+
<ul class="well nav nav-list">
|
5
|
+
<% @routes.each do |controller, routes| %>
|
6
|
+
<li class="nav-header"><%= controller %></li>
|
7
|
+
<% routes.each do |route| %>
|
8
|
+
<li>
|
9
|
+
<a class="show-api" href="<%= route_path(route[:id]) %>">
|
10
|
+
<div class="label-api label-api-full">
|
11
|
+
<span class="label label-important"><%= route[:verb] %></span>
|
12
|
+
</div>
|
13
|
+
<strong><%= route[:path] %></strong>
|
14
|
+
</a>
|
15
|
+
</li>
|
16
|
+
<% end %>
|
15
17
|
<% end %>
|
16
|
-
|
17
|
-
</
|
18
|
+
</ul>
|
19
|
+
</div>
|
18
20
|
</div>
|
19
21
|
<div id="show-api-div" class="span7">
|
20
|
-
<div class="
|
21
|
-
<
|
22
|
+
<div class="div-container">
|
23
|
+
<div class="alert alert-block alert-info">
|
24
|
+
<h3>Select an API endpoint on the left to get started. :)</h3>
|
25
|
+
</div>
|
22
26
|
</div>
|
23
27
|
</div>
|
24
28
|
</div>
|
@@ -18,11 +18,20 @@
|
|
18
18
|
<div class="alert alert-info">
|
19
19
|
No params specified.
|
20
20
|
</div>
|
21
|
+
<% else %>
|
22
|
+
<ul class="nav nav-tabs">
|
23
|
+
<li class="nav-label">Request</li>
|
24
|
+
<% if input[:url_params].present? %>
|
25
|
+
<li<% unless input[:post_params].present? %> class="active"<% end %>><a href="#" id="url-params">URL</a></li>
|
26
|
+
<% end %>
|
27
|
+
<% if input[:post_params].present? %>
|
28
|
+
<li class="active"><a href="#" id="post-params">POST</a></li>
|
29
|
+
<% end %>
|
30
|
+
</ul>
|
21
31
|
<% end %>
|
22
32
|
|
23
33
|
<% if input[:url_params].present? %>
|
24
|
-
<fieldset
|
25
|
-
<legend class="super-legend">URL Params</legend>
|
34
|
+
<fieldset ref="url-params">
|
26
35
|
<% input[:url_params].each do |label, value| %>
|
27
36
|
<%= render 'param_form_element', :label => "[api_taster_url_params]#{label}", :value => value, :label_text => label %>
|
28
37
|
<% end %>
|
@@ -30,8 +39,7 @@
|
|
30
39
|
<% end %>
|
31
40
|
|
32
41
|
<% if input[:post_params].present? %>
|
33
|
-
<fieldset>
|
34
|
-
<legend class="super-legend">Post Params</legend>
|
42
|
+
<fieldset ref="post-params">
|
35
43
|
<%= ApiTaster::FormBuilder.new(input[:post_params]).html.html_safe %>
|
36
44
|
</fieldset>
|
37
45
|
<% end %>
|
@@ -45,8 +53,8 @@
|
|
45
53
|
<% end %>
|
46
54
|
|
47
55
|
<div id="show-api-response-div" class="well hidden">
|
48
|
-
<legend class="super-legend">Response</legend>
|
49
56
|
<ul class="nav nav-tabs">
|
57
|
+
<li class="nav-label">Response</li>
|
50
58
|
<li class="active"><a href="#" id="response-json">JSON</a></li>
|
51
59
|
<li><a href="#" id="response-raw">Raw</a></li>
|
52
60
|
</ul>
|
data/lib/api_taster/version.rb
CHANGED
data/spec/dummy/config/routes.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_taster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -349,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
349
349
|
version: '0'
|
350
350
|
segments:
|
351
351
|
- 0
|
352
|
-
hash:
|
352
|
+
hash: 2843027510352515993
|
353
353
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
354
354
|
none: false
|
355
355
|
requirements:
|
@@ -358,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
358
358
|
version: '0'
|
359
359
|
segments:
|
360
360
|
- 0
|
361
|
-
hash:
|
361
|
+
hash: 2843027510352515993
|
362
362
|
requirements: []
|
363
363
|
rubyforge_project:
|
364
364
|
rubygems_version: 1.8.24
|