api_taster 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,7 +19,7 @@ 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', :group => :development
22
+ gem 'api_taster'
23
23
  ```
24
24
  Mount API Taster, this will allow you to visit API Taster from within your app. For example:
25
25
 
@@ -63,6 +63,21 @@ end
63
63
 
64
64
  If you use a test factory such as [FactoryGirl](https://github.com/thoughtbot/factory_girl), you can require your test factories and share the params. For example in FactoryGirl you can use the `attributes_for(:name_of_factory)` method.
65
65
 
66
+ ### Global Params
67
+
68
+ If there are certain params (such as API version and auth token) that need to be present in every API endpoint, you may set them in `ApiTaster.global_params` before `ApiTaster.routes`:
69
+
70
+ ```ruby
71
+ ApiTaster.global_params = {
72
+ :version => 1,
73
+ :auth_token => 'teGpfbVitpnUwm7qStf9'
74
+ }
75
+
76
+ ApiTaster.routes do
77
+ # your route definitions
78
+ end
79
+ ```
80
+
66
81
  ### Missing Route Definitions Detection
67
82
 
68
83
  Instead of manually finding out which route definitions you need, API Taster provides a warning page that shows you all the missing definitions.
@@ -1,5 +1,13 @@
1
1
  module ApiTaster
2
2
  class ApplicationController < ActionController::Base
3
3
  layout proc { |controller| controller.request.xhr? ? nil : 'api_taster/application' }
4
+
5
+ before_filter :reload_routes
6
+
7
+ private
8
+
9
+ def reload_routes
10
+ load Rails.application.root.join('config/routes.rb')
11
+ end
4
12
  end
5
13
  end
@@ -7,6 +7,9 @@ require 'api_taster/mapper'
7
7
  require 'api_taster/form_builder'
8
8
 
9
9
  module ApiTaster
10
+ mattr_accessor :global_params
11
+ self.global_params = {}
12
+
10
13
  def self.routes(&block)
11
14
  Route.mappings = Proc.new { block }
12
15
  end
@@ -30,9 +30,9 @@ module ApiTaster
30
30
  }
31
31
  else
32
32
  Route.supplied_params[route[:id]] ||= []
33
- Route.supplied_params[route[:id]] << params
33
+ Route.supplied_params[route[:id]] << ApiTaster.global_params.merge(params)
34
34
  end
35
35
  end
36
36
  end
37
37
  end
38
- end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module ApiTaster
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
@@ -24,7 +24,27 @@ module ApiTaster
24
24
 
25
25
  before(:all) do
26
26
  Rails.application.routes.draw { resources :dummy_users }
27
+ end
28
+
29
+ context "#global_params" do
30
+ before(:all) do
31
+ ApiTaster.global_params = { :foo => 'bar' }
32
+
33
+ ApiTaster.routes do
34
+ get '/dummy_users/:id', :id => 1
35
+ end
36
+
37
+ Route.map_routes
38
+ end
27
39
 
40
+ it "merges params" do
41
+ route = Route.find_by_verb_and_path(:get, '/dummy_users/:id')
42
+
43
+ Route.supplied_params[route[:id]].should == [{ :foo => 'bar', :id => 1 }]
44
+ end
45
+ end
46
+
47
+ before(:all) do
28
48
  ApiTaster.routes do
29
49
  get '/dummy_users/:id', :id => 1
30
50
  post '/dummy_users'
@@ -38,6 +38,10 @@ module ApiTaster
38
38
  Route.map_routes
39
39
  end
40
40
 
41
+ it "lazy loads the mapping" do
42
+ Route.mappings.should be_kind_of(Proc)
43
+ end
44
+
41
45
  it "#routes" do
42
46
  Route.routes.first.should == app_home_route
43
47
  end
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.6
4
+ version: 0.4.7
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-27 00:00:00.000000000 Z
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -339,6 +339,7 @@ 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
342
343
  homepage: https://github.com/fredwu/api_taster
343
344
  licenses: []
344
345
  post_install_message:
@@ -353,7 +354,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
353
354
  version: '0'
354
355
  segments:
355
356
  - 0
356
- hash: -1174127571206954277
357
+ hash: 2450223208085472037
357
358
  required_rubygems_version: !ruby/object:Gem::Requirement
358
359
  none: false
359
360
  requirements:
@@ -362,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
362
363
  version: '0'
363
364
  segments:
364
365
  - 0
365
- hash: -1174127571206954277
366
+ hash: 2450223208085472037
366
367
  requirements: []
367
368
  rubyforge_project:
368
369
  rubygems_version: 1.8.24
@@ -500,6 +501,7 @@ test_files:
500
501
  - spec/dummy/tmp/cache/sass/f455898439b6313d4297be03fbcfa4df713cf294/_bootstrap.scssc
501
502
  - spec/dummy/tmp/cache/sass/fced329c33ec1fff188d99efbc4d1fd1c556b66a/bootstrap.min.cssc
502
503
  - spec/dummy/tmp/cache/sass/fced329c33ec1fff188d99efbc4d1fd1c556b66a/layout.css.scssc
504
+ - spec/dummy/tmp/pids/server.pid
503
505
  - spec/form_builder_spec.rb
504
506
  - spec/mapper_spec.rb
505
507
  - spec/route_spec.rb