diff options
| author | Alban Peignier | 2018-05-13 11:21:12 +0200 |
|---|---|---|
| committer | Alban Peignier | 2018-05-13 11:21:12 +0200 |
| commit | 458f55a73105d8ade30f9874e8ca6b82e86011f1 (patch) | |
| tree | edc27c94ce7fa70119d4a0bd69f29e5266772f30 /lib | |
| parent | 261c9de605d98d6d66d81004103e998175895c82 (diff) | |
| download | chouette-core-458f55a73105d8ade30f9874e8ca6b82e86011f1.tar.bz2 | |
Define a dummy TomTom api_key in spec
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tom_tom.rb | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/tom_tom.rb b/lib/tom_tom.rb index fcebcc7ac..9158b7a28 100644 --- a/lib/tom_tom.rb +++ b/lib/tom_tom.rb @@ -1,26 +1,30 @@ module TomTom BASE_URL = 'https://api.tomtom.com' - @api_key = Rails.application.secrets.tomtom_api_key - @connection = Faraday.new( - url: BASE_URL, - params: { - key: @api_key - } - ) do |faraday| - faraday.use FaradayMiddleware::FollowRedirects, limit: 1 - faraday.adapter Faraday.default_adapter + @@api_key = Rails.application.secrets.tomtom_api_key + cattr_accessor :api_key + + def self.connection + @connection ||= Faraday.new( + url: BASE_URL, + params: { + key: api_key + } + ) do |faraday| + faraday.use FaradayMiddleware::FollowRedirects, limit: 1 + faraday.adapter Faraday.default_adapter + end end def self.enabled? - @api_key.present? + api_key.present? end def self.batch(way_costs) - TomTom::Batch.new(@connection).batch(way_costs) + TomTom::Batch.new(connection).batch(way_costs) end def self.matrix(way_costs) - TomTom::Matrix.new(@connection).matrix(way_costs) + TomTom::Matrix.new(connection).matrix(way_costs) end end |
