-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow speed_unit to be passed to request #7
base: master
Are you sure you want to change the base?
Conversation
1 similar comment
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
2 similar comments
Hi @netuoso |
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to use units
, instead of speed_unit
. Here I want to keep the params similar to the Google Maps request params name.
And also, please use :
, instead of =
, to keep consistent with other methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is snapped_speed_limits
method that can accept units
also, do you mind to add this for that method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your example in the PR description can be put in the method example here, so it will be in documentation also :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing. I will update this later today so you can check it over! Thanks for the gem btw. Very useful.
params = GoogleMapsService::Convert.as_list(place_ids).map { |place_id| ['placeId', place_id] } | ||
params << ['units', speed_unit] if speed_unit == 'MPH' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before, to keep it similar to other methods
Could you please change to: params[:units] = ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this situation, params is an array. [['key1','value1'],['key2','value2']]
. I went ahead and made the conversion from the multi-dimensional array to a hash. Would you rather it converted to a hash for readability or to use the << or push methods to add the the array?
snapped_speed_limits
params are in hash form so this isn't a concern there.
Fyi, when i converted the params to a hash and added the units as a symbol, it created problems. Therefore I went with params['units']
instead inside speed_limits
method.
2 similar comments
2 similar comments
@edwardsamuel ok waiting for you to review. the coverage decrease is due to changing the params sent to the if we wrapped the array to hash conversion inside a conditional that only executes if units is sent as a param to the speed_limits method it would retain 100% coverage. |
1 similar comment
Hi @netuoso,
and no need to do:
Thanks! |
@edwardsamuel No problem! That should do it. |
2 similar comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @netuoso
Will merge and publish it soon |
What happened to this? |
Explanation:
This change leaves KPH as the default while adding the ability to send 'MPH' to the roads.rb
Example request: