gds-api-adapters 7.16.1 → 7.17.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,11 @@ class GdsApi::Router < GdsApi::Base
27
27
  put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "backend", :backend_id => backend_id})
28
28
  end
29
29
 
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
+ :redirect_to => destination, :redirect_type => redirect_type})
33
+ end
34
+
30
35
  def delete_route(path, type)
31
36
  delete_json!("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}&route_type=#{CGI.escape(type)}")
32
37
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '7.16.1'
2
+ VERSION = '7.17.0'
3
3
  end
data/test/router_test.rb CHANGED
@@ -195,9 +195,8 @@ describe GdsApi::Router do
195
195
 
196
196
  it "should raise an error if creating/updating the route fails" do
197
197
  route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo"}
198
- response_data = route_data.merge(:errors => {"backend_id" => "does not exist"})
198
+ response_data = route_data.merge("errors" => {"backend_id" => "does not exist"})
199
199
 
200
- response_data = {"backend_id" => "foo", "backend_url" => "ftp://foo.example.com/", "errors" => {"backend_url" => "is not an HTTP URL"}}
201
200
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
202
201
  with(:body => {"route" => route_data}.to_json).
203
202
  to_return(:status => 400, :body => response_data.to_json, :headers => {"Content-type" => "application/json"})
@@ -217,6 +216,56 @@ describe GdsApi::Router do
217
216
  end
218
217
  end
219
218
 
219
+ describe "creating/updating a redirect route" do
220
+ it "should allow creating/updating a redirect route" do
221
+ route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect", "redirect_to" => "/bar", "redirect_type" => "permanent"}
222
+ req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
223
+ with(:body => {"route" => route_data}.to_json).
224
+ to_return(:status => 201, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
225
+
226
+ response = @api.add_redirect_route("/foo", "exact", "/bar")
227
+ assert_equal 201, response.code
228
+ assert_equal "/bar", response.redirect_to
229
+
230
+ assert_requested(req)
231
+ end
232
+
233
+ it "should allow creating/updating a temporary redirect route" do
234
+ route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect", "redirect_to" => "/bar", "redirect_type" => "temporary"}
235
+ req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
236
+ with(:body => {"route" => route_data}.to_json).
237
+ to_return(:status => 201, :body => route_data.to_json, :headers => {"Content-type" => "application/json"})
238
+
239
+ response = @api.add_redirect_route("/foo", "exact", "/bar", "temporary")
240
+ assert_equal 201, response.code
241
+ assert_equal "/bar", response.redirect_to
242
+
243
+ assert_requested(req)
244
+ end
245
+
246
+ it "should raise an error if creating/updating the redirect route fails" do
247
+ route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "redirect", "redirect_to" => "bar", "redirect_type" => "permanent"}
248
+ response_data = route_data.merge("errors" => {"redirect_to" => "is not a valid URL path"})
249
+
250
+ req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
251
+ with(:body => {"route" => route_data}.to_json).
252
+ to_return(:status => 400, :body => response_data.to_json, :headers => {"Content-type" => "application/json"})
253
+
254
+ e = nil
255
+ begin
256
+ @api.add_redirect_route("/foo", "exact", "bar")
257
+ rescue GdsApi::HTTPErrorResponse => ex
258
+ e = ex
259
+ end
260
+
261
+ refute_nil e
262
+ assert_equal 400, e.code
263
+ assert_equal response_data, e.error_details
264
+
265
+ assert_requested(req)
266
+ end
267
+ end
268
+
220
269
  describe "deleting a route" do
221
270
  it "should allow deleting a route" do
222
271
  route_data = {"incoming_path" => "/foo", "route_type" => "exact", "handler" => "backend", "backend_id" => "foo"}
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.16.1
4
+ version: 7.17.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -340,7 +340,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
340
340
  version: '0'
341
341
  segments:
342
342
  - 0
343
- hash: -846499861652440754
343
+ hash: 965842329642647855
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: -846499861652440754
352
+ hash: 965842329642647855
353
353
  requirements: []
354
354
  rubyforge_project:
355
355
  rubygems_version: 1.8.23