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

Allow speed_unit to be passed to request #7

wants to merge 7 commits into from

Conversation

netuoso
Copy link

@netuoso netuoso commented May 10, 2017

Explanation:

This change leaves KPH as the default while adding the ability to send 'MPH' to the roads.rb

Example request:

google_client = GoogleMapsService::Client.new
google_client.speed_limits('ChIJaw1TDuC22YgRf6hEN94cT58')
=> [{:placeId=>"ChIJaw1TDuC22YgRf6hEN94cT58", :speedLimit=>88.51392, :units=>"KPH"}]

google_client = GoogleMapsService::Client.new
google_client.speed_limits('ChIJaw1TDuC22YgRf6hEN94cT58', units: 'MPH')
=> [{:placeId=>"ChIJaw1TDuC22YgRf6hEN94cT58", :speedLimit=>55, :units=>"MPH"}]

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 4e86596 on netuoso:master into 46746fd on edwardsamuel:master.

1 similar comment
@coveralls
Copy link

coveralls commented May 10, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 4e86596 on netuoso:master into 46746fd on edwardsamuel:master.

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
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 3a75f10 on netuoso:master into 46746fd on edwardsamuel:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 3a75f10 on netuoso:master into 46746fd on edwardsamuel:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 3a75f10 on netuoso:master into 46746fd on edwardsamuel:master.

@edwardsamuel
Copy link
Owner

Hi @netuoso
Thanks for your PR. I just saw that Speed Limit have units.
Before I merge, I have some reviews on yours (I'll write in separate comments).

@@ -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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.73% when pulling ce77462 on netuoso:master into 46746fd on edwardsamuel:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.73% when pulling ce77462 on netuoso:master into 46746fd on edwardsamuel:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.73% when pulling ce77462 on netuoso:master into 46746fd on edwardsamuel:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.73% when pulling 02973b7 on netuoso:master into 46746fd on edwardsamuel:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.73% when pulling 02973b7 on netuoso:master into 46746fd on edwardsamuel:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.73% when pulling 02973b7 on netuoso:master into 46746fd on edwardsamuel:master.

@netuoso
Copy link
Author

netuoso commented May 12, 2017

@edwardsamuel ok waiting for you to review. the coverage decrease is due to changing the params sent to the generate_auth_url method in client.rb since it isn't receiving an array from the speed_limits method any longer.

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.73% when pulling 9c20a42 on netuoso:master into 46746fd on edwardsamuel:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.73% when pulling 9c20a42 on netuoso:master into 46746fd on edwardsamuel:master.

@edwardsamuel
Copy link
Owner

Hi @netuoso,
Sorry, my bad. I realize that we can't use Hash params in the speed_limits method, but it's fine on snapped_speed_limits.
You are right, use array instead:

params << ['units', units] if units.match(/^mph$/i)

and no need to do:

params = Hash[params]

Thanks!

@netuoso
Copy link
Author

netuoso commented May 15, 2017

@edwardsamuel No problem! That should do it.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 7493b02 on netuoso:master into 46746fd on edwardsamuel:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 7493b02 on netuoso:master into 46746fd on edwardsamuel:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 7493b02 on netuoso:master into 46746fd on edwardsamuel:master.

Copy link
Owner

@edwardsamuel edwardsamuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @netuoso

@edwardsamuel
Copy link
Owner

Will merge and publish it soon

@rnestler
Copy link

Will merge and publish it soon

What happened to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants