timezone icon indicating copy to clipboard operation
timezone copied to clipboard

Wrong error raised for Geonames Lookup

Open Chambeur opened this issue 7 years ago • 1 comments

According to README:

Timezone.lookup(10, 10)
=> Timezone::Error::Geonames: api limit reached

Timezone.lookup(10, 100000)
=> Timezone::Error::InvalidZone

Timezone.lookup(10, 100000, Timezone::NilZone.new)
=> #<Timezone::NilZone>

Timezone.lookup(10, 100000){ |name| "#{name} is invalid" }
=> " is invalid"

However, with the GeoNames API, we get:

> Timezone.lookup(10, 100000)
=> Timezone::Error::GeoNames: invalid lat/lng

> Timezone.lookup(10, 100000, Timezone::NilZone.new)
=> Timezone::Error::GeoNames: invalid lat/lng

Chambeur avatar Sep 13 '18 08:09 Chambeur

@Chambeur thank you for filing a ticket. What version of the gem are you using?

To clarify a few things: the api limit reached error will only occur if you have reached the API limit, and it will occur even if the lat/lng is valid. It's not easily reproducible unless you make enough requests to hit the geonames API limit.

I have not tested the exact lat/lng coordinates in the example in a while, but if they are no longer working as intended I would be happy to see a PR to update the README.

With regards to the default value (in your last example), here is the behavior I am seeing on the most recent version of the gem:

2.3.3 (main):0 > Timezone.lookup(10, 100000)
Timezone::Error::GeoNames: invalid lat/lng

2.3.3 (main):0 > Timezone.lookup(-10, 10)
Timezone::Error::InvalidZone: Timezone::Error::InvalidZone

2.3.3 (main):0 > Timezone.lookup(-10, 10, ::Timezone::NilZone.new)
=> #<Timezone::NilZone>

panthomakos avatar Sep 17 '18 21:09 panthomakos