Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/google_maps_service/apis/roads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Owner

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.

Copy link
Owner

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?

Copy link
Owner

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 :)

Copy link
Author

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'
Copy link
Owner

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] = ...?

Copy link
Author

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.


return get('/v1/speedLimits', params,
base_url: ROADS_BASE_URL,
Expand Down