Skip to content

Commit d59d882

Browse files
committed
Merge pull request #2025 from alphagov/move-global-variables-to-services-module
Move global variables to Services module
2 parents a58dad8 + 13fc6a2 commit d59d882

9 files changed

+23
-19
lines changed

app/models/world_location.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ def self.reset_cache
1313

1414
def self.all
1515
cache_fetch("all") do
16-
$worldwide_api.world_locations.with_subsequent_pages.map do |l|
16+
Services.worldwide_api.world_locations.with_subsequent_pages.map do |l|
1717
new(l) if l.format == "World location" and l.details and l.details.slug.present?
1818
end.compact
1919
end
2020
end
2121

2222
def self.find(location_slug)
2323
cache_fetch("find_#{location_slug}") do
24-
data = $worldwide_api.world_location(location_slug)
24+
data = Services.worldwide_api.world_location(location_slug)
2525
self.new(data) if data
2626
end
2727
end

app/models/worldwide_organisation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class WorldwideOrganisation
22
extend Forwardable
33

44
def self.for_location(location_slug)
5-
$worldwide_api.organisations_for_world_location(location_slug).map do |org|
5+
Services.worldwide_api.organisations_for_world_location(location_slug).map do |org|
66
new(org)
77
end
88
end

config/initializers/imminence.rb

-3
This file was deleted.

config/initializers/worldwide_api.rb

-9
This file was deleted.

lib/services.rb

+16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
require 'gds_api/publishing_api'
2+
require 'gds_api/imminence'
3+
require 'gds_api/worldwide'
24

35
module Services
46
def self.publishing_api
57
@publishing_api ||= GdsApi::PublishingApi.new(Plek.new.find('publishing-api'))
68
end
9+
10+
def self.imminence_api
11+
@imminence_api ||= GdsApi::Imminence.new(Plek.new.find('imminence'))
12+
end
13+
14+
def self.worldwide_api
15+
# In development, point at the public version of the API
16+
# as we won't normally have whitehall running
17+
if Rails.env.development?
18+
@worldwide_api ||= GdsApi::Worldwide.new("https://www.gov.uk")
19+
else
20+
@worldwide_api ||= GdsApi::Worldwide.new(Plek.new.find('whitehall-admin'))
21+
end
22+
end
723
end

lib/smart_answer/calculators/landlord_immigration_check_calculator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LandlordImmigrationCheckCalculator
1818
)
1919

2020
def self.valid_postcode(postcode)
21-
response = $imminence.areas_for_postcode(postcode)
21+
response = Services.imminence_api.areas_for_postcode(postcode)
2222
return false unless response and response.code == 200
2323
areas = response.to_hash["results"]
2424
! areas.find { |a| VALID_BOROUGHS.include?(a["slug"]) }.nil?

test/data/landlord-immigration-check-files.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ lib/smart_answer_flows/landlord-immigration-check/outcomes/outcome_check_not_nee
1818
lib/smart_answer_flows/landlord-immigration-check/outcomes/outcome_check_not_needed_when_hostel_refuge.govspeak.erb: 6c068528a1a1c08d957d6446d03c6c7e
1919
lib/smart_answer_flows/landlord-immigration-check/outcomes/outcome_check_not_needed_when_mobile_home.govspeak.erb: 76921608102f56db3c0a2e7de007a989
2020
lib/smart_answer_flows/landlord-immigration-check/outcomes/outcome_check_not_needed_when_under_18.govspeak.erb: 31a94b4f17d48afac83ba42eab361cab
21-
lib/smart_answer/calculators/landlord_immigration_check_calculator.rb: bd0670bd986a0032d2a21297bc3616e5
21+
lib/smart_answer/calculators/landlord_immigration_check_calculator.rb: ece61292e6e20bdfb86ef479108d019b

test/unit/calculators/landlord_immigration_check_calculator_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LandlordImmigrationCheckCalculatorTest < ActiveSupport::TestCase
1818
stub_request(:get, %r{\A#{Plek.new.find('imminence')}/areas/E15\.json}).
1919
to_return(body: { _response_info: { status: 404 }, total: 0, results: [] }.to_json)
2020

21-
response = $imminence.areas_for_postcode("E15")
21+
response = Services.imminence_api.areas_for_postcode("E15")
2222

2323
assert_equal 404, response["_response_info"]["status"]
2424
assert_equal 0, response["total"]

test/unit/world_location_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class WorldLocationTest < ActiveSupport::TestCase
4040
details = {"results" => [loc1, loc2, loc3, loc4]}
4141
response = GdsApi::ListResponse.new(stub(body: details.to_json, headers: {}), nil)
4242

43-
$worldwide_api.stubs(:world_locations).returns(response)
43+
Services.worldwide_api.stubs(:world_locations).returns(response)
4444

4545
results = WorldLocation.all
4646
assert_equal %w(location-1 location-4), results.map(&:slug)

0 commit comments

Comments
 (0)