require 'gds_api/content_store'
require 'gds_api/rummager'
require 'gds_api/email_alert_api'

module Services
  def self.content_store
    @content_store ||= GdsApi::ContentStore.new(Plek.find("content-store"))
  end

  def self.cached_content_item(base_path)
    Rails.cache.fetch("finder-frontend_content_items#{base_path}", expires_in: 5.minutes) do
      content_store.content_item(base_path).to_h
    end
  end

  def self.rummager
    @rummager ||= GdsApi::Rummager.new(Plek.find("search"))
  end

  def self.email_alert_api
    @email_alert_api ||= GdsApi::EmailAlertApi.new(
      Plek.find("email-alert-api"),
      bearer_token: ENV.fetch("EMAIL_ALERT_API_BEARER_TOKEN", "wubbalubbadubdub")
    )
  end

  def self.worldwide_api
    @worldwide_api ||= GdsApi::Worldwide.new(Plek.find('whitehall-admin'))
  end
end

require 'gds_api/content_store'
require 'gds_api/rummager'
require 'gds_api/email_alert_api'

module Services
  def self.content_store
    @content_store ||= GdsApi::ContentStore.new(Plek.find("content-store"))
  end

  def self.cached_content_item(base_path)
    Rails.cache.fetch("finder-frontend_content_items#{base_path}", expires_in: 5.minutes) do
      GovukStatsd.time("content_store.fetch_request_time") do
        content_store.content_item(base_path).to_h
      end
    end
  end

  def self.rummager
    @rummager ||= GdsApi::Rummager.new(Plek.find("search"))
  end

  def self.email_alert_api
    @email_alert_api ||= GdsApi::EmailAlertApi.new(
      Plek.find("email-alert-api"),
      bearer_token: ENV.fetch("EMAIL_ALERT_API_BEARER_TOKEN", "wubbalubbadubdub")
    )
  end

  def self.worldwide_api
    @worldwide_api ||= GdsApi::Worldwide.new(Plek.find('whitehall-admin'))
  end
end

Add timer to content item requests
Add timer to content item requests

This adds tracking to the content item requests.
This will be available in Graphite at
stats.timers.finder-frontend.content_store.fetch_request_time
