uber-ruby icon indicating copy to clipboard operation
uber-ruby copied to clipboard

NoMethodError on #price_estimates for coordinates over 100 miles

Open Drowze opened this issue 8 years ago • 0 comments

The gem breaks when the distance between two coordinates is over 100 miles. #34 is a PR that fixes the problem just for reference - be warned that it breaks the requests endpoint (since it passes useful information on the error response, and I am simply throwing an error for any 4xx & 5xx response).

I'd like to see suggestions on a good way to catch this 100 miles error (that seems a bummer, really)

Details:

[2] pry(main)> $uber.price_estimations(start_latitude: -23.434553, start_longitude: -46.478126, end_latitude: -23.460275, end_longitude: -40)
NoMethodError: undefined method `each' for "Distance between two points exceeds 100 miles":String
from /home/giba/.rvm/gems/ruby-2.4.1/gems/uber-ruby-0.9.0/lib/uber/base.rb:12:in `initialize'

Uber API details (for reference):

Request (v1.2)

curl -H 'Authorization: Token <TOKEN>' \
     -H 'Accept-Language: en_US' \
     -H 'Content-Type: application/json' \
     'https://api.uber.com/v1.2/estimates/price?start_latitude=37.7752315&start_longitude=-122.418075&end_latitude=37.7752415&end_longitude=-120.518075'

Response (v1.2)

{
	"fields": {
		"start_longitude": "Distance between two points exceeds 100 miles",
		"end_longitude": "Distance between two points exceeds 100 miles",
		"start_latitude": "Distance between two points exceeds 100 miles",
		"end_latitude": "Distance between two points exceeds 100 miles"
	},
	"message": "Distance between two points exceeds 100 miles",
	"code": "distance_exceeded"
}

Request (v1)

curl -H 'Authorization: Token <TOKEN>' \
     -H 'Accept-Language: en_US' \
     -H 'Content-Type: application/json' \
     'https://api.uber.com/v1/estimates/price?start_latitude=37.7752315&start_longitude=-122.418075&end_latitude=37.7752415&end_longitude=-120.518075' 

Response (v1)

{
	"fields": {
		"start_longitude": "Distance between two points exceeds 100 miles",
		"end_longitude": "Distance between two points exceeds 100 miles",
		"start_latitude": "Distance between two points exceeds 100 miles",
		"end_latitude": "Distance between two points exceeds 100 miles"
	},
	"message": "Distance between two points exceeds 100 miles",
	"code": "distance_exceeded"
}

Drowze avatar Jul 13 '17 23:07 Drowze