diff options
| author | Teddy Wing | 2018-03-12 12:50:43 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-03-14 16:38:40 +0100 | 
| commit | 05d2014dff30901feba5c9aab3e066d89d3771ca (patch) | |
| tree | c5726ef3391856a31faf4a32ec863397712468bd | |
| parent | 587bac0983d80a7ace5813e239ca951155fc56f6 (diff) | |
| download | chouette-core-05d2014dff30901feba5c9aab3e066d89d3771ca.tar.bz2 | |
TomTom: Provide `TomTom.batch(...)` method
This change enables us to call `TomTom.batch(...)` instead of
`TomTom.new.batch(...)` a couple commits ago. This is nice because the
initialisation was kind of unnecessary for users of the class.
Refs #6095
| -rw-r--r-- | lib/tom_tom.rb | 16 | ||||
| -rw-r--r-- | lib/tom_tom/batch.rb | 15 | ||||
| -rw-r--r-- | spec/lib/tom_tom/batch_spec.rb | 4 | 
3 files changed, 20 insertions, 15 deletions
| diff --git a/lib/tom_tom.rb b/lib/tom_tom.rb index 2947961c3..97f914f28 100644 --- a/lib/tom_tom.rb +++ b/lib/tom_tom.rb @@ -1,2 +1,18 @@  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 +  end + +  def self.batch(way_costs) +    TomTom::Batch.new(@connection).batch(way_costs) +  end  end diff --git a/lib/tom_tom/batch.rb b/lib/tom_tom/batch.rb index 4d590a945..f947cced8 100644 --- a/lib/tom_tom/batch.rb +++ b/lib/tom_tom/batch.rb @@ -1,18 +1,7 @@  module TomTom    class Batch -    BASE_URL = 'https://api.tomtom.com' -    API_KEY = Rails.application.secrets.tomtom_api_key - -    def initialize -      @connection = Faraday.new( -        url: BASE_URL, -        params: { -          key: API_KEY -        } -      ) do |faraday| -        faraday.use FaradayMiddleware::FollowRedirects, limit: 1 -        faraday.adapter Faraday.default_adapter -      end +    def initialize(connection) +      @connection = connection      end      def batch(way_costs) diff --git a/spec/lib/tom_tom/batch_spec.rb b/spec/lib/tom_tom/batch_spec.rb index 5aff970eb..aee1a2f1d 100644 --- a/spec/lib/tom_tom/batch_spec.rb +++ b/spec/lib/tom_tom/batch_spec.rb @@ -1,5 +1,5 @@  RSpec.describe TomTom::Batch do -  let(:tomtom) { TomTom::Batch.new } +  let(:batch) { TomTom::Batch.new(nil) }    describe "#convert_way_costs_for_batch" do      it "turns WayCost points into a collection of colon-separated strings" do @@ -15,7 +15,7 @@ RSpec.describe TomTom::Batch do        ]        expect( -        tomtom.convert_way_costs_for_batch(way_costs) +        batch.convert_way_costs_for_batch(way_costs)        ).to eq([          '2,48:3,46',          '-71,42:-71.5,42.9' | 
