Class: GdsApi::PublishingApi::SpecialRoutePublisher

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SpecialRoutePublisher

Returns a new instance of SpecialRoutePublisher.



7
8
9
10
# File 'lib/gds_api/publishing_api/special_route_publisher.rb', line 7

def initialize(options = {})
  @logger = options[:logger] || GdsApi::Base.logger
  @publishing_api = options[:publishing_api] || GdsApi::PublishingApi.new(Plek.find("publishing-api"))
end

Instance Method Details

#publish(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gds_api/publishing_api/special_route_publisher.rb', line 12

def publish(options)
  logger.info("Publishing #{options.fetch(:type)} route #{options.fetch(:base_path)}, routing to #{options.fetch(:rendering_app)}")

  update_type = options.fetch(:update_type, "major")
  locale = options.fetch(:locale, "en")

  put_content_response = publishing_api.put_content(
    options.fetch(:content_id),
    base_path: options.fetch(:base_path),
    document_type: options.fetch(:document_type, "special_route"),
    schema_name: options.fetch(:schema_name, "special_route"),
    title: options.fetch(:title),
    description: options.fetch(:description, ""),
    locale:,
    details: {},
    routes: [
      {
        path: options.fetch(:base_path),
        type: options.fetch(:type),
      },
    ],
    publishing_app: options.fetch(:publishing_app),
    rendering_app: options.fetch(:rendering_app),
    public_updated_at: time.now.iso8601,
    update_type:,
  )

  publishing_api.patch_links(options.fetch(:content_id), links: options[:links]) if options[:links]
  publishing_api.publish(options.fetch(:content_id), update_type, locale:)
  put_content_response
end