diff --git a/app/models/world_location.rb b/app/models/world_location.rb index b96feb2a32c..b92b678882a 100644 --- a/app/models/world_location.rb +++ b/app/models/world_location.rb @@ -13,7 +13,7 @@ def self.reset_cache def self.all cache_fetch("all") do - $worldwide_api.world_locations.with_subsequent_pages.map do |l| + Services.worldwide_api.world_locations.with_subsequent_pages.map do |l| new(l) if l.format == "World location" and l.details and l.details.slug.present? end.compact end @@ -21,7 +21,7 @@ def self.all def self.find(location_slug) cache_fetch("find_#{location_slug}") do - data = $worldwide_api.world_location(location_slug) + data = Services.worldwide_api.world_location(location_slug) self.new(data) if data end end diff --git a/app/models/worldwide_organisation.rb b/app/models/worldwide_organisation.rb index 6d46d9c6097..58f3f22bde1 100644 --- a/app/models/worldwide_organisation.rb +++ b/app/models/worldwide_organisation.rb @@ -2,7 +2,7 @@ class WorldwideOrganisation extend Forwardable def self.for_location(location_slug) - $worldwide_api.organisations_for_world_location(location_slug).map do |org| + Services.worldwide_api.organisations_for_world_location(location_slug).map do |org| new(org) end end diff --git a/config/initializers/worldwide_api.rb b/config/initializers/worldwide_api.rb deleted file mode 100644 index 292c78169a8..00000000000 --- a/config/initializers/worldwide_api.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'gds_api/worldwide' - -# In development, point at the public version of the API -# as we won't normally have whitehall running -if Rails.env.development? - $worldwide_api = GdsApi::Worldwide.new("https://www.gov.uk") -else - $worldwide_api = GdsApi::Worldwide.new(Plek.new.find('whitehall-admin')) -end diff --git a/lib/services.rb b/lib/services.rb index 90b100dfe37..225140fd80b 100644 --- a/lib/services.rb +++ b/lib/services.rb @@ -1,5 +1,6 @@ require 'gds_api/publishing_api' require 'gds_api/imminence' +require 'gds_api/worldwide' module Services def self.publishing_api @@ -9,4 +10,14 @@ def self.publishing_api def self.imminence_api @imminence_api ||= GdsApi::Imminence.new(Plek.new.find('imminence')) end + + def self.worldwide_api + # In development, point at the public version of the API + # as we won't normally have whitehall running + if Rails.env.development? + @worldwide_api ||= GdsApi::Worldwide.new("https://www.gov.uk") + else + @worldwide_api ||= GdsApi::Worldwide.new(Plek.new.find('whitehall-admin')) + end + end end diff --git a/test/unit/world_location_test.rb b/test/unit/world_location_test.rb index 0ca9324729a..e7ab1152b5e 100644 --- a/test/unit/world_location_test.rb +++ b/test/unit/world_location_test.rb @@ -40,7 +40,7 @@ class WorldLocationTest < ActiveSupport::TestCase details = {"results" => [loc1, loc2, loc3, loc4]} response = GdsApi::ListResponse.new(stub(body: details.to_json, headers: {}), nil) - $worldwide_api.stubs(:world_locations).returns(response) + Services.worldwide_api.stubs(:world_locations).returns(response) results = WorldLocation.all assert_equal %w(location-1 location-4), results.map(&:slug)