Skip to content
Snippets Groups Projects
Commit 22db336f authored by Sam Oliver's avatar Sam Oliver
Browse files

Add `time_zone` to `Opencagedata` result

parent 512c6877
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,15 @@ module Geocoder::Result
[south, west, north, east]
end
def time_zone
# The OpenCage API documentation states that `annotations` is available
# "when possible" https://geocoder.opencagedata.com/api#annotations
@data
.fetch('annotations', {})
.fetch('timezone', {})
.fetch('name', nil)
end
def self.response_attributes
%w[boundingbox license
formatted stadium]
......
......@@ -60,7 +60,10 @@ class OpencagedataTest < GeocoderTestCase
assert_match(/\bq=45.423733%2C-75.676333\b/, query.url)
end
def test_opencagedata_time_zone
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "America/New_York", result.time_zone
end
def test_raises_exception_when_invalid_request
Geocoder.configure(always_raise: [Geocoder::InvalidRequest])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment