api_taster 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f3a1189530fd63c3d2e25cbbee312fe3a8e29c5
4
+ data.tar.gz: 468045d8574f04e57dcd2ede43ab1618f714a1a8
5
+ SHA512:
6
+ metadata.gz: 9ea4a76b1b9072f6bf3873cd598022b2122a5c6d0a9cae3103ede407e414a07caeb585a32d0d3933cbae9c2d35d2e30fbd56011399235b0f1f26380c2e233aa1
7
+ data.tar.gz: f5a28623c9bf2180cbd52ecfb11efe250b78922dbca8a4690e83dcc0d7c77db542b85470a608327f6b656a7aebc71a05f7151e65de202f43137d37499ed6e9c2
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.3
4
+ - 2.0.0
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.files = `git ls-files`.split($\)
15
15
  s.test_files = Dir["spec/**/*"]
16
16
 
17
- s.add_dependency 'rails', '>= 3.1.0'
17
+ s.add_dependency 'rails', '~> 3.2.0'
18
18
  s.add_dependency 'jquery-rails'
19
19
  s.add_dependency 'sass-rails'
20
20
  s.add_dependency 'bootstrap-sass', '~> 2.1'
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_development_dependency 'rake'
25
25
  s.add_development_dependency 'simplecov'
26
- s.add_development_dependency 'rspec-rails'
26
+ s.add_development_dependency 'rspec-rails', '~> 2.13.2'
27
27
  s.add_development_dependency 'pry'
28
28
  s.add_development_dependency 'thin'
29
29
  end
