timezone 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.markdown +4 -0
- data/README.markdown +15 -0
- data/lib/timezone/lookup/google.rb +6 -0
- data/lib/timezone/version.rb +1 -1
- data/test/mocks/google_no_result_found.json +1 -0
- data/test/timezone/lookup/test_google.rb +6 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a63e375d390532b48a5893acc6b5cae503327d8
|
4
|
+
data.tar.gz: 027d0d641967c2d31819c1ae08474119e037e03f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6ab4ce56850408b116810372db3a249d7350e77ce7f2262aa1e5e24ef989deea3b00aafedcbd21d8ad4737b2c7776d779af12b0807068c769b4a9fe478a3745
|
7
|
+
data.tar.gz: 629551995f3b72c874c0403bbf600141b2af662be10a2eabc880c2b23cf6f5312ad0a997f2d10d7bb1f173deb7d169b4e630535d788421f16f5d61c797fadfff
|
data/CHANGES.markdown
CHANGED
data/README.markdown
CHANGED
@@ -170,6 +170,21 @@ Latitude - longitude lookups can raise `::Timezone::Error::Lookup` exceptions wh
|
|
170
170
|
Timezone.lookup(10, 100000){ |name| "#{name} is invalid" }
|
171
171
|
=> " is invalid"
|
172
172
|
|
173
|
+
## Using Geonames and Google Lookups
|
174
|
+
|
175
|
+
`timezone` can be configured to use both Google and Geonames lookups. For instance, you may choose to fallback to Google if a Geonames lookup fails. The return value from a `::Timezone::Lookup.config` call can be stored and re-used to trigger lookups for the configured service. For instance:
|
176
|
+
|
177
|
+
GEONAMES_LOOKUP = Timezone::Lookup.config(:geonames) { |c| c.username = ... }
|
178
|
+
GOOGLE_LOOKUP = Timezone::Lookup.config(:google) { |c| c.api_key = ... }
|
179
|
+
|
180
|
+
lat, lon = 89, 40
|
181
|
+
|
182
|
+
begin
|
183
|
+
GEONAMES_LOOKUP.lookup(lat, lon)
|
184
|
+
rescue ::Timezone::Error::Lookup
|
185
|
+
GOOGLE_LOOKUP.lookup(lat, lon)
|
186
|
+
end
|
187
|
+
|
173
188
|
## Listing Timezones
|
174
189
|
|
175
190
|
Retrieving the complete list of timezones can be accomplished using the `::Timezone::names` function. NOTE: the list is not ordered.
|
@@ -10,6 +10,10 @@ module Timezone
|
|
10
10
|
module Lookup
|
11
11
|
# @!visibility private
|
12
12
|
class Google < ::Timezone::Lookup::Basic
|
13
|
+
# Indicates that no time zone data could be found for the specified
|
14
|
+
# <lat, lng>. This can occur if the query is incomplete or ambiguous.
|
15
|
+
NO_TIMEZONE_INFORMATION = 'ZERO_RESULTS'.freeze
|
16
|
+
|
13
17
|
def initialize(config)
|
14
18
|
if config.api_key.nil?
|
15
19
|
raise(::Timezone::Error::InvalidConfig, 'missing api key'.freeze)
|
@@ -31,6 +35,8 @@ module Timezone
|
|
31
35
|
return unless response.code =~ /^2\d\d$/
|
32
36
|
data = JSON.parse(response.body)
|
33
37
|
|
38
|
+
return if data['status'.freeze] == NO_TIMEZONE_INFORMATION
|
39
|
+
|
34
40
|
if data['status'.freeze] != 'OK'.freeze
|
35
41
|
raise(Timezone::Error::Google, data['errorMessage'])
|
36
42
|
end
|
data/lib/timezone/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{ "status" : "ZERO_RESULTS" }
|
@@ -73,6 +73,12 @@ class TestGoogle < ::Minitest::Test
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def test_no_result_found
|
77
|
+
mine = lookup(File.open(mock_path + '/google_no_result_found.json').read)
|
78
|
+
|
79
|
+
assert_nil(mine.lookup(26.188703, -78.987053))
|
80
|
+
end
|
81
|
+
|
76
82
|
private
|
77
83
|
|
78
84
|
def mock_path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timezone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pan Thomakos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -699,6 +699,7 @@ files:
|
|
699
699
|
- test/http_test_client.rb
|
700
700
|
- test/mocks/api_limit_reached.json
|
701
701
|
- test/mocks/google_lat_lon_coords.txt
|
702
|
+
- test/mocks/google_no_result_found.json
|
702
703
|
- test/mocks/google_request_denied.txt
|
703
704
|
- test/mocks/invalid_latlong.json
|
704
705
|
- test/mocks/invalid_parameter.json
|
@@ -745,13 +746,14 @@ rubyforge_project: timezone
|
|
745
746
|
rubygems_version: 2.5.1
|
746
747
|
signing_key:
|
747
748
|
specification_version: 4
|
748
|
-
summary: timezone-1.2.
|
749
|
+
summary: timezone-1.2.8
|
749
750
|
test_files:
|
750
751
|
- test/data/Helsinki_rules_without_timestamps.json
|
751
752
|
- test/data/asia
|
752
753
|
- test/http_test_client.rb
|
753
754
|
- test/mocks/api_limit_reached.json
|
754
755
|
- test/mocks/google_lat_lon_coords.txt
|
756
|
+
- test/mocks/google_no_result_found.json
|
755
757
|
- test/mocks/google_request_denied.txt
|
756
758
|
- test/mocks/invalid_latlong.json
|
757
759
|
- test/mocks/invalid_parameter.json
|