api_taster 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.8.7
3
4
  - 1.9.3
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
-
5
- gem "jquery-rails"
6
- gem "bootstrap-sass"
@@ -36,22 +36,22 @@ $.fn.extend({
36
36
  replaceUrlParams: function(params) {
37
37
  var form = this;
38
38
 
39
+ ApiTaster.storeFormActionFor(form);
40
+
41
+ var formAction = form.attr("action");
42
+
39
43
  $.each(params, function(i, param) {
40
44
  var matches = param["name"].match(/\[api_taster_url_params\](.*)/)
41
45
  if (matches) {
42
46
  var paramKey = matches[1];
43
47
  var paramValue = param["value"];
48
+ var regex = new RegExp(":" + paramKey);
44
49
 
45
- ApiTaster.storeFormActionFor(form);
46
-
47
- var regex = new RegExp(":" + paramKey);
48
- var replacedAction = ApiTaster.formAction.replace(regex, paramValue);
49
-
50
- form.attr("action", replacedAction);
51
- } else {
52
- ApiTaster.storeFormActionFor(form);
50
+ formAction = formAction.replace(regex, paramValue);
53
51
  }
54
52
  });
53
+
54
+ form.attr("action", formAction);
55
55
  },
56
56
 
57
57
  enableNavTabsFor: function(contentElement) {
@@ -1,5 +1,5 @@
1
1
  module ApiTaster
2
- class RoutesController < ApplicationController
2
+ class RoutesController < ApiTaster::ApplicationController
3
3
  before_filter :map_routes
4
4
 
5
5
  def index
@@ -10,7 +10,7 @@ module ApiTaster
10
10
 
11
11
  def show
12
12
  @route = Route.find(params[:id])
13
- @inputs = Route.inputs_for(@route)
13
+ @inputs = Route.params_for(@route)
14
14
  end
15
15
 
16
16
  def missing_definitions
@@ -29,8 +29,8 @@ module ApiTaster
29
29
  :params => params
30
30
  }
31
31
  else
32
- Route.inputs[route[:id]] ||= []
33
- Route.inputs[route[:id]] << params
32
+ Route.supplied_params[route[:id]] ||= []
33
+ Route.supplied_params[route[:id]] << params
34
34
  end
35
35
  end
36
36
  end
@@ -3,13 +3,13 @@ module ApiTaster
3
3
  cattr_accessor :route_set
4
4
  cattr_accessor :routes
5
5
  cattr_accessor :mappings
6
- cattr_accessor :inputs
6
+ cattr_accessor :supplied_params
7
7
  cattr_accessor :obsolete_definitions
8
8
 
9
9
  class << self
10
10
  def map_routes
11
11
  self.route_set = Rails.application.routes
12
- self.inputs = {}
12
+ self.supplied_params = {}
13
13
  self.obsolete_definitions = []
14
14
 
15
15
  normalise_routes!
@@ -56,12 +56,12 @@ module ApiTaster
56
56
  end[0]
57
57
  end
58
58
 
59
- def inputs_for(route)
60
- unless inputs.has_key?(route[:id])
59
+ def params_for(route)
60
+ unless supplied_params.has_key?(route[:id])
61
61
  return { :undefined => route }
62
62
  end
63
63
 
64
- inputs[route[:id]].collect { |input| split_input(input, route) }
64
+ supplied_params[route[:id]].collect { |input| split_input(input, route) }
65
65
  end
66
66
 
67
67
  def missing_definitions
@@ -71,7 +71,7 @@ module ApiTaster
71
71
  private
72
72
 
73
73
  def undefined_route?(route)
74
- r = inputs_for(route)
74
+ r = params_for(route)
75
75
  r.is_a?(Hash) && r.has_key?(:undefined)
76
76
  end
77
77
 
@@ -97,7 +97,7 @@ module ApiTaster
97
97
  def split_input(input, route)
98
98
  url_param_keys = route[:path].scan /:\w+/
99
99
 
100
- url_params = input.select { |k| ":#{k}".in?(url_param_keys) }
100
+ url_params = input.reject { |k, v| ! ":#{k}".in?(url_param_keys) }
101
101
  post_params = input.diff(url_params)
102
102
 
103
103
  {
@@ -1,3 +1,3 @@
1
1
  module ApiTaster
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
@@ -10,7 +10,7 @@ module ApiTaster
10
10
 
11
11
  it "#show" do
12
12
  Route.stub(:find).and_return(Route.new)
13
- Route.stub(:inputs_for).and_return([])
13
+ Route.stub(:params_for).and_return([])
14
14
 
15
15
  get :show, :id => 1, :use_route => :api_taster
16
16
 
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json]
8
+ wrap_parameters :format => [:json]
9
9
  end
10
10
 
11
11
  # Disable root element in JSON by default.
data/spec/mapper_spec.rb CHANGED
@@ -39,25 +39,25 @@ module ApiTaster
39
39
  it "gets users" do
40
40
  route = Route.find_by_verb_and_path(:get, '/dummy_users/:id')
41
41
 
42
- Route.inputs[route[:id]].should == [{ :id => 1 }]
42
+ Route.supplied_params[route[:id]].should == [{ :id => 1 }]
43
43
  end
44
44
 
45
45
  it "posts a new user" do
46
46
  route = Route.find_by_verb_and_path(:post, '/dummy_users')
47
47
 
48
- Route.inputs[route[:id]].should == [{}, { :hello => 'world' }]
48
+ Route.supplied_params[route[:id]].should == [{}, { :hello => 'world' }]
49
49
  end
50
50
 
51
51
  it "edits a user" do
52
52
  route = Route.find_by_verb_and_path(:put, '/dummy_users/:id')
53
53
 
54
- Route.inputs[route[:id]].should == [{ :id => 2 }]
54
+ Route.supplied_params[route[:id]].should == [{ :id => 2 }]
55
55
  end
56
56
 
57
57
  it "deletes a user" do
58
58
  route = Route.find_by_verb_and_path(:delete, '/dummy_users/:id')
59
59
 
60
- Route.inputs[route[:id]].should == [{ :id => 3 }]
60
+ Route.supplied_params[route[:id]].should == [{ :id => 3 }]
61
61
  end
62
62
  end
63
63
  end
data/spec/route_spec.rb CHANGED
@@ -59,7 +59,7 @@ module ApiTaster
59
59
  Route.find_by_verb_and_path(:delete, '/home').should == nil
60
60
  end
61
61
 
62
- it "#inputs_for" do
62
+ it "#params_for" do
63
63
  Route.stub(:routes).and_return([{
64
64
  :id => 0,
65
65
  :path => '/dummy/:dummy_id'
@@ -68,12 +68,12 @@ module ApiTaster
68
68
  :path => 'a_non_existing_dummy',
69
69
  :verb => 'get'
70
70
  }])
71
- Route.inputs[0] = [{ :dummy_id => 1, :hello => 'world' }]
71
+ Route.supplied_params[0] = [{ :dummy_id => 1, :hello => 'world' }]
72
72
 
73
- Route.inputs_for(Route.find(999)).should have_key(:undefined)
73
+ Route.params_for(Route.find(999)).should have_key(:undefined)
74
74
 
75
75
  2.times do
76
- Route.inputs_for(Route.find(0)).should == [{
76
+ Route.params_for(Route.find(0)).should == [{
77
77
  :url_params => { :dummy_id => 1 },
78
78
  :post_params => { :hello => 'world' }
79
79
  }]
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
4
+ version: 0.4.5
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-22 00:00:00.000000000 Z
12
+ date: 2012-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -354,7 +354,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
354
354
  version: '0'
355
355
  segments:
356
356
  - 0
357
- hash: -1654334421203811347
357
+ hash: 4235987413395832386
358
358
  required_rubygems_version: !ruby/object:Gem::Requirement
359
359
  none: false
360
360
  requirements:
@@ -363,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
363
363
  version: '0'
364
364
  segments:
365
365
  - 0
366
- hash: -1654334421203811347
366
+ hash: 4235987413395832386
367
367
  requirements: []
368
368
  rubyforge_project:
369
369
  rubygems_version: 1.8.24