Class: GdsApi::Router

Inherits:
Base
  • Object
show all
Defined in:
lib/gds_api/router.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#client, #create_client, #get_list!, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Instance Method Details

#add_backend(id, url) ⇒ Object



11
12
13
# File 'lib/gds_api/router.rb', line 11

def add_backend(id, url)
  put_json!("#{endpoint}/backends/#{CGI.escape(id)}", :backend => {:backend_url => url})
end

#add_gone_route(path, type, options = {}) ⇒ Object



41
42
43
44
45
# File 'lib/gds_api/router.rb', line 41

def add_gone_route(path, type, options = {})
  response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "gone"})
  commit_routes if options[:commit]
  response
end

#add_redirect_route(path, type, destination, redirect_type = "permanent", options = {}) ⇒ Object



34
35
36
37
38
39
# File 'lib/gds_api/router.rb', line 34

def add_redirect_route(path, type, destination, redirect_type = "permanent", options = {})
  response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "redirect",
            :redirect_to => destination, :redirect_type => redirect_type, :segments_mode => options[:segments_mode]})
  commit_routes if options[:commit]
  response
end

#add_route(path, type, backend_id, options = {}) ⇒ Object



28
29
30
31
32
# File 'lib/gds_api/router.rb', line 28

def add_route(path, type, backend_id, options = {})
  response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "backend", :backend_id => backend_id})
  commit_routes if options[:commit]
  response
end

#commit_routesObject



59
60
61
# File 'lib/gds_api/router.rb', line 59

def commit_routes
  post_json!("#{endpoint}/routes/commit", {})
end

#delete_backend(id) ⇒ Object



15
16
17
# File 'lib/gds_api/router.rb', line 15

def delete_backend(id)
  delete_json!("#{endpoint}/backends/#{CGI.escape(id)}")
end

#delete_route(path, options_or_deprecated_type = {}, deprecated_options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gds_api/router.rb', line 47

def delete_route(path, options_or_deprecated_type = {}, deprecated_options = {})
  if options_or_deprecated_type.is_a?(String)
    $stderr.puts "DEPRECATION WARNING: passing type to GdsApi::Router#delete_route is deprecated and will be removed in a future version. Caller: #{caller[0]}"
    options = deprecated_options
  else
    options = options_or_deprecated_type
  end
  response = delete_json!("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}")
  commit_routes if options[:commit]
  response
end

#get_backend(id) ⇒ Object

Backends



7
8
9
# File 'lib/gds_api/router.rb', line 7

def get_backend(id)
  get_json("#{endpoint}/backends/#{CGI.escape(id)}")
end

#get_route(path, type = nil) ⇒ Object

Routes



21
22
23
24
25
26
# File 'lib/gds_api/router.rb', line 21

def get_route(path, type = nil)
  if type
    $stderr.puts "DEPRECATION WARNING: passing type to GdsApi::Router#get_route is deprecated and will be removed in a future version. Caller: #{caller[0]}"
  end
  get_json("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}")
end