From 4e86596e0eb47d77bf3f581c994fca81db2aab4f Mon Sep 17 00:00:00 2001 From: "Andrew Chaney (netuoso)" Date: Wed, 10 May 2017 15:56:59 -0500 Subject: [PATCH 1/6] Allow speed_unit to be passed to request --- lib/google_maps_service/apis/roads.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/google_maps_service/apis/roads.rb b/lib/google_maps_service/apis/roads.rb index 9c2102c..b3acaa1 100644 --- a/lib/google_maps_service/apis/roads.rb +++ b/lib/google_maps_service/apis/roads.rb @@ -63,8 +63,9 @@ def snap_to_roads(path, interpolate: false) # by the snap_to_roads function. You can pass up to 100 Place IDs. # # @return [Array] Array of speed limits. - def speed_limits(place_ids) + def speed_limits(place_ids, speed_unit='KPH') params = GoogleMapsService::Convert.as_list(place_ids).map { |place_id| ['placeId', place_id] } + params << ['units', speed_unit] return get('/v1/speedLimits', params, base_url: ROADS_BASE_URL, From 3a75f1076eae0bca9da7ce02b157bc8038df60c5 Mon Sep 17 00:00:00 2001 From: Andrew Chaney Date: Thu, 11 May 2017 11:11:35 -0500 Subject: [PATCH 2/6] Make update to keep existing tests passing Since KPH is google default unit when no unit param is sent, just do not send it at all unless speed_unit is set to MPH --- lib/google_maps_service/apis/roads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google_maps_service/apis/roads.rb b/lib/google_maps_service/apis/roads.rb index b3acaa1..4e8427c 100644 --- a/lib/google_maps_service/apis/roads.rb +++ b/lib/google_maps_service/apis/roads.rb @@ -65,7 +65,7 @@ def snap_to_roads(path, interpolate: false) # @return [Array] Array of speed limits. def speed_limits(place_ids, speed_unit='KPH') params = GoogleMapsService::Convert.as_list(place_ids).map { |place_id| ['placeId', place_id] } - params << ['units', speed_unit] + params << ['units', speed_unit] if speed_unit == 'MPH' return get('/v1/speedLimits', params, base_url: ROADS_BASE_URL, From 684c5124c6f605c22abf0e55449c8773508c63a8 Mon Sep 17 00:00:00 2001 From: "Andrew Chaney (netuoso)" Date: Fri, 12 May 2017 10:59:57 -0500 Subject: [PATCH 3/6] Make changes as requested by edwardsamuel --- lib/google_maps_service/apis/roads.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/google_maps_service/apis/roads.rb b/lib/google_maps_service/apis/roads.rb index b3acaa1..f8680cf 100644 --- a/lib/google_maps_service/apis/roads.rb +++ b/lib/google_maps_service/apis/roads.rb @@ -63,9 +63,10 @@ def snap_to_roads(path, interpolate: false) # by the snap_to_roads function. You can pass up to 100 Place IDs. # # @return [Array] Array of speed limits. - def speed_limits(place_ids, speed_unit='KPH') + def speed_limits(place_ids, units: 'KPH') params = GoogleMapsService::Convert.as_list(place_ids).map { |place_id| ['placeId', place_id] } - params << ['units', speed_unit] + params = params.to_h + params['units'] = units if units.match(/^mph$/i) return get('/v1/speedLimits', params, base_url: ROADS_BASE_URL, @@ -92,12 +93,13 @@ def speed_limits(place_ids, speed_unit='KPH') # # @return [Hash] A hash with both a list of speed limits and a list of the snapped # points. - def snapped_speed_limits(path) + def snapped_speed_limits(path, units: 'KPH') path = GoogleMapsService::Convert.waypoints(path) params = { - path: path - } + path: path, + units: (units if units.match(/^mph$/i)) + }.reject {|k,v| v.nil?} return get('/v1/speedLimits', params, base_url: ROADS_BASE_URL, From 02973b7c3936f1f73d57b4a56bf9a585576e9d57 Mon Sep 17 00:00:00 2001 From: "Andrew Chaney (netuoso)" Date: Fri, 12 May 2017 11:16:35 -0500 Subject: [PATCH 4/6] Change syntax to map array to Hash to support Ruby2.0.0 --- lib/google_maps_service/apis/roads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google_maps_service/apis/roads.rb b/lib/google_maps_service/apis/roads.rb index f8680cf..a81b1c6 100644 --- a/lib/google_maps_service/apis/roads.rb +++ b/lib/google_maps_service/apis/roads.rb @@ -65,7 +65,7 @@ def snap_to_roads(path, interpolate: false) # @return [Array] Array of speed limits. def speed_limits(place_ids, units: 'KPH') params = GoogleMapsService::Convert.as_list(place_ids).map { |place_id| ['placeId', place_id] } - params = params.to_h + params = Hash[params.map {|k,v| [k, v]}] params['units'] = units if units.match(/^mph$/i) return get('/v1/speedLimits', params, From 9c20a4228c8d5e4c0c79a2fd3cf234316bbc82ac Mon Sep 17 00:00:00 2001 From: "Andrew Chaney (netuoso)" Date: Fri, 12 May 2017 11:29:45 -0500 Subject: [PATCH 5/6] Cleaner syntax for Array to Hash --- lib/google_maps_service/apis/roads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google_maps_service/apis/roads.rb b/lib/google_maps_service/apis/roads.rb index a81b1c6..da21a76 100644 --- a/lib/google_maps_service/apis/roads.rb +++ b/lib/google_maps_service/apis/roads.rb @@ -65,7 +65,7 @@ def snap_to_roads(path, interpolate: false) # @return [Array] Array of speed limits. def speed_limits(place_ids, units: 'KPH') params = GoogleMapsService::Convert.as_list(place_ids).map { |place_id| ['placeId', place_id] } - params = Hash[params.map {|k,v| [k, v]}] + params = Hash[params] params['units'] = units if units.match(/^mph$/i) return get('/v1/speedLimits', params, From 7493b02daba539969ac1cbce1d68fde0ec80928f Mon Sep 17 00:00:00 2001 From: Andrew Chaney Date: Mon, 15 May 2017 10:22:29 -0500 Subject: [PATCH 6/6] Update roads.rb --- lib/google_maps_service/apis/roads.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/google_maps_service/apis/roads.rb b/lib/google_maps_service/apis/roads.rb index da21a76..bbc689e 100644 --- a/lib/google_maps_service/apis/roads.rb +++ b/lib/google_maps_service/apis/roads.rb @@ -65,8 +65,7 @@ def snap_to_roads(path, interpolate: false) # @return [Array] Array of speed limits. def speed_limits(place_ids, units: 'KPH') params = GoogleMapsService::Convert.as_list(place_ids).map { |place_id| ['placeId', place_id] } - params = Hash[params] - params['units'] = units if units.match(/^mph$/i) + params << ['units', units] if units.match(/^mph$/i) return get('/v1/speedLimits', params, base_url: ROADS_BASE_URL,