api_taster 0.4.5 → 0.4.6
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 +3 -11
- data/app/controllers/api_taster/routes_controller.rb +1 -1
- data/app/views/api_taster/routes/show.html.erb +11 -11
- data/lib/api_taster/route.rb +16 -11
- data/lib/api_taster/version.rb +1 -1
- data/spec/controllers/api_taster/routes_controller_spec.rb +1 -1
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/route_spec.rb +17 -7
- metadata +4 -6
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ApiTaster [](http://travis-ci.org/fredwu/api_taster) [](https://gemnasium.com/fredwu/api_taster)
|
2
2
|
|
3
|
-
A quick and easy way to visually test
|
3
|
+
A quick and easy way to visually test your Rails application's API.
|
4
4
|
|
5
5
|

|
6
6
|
|
@@ -11,8 +11,8 @@ There are already many awesome API clients (such as [Postman](https://chrome.goo
|
|
11
11
|
API Taster compared to alternatives, have the following advantages:
|
12
12
|
|
13
13
|
- API endpoints are automatically generated from your Rails routes definition
|
14
|
-
- Defining
|
15
|
-
-
|
14
|
+
- Defining params is as easy as defining routes
|
15
|
+
- Params can be shared with your test factories
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
@@ -29,14 +29,6 @@ Rails.application.routes.draw do
|
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
-
Add API Taster into the autoload paths in `development.rb`:
|
33
|
-
|
34
|
-
```ruby
|
35
|
-
config.autoload_paths += %W(
|
36
|
-
#{ApiTaster::Engine.root}
|
37
|
-
)
|
38
|
-
```
|
39
|
-
|
40
32
|
In `routes.rb`, define parameters for each API endpoint after the normal routes definition block. For example:
|
41
33
|
|
42
34
|
```ruby
|
@@ -5,39 +5,39 @@
|
|
5
5
|
:label_type => 'important'
|
6
6
|
%>
|
7
7
|
|
8
|
-
<% if @
|
9
|
-
<%= render 'undefined_route', :route => @
|
8
|
+
<% if @params.is_a?(Hash) && @params.has_key?(:undefined) %>
|
9
|
+
<%= render 'undefined_route', :route => @params[:undefined] %>
|
10
10
|
<% else %>
|
11
|
-
<% @
|
11
|
+
<% @params.each do |param| %>
|
12
12
|
<%= form_tag @route[:path], :method => @route[:verb], :class => 'well form-horizontal', :remote => true do %>
|
13
13
|
|
14
|
-
<% if
|
14
|
+
<% if param[:url_params].empty? && param[:post_params].empty? %>
|
15
15
|
<div class="alert alert-info">
|
16
16
|
No params specified.
|
17
17
|
</div>
|
18
18
|
<% else %>
|
19
19
|
<ul class="nav nav-tabs">
|
20
20
|
<li class="nav-label">Request</li>
|
21
|
-
<% if
|
22
|
-
<li<% unless
|
21
|
+
<% if param[:url_params].present? %>
|
22
|
+
<li<% unless param[:post_params].present? %> class="active"<% end %>><a href="#" id="url-params">URL</a></li>
|
23
23
|
<% end %>
|
24
|
-
<% if
|
24
|
+
<% if param[:post_params].present? %>
|
25
25
|
<li class="active"><a href="#" id="post-params">POST</a></li>
|
26
26
|
<% end %>
|
27
27
|
</ul>
|
28
28
|
<% end %>
|
29
29
|
|
30
|
-
<% if
|
30
|
+
<% if param[:url_params].present? %>
|
31
31
|
<fieldset ref="url-params">
|
32
|
-
<%
|
32
|
+
<% param[:url_params].each do |label, value| %>
|
33
33
|
<%= render 'param_form_element', :label => "[api_taster_url_params]#{label}", :value => value, :label_text => label %>
|
34
34
|
<% end %>
|
35
35
|
</fieldset>
|
36
36
|
<% end %>
|
37
37
|
|
38
|
-
<% if
|
38
|
+
<% if param[:post_params].present? %>
|
39
39
|
<fieldset ref="post-params">
|
40
|
-
<%= ApiTaster::FormBuilder.new(
|
40
|
+
<%= ApiTaster::FormBuilder.new(param[:post_params]).html.html_safe %>
|
41
41
|
</fieldset>
|
42
42
|
<% end %>
|
43
43
|
|
data/lib/api_taster/route.rb
CHANGED
@@ -7,6 +7,7 @@ module ApiTaster
|
|
7
7
|
cattr_accessor :obsolete_definitions
|
8
8
|
|
9
9
|
class << self
|
10
|
+
|
10
11
|
def map_routes
|
11
12
|
self.route_set = Rails.application.routes
|
12
13
|
self.supplied_params = {}
|
@@ -18,8 +19,8 @@ module ApiTaster
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def normalise_routes!
|
22
|
+
@_route_counter = 0
|
21
23
|
self.routes = []
|
22
|
-
i = -1
|
23
24
|
|
24
25
|
unless route_set.respond_to?(:routes)
|
25
26
|
raise ApiTaster::Exception.new('Route definitions are missing, have you defined ApiTaster.routes?')
|
@@ -31,14 +32,16 @@ module ApiTaster
|
|
31
32
|
|
32
33
|
if (rack_app = discover_rack_app(route.app)) && rack_app.respond_to?(:routes)
|
33
34
|
rack_app.routes.routes.each do |rack_route|
|
34
|
-
self.routes << normalise_route(rack_route,
|
35
|
+
self.routes << normalise_route(rack_route, route.path.spec)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
39
|
next if route.verb.source.empty?
|
39
40
|
|
40
|
-
self.routes << normalise_route(route
|
41
|
+
self.routes << normalise_route(route)
|
41
42
|
end
|
43
|
+
|
44
|
+
self.routes.flatten!
|
42
45
|
end
|
43
46
|
|
44
47
|
def grouped_routes
|
@@ -84,14 +87,16 @@ module ApiTaster
|
|
84
87
|
end
|
85
88
|
end
|
86
89
|
|
87
|
-
def normalise_route(route,
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
def normalise_route(route, path_prefix = nil)
|
91
|
+
route.verb.source.split('|').map do |verb|
|
92
|
+
{
|
93
|
+
:id => @_route_counter+=1,
|
94
|
+
:name => route.name,
|
95
|
+
:verb => verb.gsub(/[$^]/, ''),
|
96
|
+
:path => path_prefix.to_s + route.path.spec.to_s.sub('(.:format)', ''),
|
97
|
+
:reqs => route.requirements
|
98
|
+
}
|
99
|
+
end
|
95
100
|
end
|
96
101
|
|
97
102
|
def split_input(input, route)
|
data/lib/api_taster/version.rb
CHANGED
data/spec/dummy/config/routes.rb
CHANGED
@@ -2,6 +2,7 @@ Rails.application.routes.draw do
|
|
2
2
|
mount ApiTaster::Engine => "/api_taster"
|
3
3
|
|
4
4
|
get 'home' => 'application#home', :as => :home
|
5
|
+
match 'custom' => 'application#home', :via => [:get, :delete]
|
5
6
|
|
6
7
|
resources :users, :except => [:new, :edit] do
|
7
8
|
resources :comments, :only => [:new, :edit]
|
data/spec/route_spec.rb
CHANGED
@@ -2,9 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module ApiTaster
|
4
4
|
describe Route do
|
5
|
+
context "undefined ApiTaster.routes" do
|
6
|
+
it "errors out" do
|
7
|
+
Route.route_set = nil
|
8
|
+
expect { Route.normalise_routes! }.to raise_exception(ApiTaster::Exception)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
5
12
|
let(:app_home_route) do
|
6
13
|
{
|
7
|
-
:id =>
|
14
|
+
:id => 1,
|
8
15
|
:name => 'home',
|
9
16
|
:verb => 'GET',
|
10
17
|
:path => '/home',
|
@@ -19,6 +26,7 @@ module ApiTaster
|
|
19
26
|
routes = ActionDispatch::Routing::RouteSet.new
|
20
27
|
routes.draw do
|
21
28
|
get 'home' => 'application#home', :as => :home
|
29
|
+
match 'dual_action' => 'dummy/action', :via => [:get, :delete]
|
22
30
|
resources :users do
|
23
31
|
resources :comments
|
24
32
|
end
|
@@ -34,11 +42,13 @@ module ApiTaster
|
|
34
42
|
Route.routes.first.should == app_home_route
|
35
43
|
end
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
it "finds rack app routes" do
|
46
|
+
Route.find_by_verb_and_path(:get, '/app/home').should_not == nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "outputs routes for all verbs" do
|
50
|
+
Route.find_by_verb_and_path(:get, '/dual_action').should_not == nil
|
51
|
+
Route.find_by_verb_and_path(:delete, '/dual_action').should_not == nil
|
42
52
|
end
|
43
53
|
|
44
54
|
it "#grouped_routes" do
|
@@ -49,7 +59,7 @@ module ApiTaster
|
|
49
59
|
end
|
50
60
|
|
51
61
|
it "#find" do
|
52
|
-
Route.find(
|
62
|
+
Route.find(1).should == app_home_route
|
53
63
|
Route.find(999).should == nil
|
54
64
|
end
|
55
65
|
|
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.4.
|
4
|
+
version: 0.4.6
|
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-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -339,7 +339,6 @@ files:
|
|
339
339
|
- spec/dummy/tmp/cache/sass/f455898439b6313d4297be03fbcfa4df713cf294/_bootstrap.scssc
|
340
340
|
- spec/dummy/tmp/cache/sass/fced329c33ec1fff188d99efbc4d1fd1c556b66a/bootstrap.min.cssc
|
341
341
|
- spec/dummy/tmp/cache/sass/fced329c33ec1fff188d99efbc4d1fd1c556b66a/layout.css.scssc
|
342
|
-
- spec/dummy/tmp/pids/server.pid
|
343
342
|
homepage: https://github.com/fredwu/api_taster
|
344
343
|
licenses: []
|
345
344
|
post_install_message:
|
@@ -354,7 +353,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
354
353
|
version: '0'
|
355
354
|
segments:
|
356
355
|
- 0
|
357
|
-
hash:
|
356
|
+
hash: -1174127571206954277
|
358
357
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
359
358
|
none: false
|
360
359
|
requirements:
|
@@ -363,7 +362,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
363
362
|
version: '0'
|
364
363
|
segments:
|
365
364
|
- 0
|
366
|
-
hash:
|
365
|
+
hash: -1174127571206954277
|
367
366
|
requirements: []
|
368
367
|
rubyforge_project:
|
369
368
|
rubygems_version: 1.8.24
|
@@ -501,7 +500,6 @@ test_files:
|
|
501
500
|
- spec/dummy/tmp/cache/sass/f455898439b6313d4297be03fbcfa4df713cf294/_bootstrap.scssc
|
502
501
|
- spec/dummy/tmp/cache/sass/fced329c33ec1fff188d99efbc4d1fd1c556b66a/bootstrap.min.cssc
|
503
502
|
- spec/dummy/tmp/cache/sass/fced329c33ec1fff188d99efbc4d1fd1c556b66a/layout.css.scssc
|
504
|
-
- spec/dummy/tmp/pids/server.pid
|
505
503
|
- spec/form_builder_spec.rb
|
506
504
|
- spec/mapper_spec.rb
|
507
505
|
- spec/route_spec.rb
|