api_taster 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
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
- ![](http://i.imgur.com/1kyEk.png)
5
+ ![](http://i.imgur.com/ryjOH.png)
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 `application.rb`:
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
- ApiTaster.routes do
44
- get '/users'
45
-
46
- post '/users', {
47
- :user => {
48
- :name => 'Fred'
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
- get '/users/:id', {
53
- :id => 1
54
- }
53
+ get '/users/:id', {
54
+ :id => 1
55
+ }
55
56
 
56
- put '/users/:id', {
57
- :id => 1, :user => {
58
- :name => 'Awesome'
57
+ put '/users/:id', {
58
+ :id => 1, :user => {
59
+ :name => 'Awesome'
60
+ }
59
61
  }
60
- }
61
62
 
62
- delete '/users/:id', {
63
- :id => 1
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
- $("#url-params input").prop("disabled", true);
4
+ $("fieldset[ref=url-params] input").prop("disabled", true);
5
5
  },
6
6
  enableUrlParams: function() {
7
- $("#url-params input").prop("disabled", false);
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 ul.nav-tabs a").click(function(e) {
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
- &.super-legend {
26
- color: $colour_text;
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
- <ul class="well nav nav-list">
4
- <% @routes.each do |controller, routes| %>
5
- <li class="nav-header"><%= controller %></li>
6
- <% routes.each do |route| %>
7
- <li>
8
- <a class="show-api" href="<%= route_path(route[:id]) %>">
9
- <div class="label-api label-api-full">
10
- <span class="label label-important"><%= route[:verb] %></span>
11
- </div>
12
- <strong><%= route[:path] %></strong>
13
- </a>
14
- </li>
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
- <% end %>
17
- </ul>
18
+ </ul>
19
+ </div>
18
20
  </div>
19
21
  <div id="show-api-div" class="span7">
20
- <div class="alert alert-block alert-info">
21
- <h3>Select an API endpoint on the left to get started. :)</h3>
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 id="url-params">
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>
@@ -22,7 +22,7 @@
22
22
  </div>
23
23
  </div>
24
24
 
25
- <div class="container">
25
+ <div id="wrapper" class="container">
26
26
  <%= yield %>
27
27
  </div>
28
28
  </body>
@@ -1,3 +1,3 @@
1
1
  module ApiTaster
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -13,7 +13,10 @@ ApiTaster.routes do
13
13
 
14
14
  post '/users', {
15
15
  :user => {
16
- :name => 'Fred'
16
+ :name => 'Fred',
17
+ :comment => {
18
+ :title => 'hi!'
19
+ }
17
20
  }
18
21
  }
19
22
 
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.0
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-20 00:00:00.000000000 Z
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: 1097102219077556863
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: 1097102219077556863
361
+ hash: 2843027510352515993
362
362
  requirements: []
363
363
  rubyforge_project:
364
364
  rubygems_version: 1.8.24