Class: GdsApi::ContentStore::RedirectResolver

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_item, request_path, request_query = "") ⇒ RedirectResolver


36
37
38
39
40
# File 'lib/gds_api/content_store.rb', line 36

def initialize(content_item, request_path, request_query = "")
  @content_item = content_item
  @request_path = request_path
  @request_query = request_query.to_s
end

Class Method Details

.call(*args) ⇒ Object


42
43
44
# File 'lib/gds_api/content_store.rb', line 42

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject

Raises:


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gds_api/content_store.rb', line 46

def call
  redirect = redirect_for_path(request_path)
  raise UnresolvedRedirect, "Could not find a matching redirect" unless redirect

  destination_uri = URI.parse(
    resolve_destination(redirect, request_path, request_query)
  )

  url = if destination_uri.absolute?
          destination_uri.to_s
        else
          "#{Plek.new.website_root}#{destination_uri}"
        end

  [url, status_code(redirect)]
end