timezone 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.markdown +4 -0
- data/lib/timezone/lookup/basic.rb +3 -1
- data/lib/timezone/net_http_client.rb +1 -2
- data/lib/timezone/version.rb +1 -1
- data/test/http_test_client.rb +10 -0
- data/test/threadsafe_lookup.rb +17 -0
- data/test/timezone/lookup/test_basic.rb +2 -1
- data/test/timezone/lookup/test_geonames.rb +11 -20
- data/test/timezone/lookup/test_google.rb +8 -14
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f425df08238312c541ca6f27ec918e93839d3b71
|
4
|
+
data.tar.gz: 63d02b58ca7ef733860dfa69c63817ef4813b34c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d77400308229dfa26cb85efa32d6fdfd3e47b9adaced3bb35e9767e89ce1f7988740355e5bcc2b111169214276d385278bbf39dd0a88e7e4c698ab5b23bf8bbf
|
7
|
+
data.tar.gz: db2044e5927331b314654d961e85f77aa6e9883fd48c3fe417690d59415574688c919919cd2f23fb2ef7b3a078fd99eafbc0f8dfc46b7cd097c262a09634270b
|
data/CHANGES.markdown
CHANGED
@@ -18,6 +18,8 @@ module Timezone
|
|
18
18
|
raise(::Timezone::Error::InvalidConfig, 'missing url')
|
19
19
|
end
|
20
20
|
|
21
|
+
config.uri ||= URI.parse("#{config.protocol}://#{config.url}")
|
22
|
+
|
21
23
|
@config = config
|
22
24
|
end
|
23
25
|
|
@@ -25,7 +27,7 @@ module Timezone
|
|
25
27
|
#
|
26
28
|
# @return [#get] an instance of a request handler
|
27
29
|
def client
|
28
|
-
|
30
|
+
config.request_handler.new(config)
|
29
31
|
end
|
30
32
|
|
31
33
|
# Returns a timezone name for a given lat, long pair.
|
@@ -16,8 +16,7 @@ module Timezone
|
|
16
16
|
#
|
17
17
|
class NetHTTPClient
|
18
18
|
def initialize(config)
|
19
|
-
|
20
|
-
@http = Net::HTTP.new(uri.host, uri.port)
|
19
|
+
@http = Net::HTTP.new(config.uri.host, config.uri.port)
|
21
20
|
@http.open_timeout = config.open_timeout || 5
|
22
21
|
@http.read_timeout = config.read_timeout || 5
|
23
22
|
@http.use_ssl = (config.protocol == 'https'.freeze)
|
data/lib/timezone/version.rb
CHANGED
data/test/http_test_client.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'timezone'
|
2
|
+
|
3
|
+
# Simple script to validate that lookups are threadsafe.
|
4
|
+
#
|
5
|
+
# Usage: bundle exec ruby -Ilib test/threadsafe_lookup.rb USERNAME
|
6
|
+
|
7
|
+
raise 'You must specify a geonames username' unless ARGV.first
|
8
|
+
|
9
|
+
Timezone::Lookup.config(:geonames) do |c|
|
10
|
+
c.username = ARGV.first
|
11
|
+
end
|
12
|
+
|
13
|
+
threads = Array.new(5).map do
|
14
|
+
Thread.new { p Timezone.lookup(33.7489954, -84.3879824).name }
|
15
|
+
end
|
16
|
+
|
17
|
+
threads.map(&:join)
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'timezone/lookup/basic'
|
2
2
|
require 'minitest/autorun'
|
3
|
+
require 'ostruct'
|
3
4
|
|
4
5
|
class BasicLookupTest < ::Minitest::Test
|
5
6
|
parallelize_me!
|
6
7
|
|
7
8
|
def config
|
8
|
-
@config ||=
|
9
|
+
@config ||= OpenStruct.new(protocol: 'http', url: 'example.com')
|
9
10
|
end
|
10
11
|
|
11
12
|
def lookup
|
@@ -17,10 +17,10 @@ class TestGeonames < ::Minitest::Test
|
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
20
|
-
def lookup(&_block)
|
20
|
+
def lookup(body = nil, &_block)
|
21
21
|
config = OpenStruct.new
|
22
22
|
config.username = 'timezone'
|
23
|
-
config.request_handler =
|
23
|
+
config.request_handler = HTTPTestClientFactory.new(body)
|
24
24
|
yield config if block_given?
|
25
25
|
|
26
26
|
Timezone::Lookup::Geonames.new(config)
|
@@ -38,28 +38,23 @@ class TestGeonames < ::Minitest::Test
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_lookup
|
41
|
-
mine = lookup
|
42
|
-
mine.client.body = File.open(mock_path + '/lat_lon_coords.txt').read
|
41
|
+
mine = lookup(File.open(mock_path + '/lat_lon_coords.txt').read)
|
43
42
|
|
44
43
|
assert_equal 'Australia/Adelaide', mine.lookup(*coordinates)
|
45
44
|
end
|
46
45
|
|
47
46
|
def test_lookup_with_etc
|
48
47
|
etc_data.each do |key, data|
|
49
|
-
|
50
|
-
mine
|
51
|
-
mock_path + "/lat_lon_coords_#{key}.txt"
|
52
|
-
).read
|
48
|
+
body = File.open(mock_path + "/lat_lon_coords_#{key}.txt").read
|
49
|
+
mine = lookup(body) { |c| c.offset_etc_zones = true }
|
53
50
|
|
54
51
|
assert_equal data[:name], mine.lookup(*data[:coordinates])
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
58
55
|
def test_wrong_offset
|
59
|
-
|
60
|
-
mine
|
61
|
-
mock_path + '/lat_lon_coords_wrong_offset.txt'
|
62
|
-
).read
|
56
|
+
body = File.open(mock_path + '/lat_lon_coords_wrong_offset.txt').read
|
57
|
+
mine = lookup(body) { |c| c.offset_etc_zones = true }
|
63
58
|
|
64
59
|
assert_nil mine.lookup(*coordinates)
|
65
60
|
end
|
@@ -83,8 +78,7 @@ class TestGeonames < ::Minitest::Test
|
|
83
78
|
end
|
84
79
|
|
85
80
|
def test_api_limit
|
86
|
-
mine = lookup
|
87
|
-
mine.client.body = File.open(mock_path + '/api_limit_reached.json').read
|
81
|
+
mine = lookup(File.open(mock_path + '/api_limit_reached.json').read)
|
88
82
|
|
89
83
|
assert_exception(
|
90
84
|
mine,
|
@@ -94,22 +88,19 @@ class TestGeonames < ::Minitest::Test
|
|
94
88
|
end
|
95
89
|
|
96
90
|
def test_invalid_latlong
|
97
|
-
mine = lookup
|
98
|
-
mine.client.body = File.open(mock_path + '/invalid_latlong.json').read
|
91
|
+
mine = lookup(File.open(mock_path + '/invalid_latlong.json').read)
|
99
92
|
|
100
93
|
assert_exception(mine, 'invalid lat/lng')
|
101
94
|
end
|
102
95
|
|
103
96
|
def test_no_result_found
|
104
|
-
mine = lookup
|
105
|
-
mine.client.body = File.open(mock_path + '/no_result_found.json').read
|
97
|
+
mine = lookup(File.open(mock_path + '/no_result_found.json').read)
|
106
98
|
|
107
99
|
assert_nil(mine.lookup(10, 10))
|
108
100
|
end
|
109
101
|
|
110
102
|
def test_invalid_parameter
|
111
|
-
mine = lookup
|
112
|
-
mine.client.body = File.open(mock_path + '/invalid_parameter.json').read
|
103
|
+
mine = lookup(File.open(mock_path + '/invalid_parameter.json').read)
|
113
104
|
|
114
105
|
assert_exception(mine, 'error parsing parameter')
|
115
106
|
end
|
@@ -10,14 +10,12 @@ class TestGoogle < ::Minitest::Test
|
|
10
10
|
[-34.92771808058, 138.477041423321]
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def lookup(body = nil, &_block)
|
14
14
|
config = OpenStruct.new
|
15
|
-
config.request_handler = HTTPTestClient
|
16
15
|
config.api_key = 'MTIzYWJj'
|
17
|
-
config
|
18
|
-
|
16
|
+
config.request_handler = HTTPTestClientFactory.new(body)
|
17
|
+
yield config if block_given?
|
19
18
|
|
20
|
-
def lookup
|
21
19
|
Timezone::Lookup::Google.new(config)
|
22
20
|
end
|
23
21
|
|
@@ -33,15 +31,14 @@ class TestGoogle < ::Minitest::Test
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def test_google_using_lat_long_coordinates
|
36
|
-
mine = lookup
|
37
|
-
mine.client.body = File.open(mock_path + '/google_lat_lon_coords.txt').read
|
34
|
+
mine = lookup(File.open(mock_path + '/google_lat_lon_coords.txt').read)
|
38
35
|
|
39
36
|
assert_equal 'Australia/Adelaide', mine.lookup(*coordinates)
|
40
37
|
end
|
41
38
|
|
42
39
|
def test_google_request_denied_read_lat_long_coordinates
|
43
|
-
mine = lookup
|
44
|
-
|
40
|
+
mine = lookup(nil)
|
41
|
+
|
45
42
|
assert_raises Timezone::Error::Google, 'The provided API key is invalid.' do
|
46
43
|
mine.lookup(*coordinates)
|
47
44
|
end
|
@@ -61,13 +58,10 @@ class TestGoogle < ::Minitest::Test
|
|
61
58
|
end
|
62
59
|
|
63
60
|
def test_url_enterprise
|
64
|
-
|
65
|
-
econfig.client_id = '123&asdf'
|
66
|
-
|
67
|
-
enterprise = Timezone::Lookup::Google.new(econfig)
|
61
|
+
mine = lookup { |c| c.client_id = '123&asdf' }
|
68
62
|
|
69
63
|
Timecop.freeze(Time.at(1_433_347_661)) do
|
70
|
-
result =
|
64
|
+
result = mine.send(:url, '123', '123')
|
71
65
|
params = {
|
72
66
|
'location' => '123%2C123',
|
73
67
|
'timestamp' => '1433347661',
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pan Thomakos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -708,6 +708,7 @@ files:
|
|
708
708
|
- test/mocks/lat_lon_coords_wrong_offset.txt
|
709
709
|
- test/mocks/no_result_found.json
|
710
710
|
- test/test_timezone.rb
|
711
|
+
- test/threadsafe_lookup.rb
|
711
712
|
- test/timezone/lookup/test_basic.rb
|
712
713
|
- test/timezone/lookup/test_geonames.rb
|
713
714
|
- test/timezone/lookup/test_google.rb
|
@@ -743,7 +744,7 @@ rubyforge_project: timezone
|
|
743
744
|
rubygems_version: 2.5.1
|
744
745
|
signing_key:
|
745
746
|
specification_version: 4
|
746
|
-
summary: timezone-1.2.
|
747
|
+
summary: timezone-1.2.5
|
747
748
|
test_files:
|
748
749
|
- test/data/Helsinki_rules_without_timestamps.json
|
749
750
|
- test/data/asia
|
@@ -760,6 +761,7 @@ test_files:
|
|
760
761
|
- test/mocks/lat_lon_coords_wrong_offset.txt
|
761
762
|
- test/mocks/no_result_found.json
|
762
763
|
- test/test_timezone.rb
|
764
|
+
- test/threadsafe_lookup.rb
|
763
765
|
- test/timezone/lookup/test_basic.rb
|
764
766
|
- test/timezone/lookup/test_geonames.rb
|
765
767
|
- test/timezone/lookup/test_google.rb
|
@@ -770,4 +772,3 @@ test_files:
|
|
770
772
|
- test/timezone/test_mathn_compatibility.rb
|
771
773
|
- test/timezone/test_nil_zone.rb
|
772
774
|
- test/timezone/test_zone.rb
|
773
|
-
has_rdoc:
|