From 9291d45e825edbaf52cb556c102498366985496f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 15 Mar 2018 11:52:16 +0100 Subject: Route: Don't run `#calculate_costs!` on callback if TomTom disabled We say `TomTom` is disabled when no API key is present. If this is the case, the `after_save` callback that uses it shouldn't be executed. I had to change my `API_KEY` constant to an instance variable to be able to change it for testing. Refs #6095 --- lib/tom_tom.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/tom_tom.rb b/lib/tom_tom.rb index 97f914f28..a1a2bda43 100644 --- a/lib/tom_tom.rb +++ b/lib/tom_tom.rb @@ -1,17 +1,21 @@ module TomTom BASE_URL = 'https://api.tomtom.com' - API_KEY = Rails.application.secrets.tomtom_api_key + @api_key = Rails.application.secrets.tomtom_api_key @connection = Faraday.new( url: BASE_URL, params: { - key: API_KEY + key: @api_key } ) do |faraday| faraday.use FaradayMiddleware::FollowRedirects, limit: 1 faraday.adapter Faraday.default_adapter end + def self.enabled? + @api_key.present? + end + def self.batch(way_costs) TomTom::Batch.new(@connection).batch(way_costs) end -- cgit v1.2.3