@@ -119,8 +119,7 @@ jQuery(function($) {
119
119
  window.ajax = $.ajax({
120
120
  url: ApiTaster.getSubmitUrl($form),
121
121
  type: $form.attr('method'),
122
- data: $form.serialize(),
123
- dataType: 'xml'
122
+ data: $form.serialize()
124
123
  }).complete(onComplete);
125
124
 
126
125
  ApiTaster.lastRequest = {};
@@ -6,13 +6,17 @@ require 'api_taster/engine'
6
6
  require 'api_taster/route'
7
7
  require 'api_taster/mapper'
8
8
  require 'api_taster/form_builder'
9
+ require 'api_taster/route_collector'
9
10
 
10
11
  module ApiTaster
11
12
  mattr_accessor :global_params
12
13
  self.global_params = {}
13
14
 
15
+ mattr_accessor :route_path
16
+ self.route_path = "#{Rails.root}/lib/api_tasters"
17
+
14
18
  def self.routes(&block)
15
- Route.mappings = Proc.new { block }
19
+ ApiTaster::RouteCollector.routes << block
16
20
  end
17
21
 
18
22
  class Exception < ::Exception; end
@@ -26,15 +26,15 @@ module ApiTaster
26
26
 
27
27
  new_parent_labels = parent_labels.clone << label
28
28
 
29
- if value.is_a?(Hash)
29
+ case value
30
+ when Hash
30
31
  add_legend_to_buffer(parent_labels, label)
31
-
32
32
  add_to_buffer(value, new_parent_labels)
33
- elsif value.is_a?(Array)
33
+ when Array
34
34
  value.each do |v|
35
- if v.is_a?(Hash)
35
+ case v
36
+ when Hash
36
37
  add_legend_to_buffer(parent_labels, label)
37
-
38
38
  add_to_buffer(v, parent_labels.clone << "#{label}[]")
39
39
  else
40
40
  add_element_to_buffer(parent_labels, "#{label}[]", v)
@@ -9,8 +9,7 @@ module ApiTaster
9
9
  cattr_accessor :metadata
10
10
 
11
11
  class << self
12
-
13
- def map_routes
12
+ def map_routes(path = ApiTaster.route_path)
14
13
  self.route_set = Rails.application.routes
15
14
  self.supplied_params = {}
16
15
  self.obsolete_definitions = []
@@ -20,7 +19,8 @@ module ApiTaster
20
19
  normalise_routes!
21
20
 
22
21
  begin
23
- Mapper.instance_eval(&self.mappings.call)
22
+ ApiTaster::RouteCollector.collect(path)
23
+ Mapper.instance_eval(&self.mappings)
24
24
  rescue
25
25
  Route.mappings = {}
26
26
  end
@@ -35,11 +35,12 @@ module ApiTaster
35
35
  end
36
36
 
37
37
  route_set.routes.each do |route|
38
- next if route.app.is_a?(ActionDispatch::Routing::Mapper::Constraints)
39
38
  next if route.app.is_a?(Sprockets::Environment)
40
39
  next if route.app == ApiTaster::Engine
41
40
 
42
- if (rack_app = discover_rack_app(route.app)) && rack_app.respond_to?(:routes)
41
+ rack_app = discover_rack_app(route.app)
42
+
43
+ if rack_app && rack_app.respond_to?(:routes) && rack_app.routes.respond_to?(:routes)
43
44
  rack_app.routes.routes.each do |rack_route|
44
45
  self.routes << normalise_route(rack_route, route.path.spec)
45
46
  end
@@ -0,0 +1,15 @@
1
+ module ApiTaster
2
+ class RouteCollector
3
+ cattr_accessor :routes
4
+ self.routes = []
5
+
6
+ def self.collect(path)
7
+ self.routes = []
8
+ Dir["#{path}/**/*.rb"].each { |file| load(file) }
9
+
10
+ Route.mappings = Proc.new do
11
+ RouteCollector.routes.each { |route| instance_eval(&route) }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module ApiTaster
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1,4 @@
1
+ ApiTaster.routes do
2
+ post '/dummy_users'
3
+ post '/dummy_users', { :hello => 'world' }, { :meta => 'data' }
4
+ end
@@ -0,0 +1,3 @@
1
+ ApiTaster.routes do
2
+ get '/dummy_users/:id', :id => 1
3
+ end
@@ -0,0 +1,3 @@
1
+ ApiTaster.routes do
2
+ get '/dummy_users/:id', :id => 1
3
+ end
@@ -0,0 +1,10 @@
1
+ ApiTaster.routes do
2
+ get '/dummy_route'
3
+ desc "Dummy user ID"
4
+ get '/dummy_users/:id', :id => 1
5
+ post '/dummy_users'
6
+ post '/dummy_users', { :hello => 'world' }, { :meta => 'data' }
7
+ put '/dummy_users/:id', :id => 2
8
+ delete '/dummy_users/:id', :id => 3
9
+ patch '/dummy_users/:id', :id => 4
10
+ end
@@ -0,0 +1,4 @@
1
+ ApiTaster.routes do
2
+ post '/dummy_users'
3
+ post '/dummy_users', { :hello => 'world' }, { :meta => 'data' }
4
+ end
@@ -0,0 +1,3 @@
1
+ ApiTaster.routes do
2
+ get '/dummy_users/:id', :id => 42
3
+ end
@@ -2,19 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  module ApiTaster
4
4
  describe Mapper do
5
+ context "#global_params" do
6
+ before(:all) do
7
+ ApiTaster.global_params = { :foo => 'bar' }
8
+
9
+ Route.map_routes "#{Rails.root}/lib/api_tasters/global_params"
10
+ end
11
+
12
+ it "merges params" do
13
+ route = Route.find_by_verb_and_path(:get, '/dummy_users/:id')
14
+
15
+ Route.supplied_params[route[:id]].should == [{ :foo => 'bar', :id => 1 }]
16
+ end
17
+ end
18
+
5
19
  context "non-existing routes" do
6
20
  before(:all) do
21
+ ApiTaster.global_params = {}
7
22
  routes = ActionDispatch::Routing::RouteSet.new
8
23
  routes.draw do
9
24
  get '/awesome_route' => 'awesome#route'
10
25
  end
11
26
 
12
- ApiTaster.routes do
13
- get '/dummy_route'
14
- end
15
-
16
27
  Route.route_set = routes
17
- Route.map_routes
28
+ Route.map_routes "#{Rails.root}/lib/api_tasters/mapper"
18
29
  end
19
30
 
20
31
  it "records obsolete definitions" do
@@ -28,38 +39,8 @@ module ApiTaster
28
39
  member { map_method :patch, :update }
29
40
  end
30
41
  end
31
- end
32
-
33
- context "#global_params" do
34
- before(:all) do
35
- ApiTaster.global_params = { :foo => 'bar' }
36
-
37
- ApiTaster.routes do
38
- get '/dummy_users/:id', :id => 1
39
- end
40
-
41
- Route.map_routes
42
- end
43
-
44
- it "merges params" do
45
- route = Route.find_by_verb_and_path(:get, '/dummy_users/:id')
46
-
47
- Route.supplied_params[route[:id]].should == [{ :foo => 'bar', :id => 1 }]
48
- end
49
- end
50
-
51
- before(:all) do
52
- ApiTaster.routes do
53
- desc "Dummy user ID"
54
- get '/dummy_users/:id', :id => 1
55
- post '/dummy_users'
56
- post '/dummy_users', { :hello => 'world' }, { :meta => 'data' }
57
- put '/dummy_users/:id', :id => 2
58
- delete '/dummy_users/:id', :id => 3
59
- patch '/dummy_users/:id', :id => 4
60
- end
61
42
 
62
- Route.map_routes
43
+ Route.map_routes "#{Rails.root}/lib/api_tasters/mapper"
63
44
  end
64
45
 
65
46
  it "gets users" do
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module ApiTaster
4
+ describe RouteCollector do
5
+ before(:all) do
6
+ Rails.application.routes.draw do
7
+ resources :dummy_users
8
+ end
9
+ Route.map_routes "#{Rails.root}/lib/api_tasters/route_collector"
10
+ end
11
+
12
+ it "gets users" do
13
+ route = Route.find_by_verb_and_path(:get, '/dummy_users/:id')
14
+ Route.supplied_params[route[:id]].should == [{ :id => 42 }]
15
+ end
16
+
17
+ it "posts a new user" do
18
+ route = Route.find_by_verb_and_path(:post, '/dummy_users')
19
+ Route.supplied_params[route[:id]].should == [{}, { :hello => 'world' }]
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,192 +1,169 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_taster
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.6.0
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Fred Wu
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-28 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: 3.1.0
20
- none: false
21
- prerelease: false
22
14
  name: rails
23
15
  requirement: !ruby/object:Gem::Requirement
24
16
  requirements:
25
- - - ! '>='
17
+ - - ~>
26
18
  - !ruby/object:Gem::Version
27
- version: 3.1.0
28
- none: false
19
+ version: 3.2.0
29
20
  type: :runtime
30
- - !ruby/object:Gem::Dependency
21
+ prerelease: false
31
22
  version_requirements: !ruby/object:Gem::Requirement
32
23
  requirements:
33
- - - ! '>='
24
+ - - ~>
34
25
  - !ruby/object:Gem::Version
35
- version: '0'
36
- none: false
37
- prerelease: false
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
38
28
  name: jquery-rails
39
29
  requirement: !ruby/object:Gem::Requirement
40
30
  requirements:
41
- - - ! '>='
31
+ - - '>='
42
32
  - !ruby/object:Gem::Version
43
33
  version: '0'
44
- none: false
45
34
  type: :runtime
46
- - !ruby/object:Gem::Dependency
35
+ prerelease: false
47
36
  version_requirements: !ruby/object:Gem::Requirement
48
37
  requirements:
49
- - - ! '>='
38
+ - - '>='
50
39
  - !ruby/object:Gem::Version
51
40
  version: '0'
52
- none: false
53
- prerelease: false
41
+ - !ruby/object:Gem::Dependency
54
42
  name: sass-rails
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
- - - ! '>='
45
+ - - '>='
58
46
  - !ruby/object:Gem::Version
59
47
  version: '0'
60
- none: false
61
48
  type: :runtime
62
- - !ruby/object:Gem::Dependency
49
+ prerelease: false
63
50
  version_requirements: !ruby/object:Gem::Requirement
64
51
  requirements:
65
- - - ~>
52
+ - - '>='
66
53
  - !ruby/object:Gem::Version
67
- version: '2.1'
68
- none: false
69
- prerelease: false
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
70
56
  name: bootstrap-sass
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ~>
74
60
  - !ruby/object:Gem::Version
75
61
  version: '2.1'
76
- none: false
77
62
  type: :runtime
78
- - !ruby/object:Gem::Dependency
63
+ prerelease: false
79
64
  version_requirements: !ruby/object:Gem::Requirement
80
65
  requirements:
81
- - - ! '>='
66
+ - - ~>
82
67
  - !ruby/object:Gem::Version
83
- version: '0'
84
- none: false
85
- prerelease: false
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
86
70
  name: redcarpet
87
71
  requirement: !ruby/object:Gem::Requirement
88
72
  requirements:
89
- - - ! '>='
73
+ - - '>='
90
74
  - !ruby/object:Gem::Version
91
75
  version: '0'
92
- none: false
93
76
  type: :runtime
94
- - !ruby/object:Gem::Dependency
77
+ prerelease: false
95
78
  version_requirements: !ruby/object:Gem::Requirement
96
79
  requirements:
97
- - - ~>
80
+ - - '>='
98
81
  - !ruby/object:Gem::Version
99
- version: '1.0'
100
- none: false
101
- prerelease: false
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
102
84
  name: remotipart
103
85
  requirement: !ruby/object:Gem::Requirement
104
86
  requirements:
105
87
  - - ~>
106
88
  - !ruby/object:Gem::Version
107
89
  version: '1.0'
108
- none: false
109
90
  type: :runtime
110
- - !ruby/object:Gem::Dependency
91
+ prerelease: false
111
92
  version_requirements: !ruby/object:Gem::Requirement
112
93
  requirements:
113
- - - ! '>='
94
+ - - ~>
114
95
  - !ruby/object:Gem::Version
115
- version: '0'
116
- none: false
117
- prerelease: false
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
118
98
  name: rake
119
99
  requirement: !ruby/object:Gem::Requirement
120
100
  requirements:
121
- - - ! '>='
101
+ - - '>='
122
102
  - !ruby/object:Gem::Version
123
103
  version: '0'
124
- none: false
125
104
  type: :development
126
- - !ruby/object:Gem::Dependency
105
+ prerelease: false
127
106
  version_requirements: !ruby/object:Gem::Requirement
128
107
  requirements:
129
- - - ! '>='
108
+ - - '>='
130
109
  - !ruby/object:Gem::Version
131
110
  version: '0'
132
- none: false
133
- prerelease: false
111
+ - !ruby/object:Gem::Dependency
134
112
  name: simplecov
135
113
  requirement: !ruby/object:Gem::Requirement
136
114
  requirements:
137
- - - ! '>='
115
+ - - '>='
138
116
  - !ruby/object:Gem::Version
139
117
  version: '0'
140
- none: false
141
118
  type: :development
142
- - !ruby/object:Gem::Dependency
119
+ prerelease: false
143
120
  version_requirements: !ruby/object:Gem::Requirement
144
121
  requirements:
145
- - - ! '>='
122
+ - - '>='
146
123
  - !ruby/object:Gem::Version
147
124
  version: '0'
148
- none: false
149
- prerelease: false
125
+ - !ruby/object:Gem::Dependency
150
126
  name: rspec-rails
151
127
  requirement: !ruby/object:Gem::Requirement
152
128
  requirements:
153
- - - ! '>='
129
+ - - ~>
154
130
  - !ruby/object:Gem::Version
155
- version: '0'
156
- none: false
131
+ version: 2.13.2
157
132
  type: :development
158
- - !ruby/object:Gem::Dependency
133
+ prerelease: false
159
134
  version_requirements: !ruby/object:Gem::Requirement
160
135
  requirements:
161
- - - ! '>='
136
+ - - ~>
162
137
  - !ruby/object:Gem::Version
163
- version: '0'
164
- none: false
165
- prerelease: false
138
+ version: 2.13.2
139
+ - !ruby/object:Gem::Dependency
166
140
  name: pry
167
141
  requirement: !ruby/object:Gem::Requirement
168
142
  requirements:
169
- - - ! '>='
143
+ - - '>='
170
144
  - !ruby/object:Gem::Version
171
145
  version: '0'
172
- none: false
173
146
  type: :development
174
- - !ruby/object:Gem::Dependency
147
+ prerelease: false
175
148
  version_requirements: !ruby/object:Gem::Requirement
176
149
  requirements:
177
- - - ! '>='
150
+ - - '>='
178
151
  - !ruby/object:Gem::Version
179
152
  version: '0'
180
- none: false
181
- prerelease: false
153
+ - !ruby/object:Gem::Dependency
182
154
  name: thin
183
155
  requirement: !ruby/object:Gem::Requirement
184
156
  requirements:
185
- - - ! '>='
157
+ - - '>='
186
158
  - !ruby/object:Gem::Version
187
159
  version: '0'
188
- none: false
189
160
  type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
190
167
  description: A quick and easy way to visually test out your application's API.
191
168
  email:
192
169
  - ifredwu@gmail.com
@@ -229,11 +206,14 @@ files:
229
206
  - lib/api_taster/form_builder.rb
230
207
  - lib/api_taster/mapper.rb
231
208
  - lib/api_taster/route.rb
209
+ - lib/api_taster/route_collector.rb
232
210
  - lib/api_taster/version.rb
233
211
  - lib/tasks/api_taster_tasks.rake
234
212
  - script/rails
235
213
  - spec/controllers/api_taster/routes_controller_spec.rb
236
214
  - spec/dummy/Rakefile
215
+ - spec/dummy/api_tasters/test1.rb
216
+ - spec/dummy/api_tasters/test2.rb
237
217
  - spec/dummy/app/assets/javascripts/application.js
238
218
  - spec/dummy/app/assets/stylesheets/application.css
239
219
  - spec/dummy/app/controllers/application_controller.rb
@@ -257,12 +237,17 @@ files:
257
237
  - spec/dummy/config/initializers/wrap_parameters.rb
258
238
  - spec/dummy/config/locales/en.yml
259
239
  - spec/dummy/config/routes.rb
240
+ - spec/dummy/lib/api_tasters/global_params/test.rb
241
+ - spec/dummy/lib/api_tasters/mapper/test1.rb
242
+ - spec/dummy/lib/api_tasters/route_collector/test1.rb
243
+ - spec/dummy/lib/api_tasters/route_collector/test2.rb
260
244
  - spec/dummy/lib/assets/.gitkeep
261
245
  - spec/dummy/log/.gitkeep
262
246
  - spec/dummy/script/rails
263
247
  - spec/form_builder_spec.rb
264
248
  - spec/helpers/api_taster/application_helper_spec.rb
265
249
  - spec/mapper_spec.rb
250
+ - spec/route_collector_spec.rb
266
251
  - spec/route_spec.rb
267
252
  - spec/spec_helper.rb
268
253
  - spec/dummy/log/development.log
@@ -485,39 +470,33 @@ files:
485
470
  - spec/dummy/tmp/cache/sass/c4c1688f5dbdaaa3941b73da0a6005bdab08bb92/_variables.scssc
486
471
  - spec/dummy/tmp/cache/sass/c4c1688f5dbdaaa3941b73da0a6005bdab08bb92/_wells.scssc
487
472
  - spec/dummy/tmp/cache/sass/d27ff1c5f2e254072ed81f036be53e0b7a828e6c/bootstrap.scssc
488
- - spec/dummy/tmp/pids/server.pid
489
473
  homepage: https://github.com/fredwu/api_taster
490
474
  licenses: []
475
+ metadata: {}
491
476
  post_install_message:
492
477
  rdoc_options: []
493
478
  require_paths:
494
479
  - lib
495
480
  required_ruby_version: !ruby/object:Gem::Requirement
496
481
  requirements:
497
- - - ! '>='
482
+ - - '>='
498
483
  - !ruby/object:Gem::Version
499
484
  version: '0'
500
- segments:
501
- - 0
502
- hash: -2826962051612884184
503
- none: false
504
485
  required_rubygems_version: !ruby/object:Gem::Requirement
505
486
  requirements:
506
- - - ! '>='
487
+ - - '>='
507
488
  - !ruby/object:Gem::Version
508
489
  version: '0'
509
- segments:
510
- - 0
511
- hash: -2826962051612884184
512
- none: false
513
490
  requirements: []
514
491
  rubyforge_project:
515
- rubygems_version: 1.8.24
492
+ rubygems_version: 2.0.3
516
493
  signing_key:
517
- specification_version: 3
494
+ specification_version: 4
518
495
  summary: A quick and easy way to visually test out your application's API.
519
496
  test_files:
520
497
  - spec/controllers/api_taster/routes_controller_spec.rb
498
+ - spec/dummy/api_tasters/test1.rb
499
+ - spec/dummy/api_tasters/test2.rb
521
500
  - spec/dummy/app/assets/javascripts/application.js
522
501
  - spec/dummy/app/assets/stylesheets/application.css
523
502
  - spec/dummy/app/controllers/application_controller.rb
@@ -539,6 +518,10 @@ test_files:
539
518
  - spec/dummy/config/locales/en.yml
540
519
  - spec/dummy/config/routes.rb
541
520
  - spec/dummy/config.ru
521
+ - spec/dummy/lib/api_tasters/global_params/test.rb
522
+ - spec/dummy/lib/api_tasters/mapper/test1.rb
523
+ - spec/dummy/lib/api_tasters/route_collector/test1.rb
524
+ - spec/dummy/lib/api_tasters/route_collector/test2.rb
542
525
  - spec/dummy/log/development.log
543
526
  - spec/dummy/log/test.log
544
527
  - spec/dummy/Rakefile
@@ -761,9 +744,9 @@ test_files:
761
744
  - spec/dummy/tmp/cache/sass/c4c1688f5dbdaaa3941b73da0a6005bdab08bb92/_variables.scssc
762
745
  - spec/dummy/tmp/cache/sass/c4c1688f5dbdaaa3941b73da0a6005bdab08bb92/_wells.scssc
763
746
  - spec/dummy/tmp/cache/sass/d27ff1c5f2e254072ed81f036be53e0b7a828e6c/bootstrap.scssc
764
- - spec/dummy/tmp/pids/server.pid
765
747
  - spec/form_builder_spec.rb
766
748
  - spec/helpers/api_taster/application_helper_spec.rb
767
749
  - spec/mapper_spec.rb
750
+ - spec/route_collector_spec.rb
768
751
  - spec/route_spec.rb
769
752
  - spec/spec_helper.rb