aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tom_tom.rb
blob: 91f1a3800fc8da3cb60dcd3a730fa9eec25c19be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module TomTom
  BASE_URL = 'https://api.tomtom.com'

  @@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? && /[a-zA-Z0-9]{32}/ === api_key
  end

  def self.batch(way_costs)
    TomTom::Batch.new(connection).batch(way_costs)
  end

  def self.matrix(way_costs)
    TomTom::Matrix.new(connection).matrix(way_costs)
  end
end