gds-api-adapters 7.17.1 → 7.18.0
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/lib/gds_api/router.rb +16 -6
- data/lib/gds_api/rummager.rb +2 -2
- data/lib/gds_api/version.rb +1 -1
- data/test/router_test.rb +70 -0
- data/test/rummager_test.rb +12 -16
- metadata +4 -4
data/lib/gds_api/router.rb
CHANGED
@@ -23,16 +23,26 @@ class GdsApi::Router < GdsApi::Base
|
|
23
23
|
get_json("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}&route_type=#{CGI.escape(type)}")
|
24
24
|
end
|
25
25
|
|
26
|
-
def add_route(path, type, backend_id)
|
27
|
-
put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "backend", :backend_id => backend_id})
|
26
|
+
def add_route(path, type, backend_id, options = {})
|
27
|
+
response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "backend", :backend_id => backend_id})
|
28
|
+
commit_routes unless options[:skip_commit]
|
29
|
+
response
|
28
30
|
end
|
29
31
|
|
30
|
-
def add_redirect_route(path, type, destination, redirect_type = "permanent")
|
31
|
-
put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "redirect",
|
32
|
+
def add_redirect_route(path, type, destination, redirect_type = "permanent", options = {})
|
33
|
+
response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "redirect",
|
32
34
|
:redirect_to => destination, :redirect_type => redirect_type})
|
35
|
+
commit_routes unless options[:skip_commit]
|
36
|
+
response
|
33
37
|
end
|
34
38
|
|
35
|
-
def delete_route(path, type)
|
36
|
-
delete_json!("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}&route_type=#{CGI.escape(type)}")
|
39
|
+
def delete_route(path, type, options = {})
|
40
|
+
response = delete_json!("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}&route_type=#{CGI.escape(type)}")
|
41
|
+
commit_routes unless options[:skip_commit]
|
42
|
+
response
|
43
|
+
end
|
44
|
+
|
45
|
+
def commit_routes
|
46
|
+
post_json!("#{endpoint}/routes/commit", {})
|
37
47
|
end
|
38
48
|
end
|
data/lib/gds_api/rummager.rb
CHANGED
@@ -5,12 +5,12 @@ module GdsApi
|
|
5
5
|
class Rummager < Base
|
6
6
|
|
7
7
|
def search(query, extra_params={})
|
8
|
-
|
8
|
+
raise ArgumentError.new("Query cannot be blank") if query.nil? || query.strip.empty?
|
9
9
|
get_json!(search_url(:search, query, extra_params))
|
10
10
|
end
|
11
11
|
|
12
12
|
def advanced_search(args)
|
13
|
-
|
13
|
+
raise ArgumentError.new("Args cannot be blank") if args.nil? || args.empty?
|
14
14
|
request_path = "#{base_url}/advanced_search?#{Rack::Utils.build_nested_query(args)}"
|
15
15
|
get_json!(request_path)
|
16
16
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/test/router_test.rb
CHANGED
@@ -140,6 +140,11 @@ describe GdsApi::Router do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
describe "managing routes" do
|
143
|
+
before :each do
|
144
|
+
@commit_req = WebMock.stub_request(:post, "#{@base_api_url}/routes/commit").
|
145
|
+
to_return(:status => 200, :body => "Routers updated")
|
146
|
+
end
|
147
|
+
|
143
148
|
describe "fetching a route" do
|
144
149
|
it "should return the route details" do
|
145
150
|
route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo"}
|
@@ -152,6 +157,7 @@ describe GdsApi::Router do
|
|
152
157
|
assert_equal "foo", response.backend_id
|
153
158
|
|
154
159
|
assert_requested(req)
|
160
|
+
assert_not_requested(@commit_req)
|
155
161
|
end
|
156
162
|
|
157
163
|
it "should return nil if nothing found" do
|
@@ -163,6 +169,7 @@ describe GdsApi::Router do
|
|
163
169
|
assert_nil response
|
164
170
|
|
165
171
|
assert_requested(req)
|
172
|
+
assert_not_requested(@commit_req)
|
166
173
|
end
|
167
174
|
|
168
175
|
it "should escape the params" do
|
@@ -176,6 +183,7 @@ describe GdsApi::Router do
|
|
176
183
|
assert_nil response
|
177
184
|
|
178
185
|
assert_requested(req)
|
186
|
+
assert_not_requested(@commit_req)
|
179
187
|
end
|
180
188
|
end
|
181
189
|
|
@@ -191,6 +199,17 @@ describe GdsApi::Router do
|
|
191
199
|
assert_equal "foo", response.backend_id
|
192
200
|
|
193
201
|
assert_requested(req)
|
202
|
+
assert_requested(@commit_req)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should not commit the routes when asked not to" do
|
206
|
+
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
207
|
+
to_return(:status => 201, :body => {}.to_json, :headers => {"Content-type" => "application/json"})
|
208
|
+
|
209
|
+
@api.add_route("/foo", "exact", "foo", :skip_commit => true)
|
210
|
+
|
211
|
+
assert_requested(req)
|
212
|
+
assert_not_requested(@commit_req)
|
194
213
|
end
|
195
214
|
|
196
215
|
it "should raise an error if creating/updating the route fails" do
|
@@ -213,6 +232,7 @@ describe GdsApi::Router do
|
|
213
232
|
assert_equal response_data, e.error_details
|
214
233
|
|
215
234
|
assert_requested(req)
|
235
|
+
assert_not_requested(@commit_req)
|
216
236
|
end
|
217
237
|
end
|
218
238
|
|
@@ -228,6 +248,7 @@ describe GdsApi::Router do
|
|
228
248
|
assert_equal "/bar", response.redirect_to
|
229
249
|
|
230
250
|
assert_requested(req)
|
251
|
+
assert_requested(@commit_req)
|
231
252
|
end
|
232
253
|
|
233
254
|
it "should allow creating/updating a temporary redirect route" do
|
@@ -241,6 +262,17 @@ describe GdsApi::Router do
|
|
241
262
|
assert_equal "/bar", response.redirect_to
|
242
263
|
|
243
264
|
assert_requested(req)
|
265
|
+
assert_requested(@commit_req)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should not commit the routes when asked not to" do
|
269
|
+
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
|
270
|
+
to_return(:status => 201, :body =>{}.to_json, :headers => {"Content-type" => "application/json"})
|
271
|
+
|
272
|
+
@api.add_redirect_route("/foo", "exact", "/bar", "temporary", :skip_commit => true)
|
273
|
+
|
274
|
+
assert_requested(req)
|
275
|
+
assert_not_requested(@commit_req)
|
244
276
|
end
|
245
277
|
|
246
278
|
it "should raise an error if creating/updating the redirect route fails" do
|
@@ -263,6 +295,7 @@ describe GdsApi::Router do
|
|
263
295
|
assert_equal response_data, e.error_details
|
264
296
|
|
265
297
|
assert_requested(req)
|
298
|
+
assert_not_requested(@commit_req)
|
266
299
|
end
|
267
300
|
end
|
268
301
|
|
@@ -278,6 +311,18 @@ describe GdsApi::Router do
|
|
278
311
|
assert_equal "foo", response.backend_id
|
279
312
|
|
280
313
|
assert_requested(req)
|
314
|
+
assert_requested(@commit_req)
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should not commit the routes when asked not to" do
|
318
|
+
req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
|
319
|
+
with(:query => {"incoming_path" => "/foo", "route_type" => "exact"}).
|
320
|
+
to_return(:status => 200, :body => {}.to_json, :headers => {"Content-type" => "application/json"})
|
321
|
+
|
322
|
+
@api.delete_route("/foo", "exact", :skip_commit => true)
|
323
|
+
|
324
|
+
assert_requested(req)
|
325
|
+
assert_not_requested(@commit_req)
|
281
326
|
end
|
282
327
|
|
283
328
|
it "should raise HTTPNotFound if nothing found" do
|
@@ -296,6 +341,7 @@ describe GdsApi::Router do
|
|
296
341
|
assert_equal 404, e.code
|
297
342
|
|
298
343
|
assert_requested(req)
|
344
|
+
assert_not_requested(@commit_req)
|
299
345
|
end
|
300
346
|
|
301
347
|
it "should escape the params" do
|
@@ -313,5 +359,29 @@ describe GdsApi::Router do
|
|
313
359
|
assert_requested(req)
|
314
360
|
end
|
315
361
|
end
|
362
|
+
|
363
|
+
describe "committing the routes" do
|
364
|
+
it "should allow committing the routes" do
|
365
|
+
@api.commit_routes
|
366
|
+
|
367
|
+
assert_requested(@commit_req)
|
368
|
+
end
|
369
|
+
|
370
|
+
it "should raise an error if committing the routes fails" do
|
371
|
+
req = WebMock.stub_request(:post, "#{@base_api_url}/routes/commit").
|
372
|
+
to_return(:status => 500, :body => "Failed to update all routers")
|
373
|
+
|
374
|
+
e = nil
|
375
|
+
begin
|
376
|
+
@api.commit_routes
|
377
|
+
rescue GdsApi::HTTPErrorResponse => ex
|
378
|
+
e = ex
|
379
|
+
end
|
380
|
+
|
381
|
+
refute_nil e
|
382
|
+
assert_equal 500, e.code
|
383
|
+
assert_equal "Failed to update all routers", e.message
|
384
|
+
end
|
385
|
+
end
|
316
386
|
end
|
317
387
|
end
|
data/test/rummager_test.rb
CHANGED
@@ -37,17 +37,15 @@ describe GdsApi::Rummager do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should return an empty set of results without making request if query is empty" do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert_not_requested :get, /example.com/
|
40
|
+
assert_raises(ArgumentError) do
|
41
|
+
GdsApi::Rummager.new("http://example.com").search("")
|
42
|
+
end
|
44
43
|
end
|
45
44
|
|
46
45
|
it "should return an empty set of results without making request if query is nil" do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
assert_not_requested :get, /example.com/
|
46
|
+
assert_raises(ArgumentError) do
|
47
|
+
GdsApi::Rummager.new("http://example.com").search(nil)
|
48
|
+
end
|
51
49
|
end
|
52
50
|
|
53
51
|
it "should request the search results in JSON format" do
|
@@ -116,17 +114,15 @@ describe GdsApi::Rummager do
|
|
116
114
|
end
|
117
115
|
|
118
116
|
it "#advanced_search should return an empty set of results without making request if arguments are empty" do
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
assert_not_requested :get, /example.com/
|
117
|
+
assert_raises(ArgumentError) do
|
118
|
+
GdsApi::Rummager.new("http://example.com").advanced_search({})
|
119
|
+
end
|
123
120
|
end
|
124
121
|
|
125
122
|
it "#advanced_search should return an empty set of results without making request if arguments is nil" do
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
assert_not_requested :get, /example.com/
|
123
|
+
assert_raises(ArgumentError) do
|
124
|
+
results = GdsApi::Rummager.new("http://example.com").advanced_search(nil)
|
125
|
+
end
|
130
126
|
end
|
131
127
|
|
132
128
|
it "#advanced_search should request the search results in JSON format" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.18.0
|
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: 2013-11-
|
12
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plek
|
@@ -340,7 +340,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
340
340
|
version: '0'
|
341
341
|
segments:
|
342
342
|
- 0
|
343
|
-
hash:
|
343
|
+
hash: 471718950989814646
|
344
344
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
345
345
|
none: false
|
346
346
|
requirements:
|
@@ -349,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
349
349
|
version: '0'
|
350
350
|
segments:
|
351
351
|
- 0
|
352
|
-
hash:
|
352
|
+
hash: 471718950989814646
|
353
353
|
requirements: []
|
354
354
|
rubyforge_project:
|
355
355
|
rubygems_version: 1.8.23
|