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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # ApiTaster [![Build Status](https://secure.travis-ci.org/fredwu/api_taster.png?branch=master)](http://travis-ci.org/fredwu/api_taster) [![Dependency Status](https://gemnasium.com/fredwu/api_taster.png)](https://gemnasium.com/fredwu/api_taster)
2
2
 
3
- A quick and easy way to visually test out your Rails application's API.
3
+ A quick and easy way to visually test your Rails application's API.
4
4
 
5
5
  ![](http://i.imgur.com/8Dnto.png)
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 post params is as easy as defining routes
15
- - Post params can be shared with your test factories
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
@@ -10,7 +10,7 @@ module ApiTaster
10
10
 
11
11
  def show
12
12
  @route = Route.find(params[:id])
13
- @inputs = Route.params_for(@route)
13
+ @params = Route.params_for(@route)
14
14
  end
15
15
 
16
16
  def missing_definitions
@@ -5,39 +5,39 @@
5
5
  :label_type => 'important'
6
6
  %>
7
7
 
8
- <% if @inputs.is_a?(Hash) && @inputs.has_key?(:undefined) %>
9
- <%= render 'undefined_route', :route => @inputs[:undefined] %>
8
+ <% if @params.is_a?(Hash) && @params.has_key?(:undefined) %>
9
+ <%= render 'undefined_route', :route => @params[:undefined] %>
10
10
  <% else %>
11
- <% @inputs.each do |input| %>
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 input[:url_params].empty? && input[:post_params].empty? %>
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 input[:url_params].present? %>
22
- <li<% unless input[:post_params].present? %> class="active"<% end %>><a href="#" id="url-params">URL</a></li>
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 input[:post_params].present? %>
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 input[:url_params].present? %>
30
+ <% if param[:url_params].present? %>
31
31
  <fieldset ref="url-params">
32
- <% input[:url_params].each do |label, value| %>
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 input[:post_params].present? %>
38
+ <% if param[:post_params].present? %>
39
39
  <fieldset ref="post-params">
40
- <%= ApiTaster::FormBuilder.new(input[:post_params]).html.html_safe %>
40
+ <%= ApiTaster::FormBuilder.new(param[:post_params]).html.html_safe %>
41
41
  </fieldset>
42
42
  <% end %>
43
43
 
@@ -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, i+=1)
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, i+=1)
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, id)
88
- {
89
- :id => id,
90
- :name => route.name,
91
- :verb => route.verb.source.gsub(/[$^]/, ''),
92
- :path => route.path.spec.to_s.sub('(.:format)', ''),
93
- :reqs => route.requirements
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)
@@ -1,3 +1,3 @@
1
1
  module ApiTaster
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
@@ -15,7 +15,7 @@ module ApiTaster
15
15
  get :show, :id => 1, :use_route => :api_taster
16
16
 
17
17
  assigns(:route).should be_kind_of(Route)
18
- assigns(:inputs).should be_kind_of(Array)
18
+ assigns(:params).should be_kind_of(Array)
19
19
  end
20
20
 
21
21
  it "#missing_definitions" do
@@ -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]
@@ -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 => 0,
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
- context "undefined ApiTaster.routes" do
38
- it "errors out" do
39
- Route.route_set = nil
40
- expect { Route.normalise_routes! }.to raise_exception(ApiTaster::Exception)
41
- end
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(0).should == app_home_route
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.5
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-25 00:00:00.000000000 Z
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: 4235987413395832386
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: 4235987413395832386
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