class GovukTaxonomyHelpers::PublishingApiResponse

Attributes

linked_content_item[RW]

Public Class Methods

new(content_item:, expanded_links:, publishing_api:) click to toggle source

@param content_item [Hash] Publishing API `get_content` response hash @param expanded_links [Hash] Publishing API `get_expanded_links` response hash @param publishing_api [PublishingApiV2] Publishing API service

# File lib/govuk_taxonomy_helpers/publishing_api_response.rb, line 23
def initialize(content_item:, expanded_links:, publishing_api:)
  details = content_item["details"] || {}

  @linked_content_item = LinkedContentItem.new(
    title: content_item["title"],
    internal_name: details["internal_name"],
    content_id: content_item["content_id"],
    base_path: content_item["base_path"]
  )

  add_expanded_links(expanded_links, publishing_api)
end

Private Instance Methods

parse_nested_child(nested_item) click to toggle source
# File lib/govuk_taxonomy_helpers/publishing_api_response.rb, line 73
def parse_nested_child(nested_item)
  details = nested_item["details"] || {}
  links = nested_item["links"] || {}

  nested_linked_content_item = LinkedContentItem.new(
    title: nested_item["title"],
    internal_name: details["internal_name"],
    content_id: nested_item["content_id"],
    base_path: nested_item["base_path"]
  )

  child_taxons = links["child_taxons"]

  if !child_taxons.nil?
    child_taxons.each do |child|
      nested_linked_content_item << parse_nested_child(child)
    end
  end

  nested_linked_content_item
end
parse_nested_parent(nested_item) click to toggle source
# File lib/govuk_taxonomy_helpers/publishing_api_response.rb, line 95
def parse_nested_parent(nested_item)
  details = nested_item["details"] || {}
  links = nested_item["links"] || {}

  nested_linked_content_item = LinkedContentItem.new(
    title: nested_item["title"],
    internal_name: details["internal_name"],
    content_id: nested_item["content_id"],
    base_path: nested_item["base_path"]
  )

  parent_taxons = links["parent_taxons"]

  if !parent_taxons.nil?
    single_parent = parent_taxons.first
    parse_nested_parent(single_parent) << nested_linked_content_item
  end

  nested_linked_content_item
end