class GdsApi::PublishingApi

def get_live_content(content_id, locale = "en")

Other tags:
    See: https://github.com/alphagov/publishing-api/blob/master/doc/api.md#get-v2contentcontent_id -

Raises:
  • (NoLiveVersion) - when the content item is not found

Returns:
  • (GdsApi::Response) - a content item

Options Hash: (**locale)
  • locale (String) -- The language, defaults to 'en' in publishing-api.

Parameters:
  • content_id (UUID) --
def get_live_content(content_id, locale = "en")
  content_item = get_content(content_id, locale: locale)
  live_states = %w[published unpublished]
  return content_item if live_states.include?(content_item.to_h["publication_state"])
  live_version_number = content_item["state_history"].find { |_, v| live_states.include?(v) }&.first
  raise NoLiveVersion, "No live version exists for content_id: #{content_id}" unless live_version_number
  get_content(content_id, locale: locale, version: live_version_number)
end