diff options
| author | Teddy Wing | 2018-03-27 15:24:27 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-03-27 16:46:18 +0200 | 
| commit | c17665c0cc064c8a14af812dedd645977d110388 (patch) | |
| tree | 78f06c47f06a0b83e785097eb3c72881de0bb322 /lib/tom_tom/matrix.rb | |
| parent | f257a8b3a7ae4c59c6907b41f6e8d7dc74259917 (diff) | |
| download | chouette-core-c17665c0cc064c8a14af812dedd645977d110388.tar.bz2 | |
TomTom::Matrix: Serialize `BigDecimal` as float
Rails serialises `BigDecimal`s as JSON strings to prevent loss of
precision. The `latitude` and `longitude` columns in `StopArea` are
stored as `BigDecimal`s. The trouble is that TomTom's API requires the
latitude & longitude values to be JSON floats, not strings.
Make a new JSON serialiser that converts the `BigDecimal` coordinates to
float to allow the values to be correctly interpreted by the API.
Refs #6222
Diffstat (limited to 'lib/tom_tom/matrix.rb')
| -rw-r--r-- | lib/tom_tom/matrix.rb | 12 | 
1 files changed, 8 insertions, 4 deletions
| diff --git a/lib/tom_tom/matrix.rb b/lib/tom_tom/matrix.rb index 49c000148..71eb6c75d 100644 --- a/lib/tom_tom/matrix.rb +++ b/lib/tom_tom/matrix.rb @@ -15,10 +15,7 @@ module TomTom          req.params[:routeType] = 'shortest'          req.params[:travelMode] = 'bus' -        req.body = { -          origins: points, -          destinations: points -        }.to_json +        req.body = build_request_body(points)        end        extract_costs_to_way_costs!( @@ -69,6 +66,13 @@ module TomTom        end      end +    def build_request_body(points) +      RequestJSONSerializer.dump({ +        origins: points, +        destinations: points +      }) +    end +      def extract_costs_to_way_costs!(way_costs, points, matrix_json)        way_costs = [] | 
