class Govuk::Diff::Pages::FormatSearcher

Public Class Methods

new(config) click to toggle source
# File lib/govuk/diff/pages/format_searcher.rb, line 8
def initialize(config)
  @config = config
end

Public Instance Methods

run() click to toggle source
# File lib/govuk/diff/pages/format_searcher.rb, line 12
def run
  puts "Getting list of formats in GOVUK" if verbose?
  response = get_facets
  extract_formats(response)
end
verbose?() click to toggle source
# File lib/govuk/diff/pages/format_searcher.rb, line 18
def verbose?
  @config.verbose
end

Private Instance Methods

extract_formats(response) click to toggle source
# File lib/govuk/diff/pages/format_searcher.rb, line 24
def extract_formats(response)
  parsed_response = JSON.parse(response)
  options = parsed_response.fetch('facets').fetch('format').fetch('options')
  options.map { |o| o['value']['slug'] }
end
get_facets() click to toggle source
# File lib/govuk/diff/pages/format_searcher.rb, line 30
def get_facets
  url = "#{@config.domains.production}/api/search.json?facet_format=#{@config.page_indexer.max_formats}"
  RestClient.get(url)
end