eztz 1.0.0 → 2.0.0
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 +5 -5
- data/.github/workflows/test.yml +31 -0
- data/.gitignore +2 -0
- data/.standard.yml +2 -0
- data/Gemfile +2 -1
- data/README.md +17 -3
- data/Rakefile +7 -5
- data/eztz.gemspec +22 -22
- data/lib/eztz/client.rb +6 -5
- data/lib/eztz/errors.rb +2 -1
- data/lib/eztz/response.rb +10 -10
- data/lib/eztz/version.rb +2 -1
- data/lib/eztz.rb +8 -7
- metadata +31 -50
- data/.coveralls.yml +0 -2
- data/.rspec +0 -1
- data/.rubocop.yml +0 -14
- data/.ruby-version +0 -1
- data/.travis.yml +0 -8
- data/LICENSE +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aac0186b216b00582be61d8225b7546bc14ae1848eb347a532a04ca4d86142c2
|
4
|
+
data.tar.gz: 87d018cd6c18a45bc0ae5b141585ae122f1d7776028c2563a63ff2880adacf12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f11c757202ea3c80d0a579be9a3eaca66e017e59ecee708373ee25871f13c38ce635841c5872139347e64cf1a3ab7c3f1b906d7d6009e5ea68bff52743e52e54
|
7
|
+
data.tar.gz: 2fe7186d7b8d622a3399e1f717485775a0b61a4db4c0fa870513427fd6666aac50f34126b070d8bb05a5112ec5e9d3f0c31d746bd9544d177243e0aa5d2013e8
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [main]
|
6
|
+
pull_request:
|
7
|
+
branches: [main]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
os: [ubuntu-latest]
|
14
|
+
ruby-version: ["2.7", "3.0", "3.1", "3.2"]
|
15
|
+
|
16
|
+
runs-on: ${{ matrix.os }}
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v3
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true
|
25
|
+
- name: Run tests for Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }}
|
26
|
+
uses: paambaati/codeclimate-action@v3.0.0
|
27
|
+
env:
|
28
|
+
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
|
29
|
+
with:
|
30
|
+
coverageCommand: bundle exec rake
|
31
|
+
coverageLocations: ${{github.workspace}}/coverage/coverage.json:simplecov
|
data/.gitignore
CHANGED
data/.standard.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# Eztz
|
2
2
|
|
3
|
+
[](https://github.com/cmason/eztz/actions/workflows/test.yml)
|
4
|
+
[](https://codeclimate.com/github/cmason/eztz/maintainability)
|
5
|
+
[](https://codeclimate.com/github/cmason/eztz/test_coverage)
|
6
|
+
[](http://badge.fury.io/rb/eztz)
|
7
|
+
|
3
8
|
Ruby wrapper for the [Google Time Zone API](https://developers.google.com/maps/documentation/timezone)
|
4
9
|
|
5
|
-
|
6
|
-
[](https://travis-ci.org/cmason/eztz)
|
7
|
-
[](http://badge.fury.io/rb/eztz)
|
10
|
+
## Requirements
|
8
11
|
|
12
|
+
- Ruby >= 2.7
|
13
|
+
|
14
|
+
Other versions of Ruby may work, but the gem is tested against the above versions.
|
9
15
|
## Installation
|
10
16
|
|
11
17
|
Add this line to your application's Gemfile:
|
@@ -24,12 +30,20 @@ Or install it yourself as:
|
|
24
30
|
|
25
31
|
## Usage
|
26
32
|
|
33
|
+
An API key is required to access the Google Time Zone API. You can create a new
|
34
|
+
API key from the [Google Cloud Console](https://developers.google.com/maps/documentation/timezone/get-api-key).
|
35
|
+
|
36
|
+
# Set your API key
|
37
|
+
Eztz.api_key = 'YOUR_API_KEY'
|
38
|
+
|
39
|
+
# Pass location coordinates as a string
|
27
40
|
$ Eztz.timezone(location: '29.65,-95.28')
|
28
41
|
|
29
42
|
=> #<Eztz::TimeZoneResponse:0x007fe71ba2df78 @timestamp=1488834591, @dst_offset=0, @error_message=nil, @raw_offset=-21600, @status="OK", @id="America/Chicago", @name="Central Standard Time">
|
30
43
|
|
31
44
|
or
|
32
45
|
|
46
|
+
# Pass location coordinates as an array
|
33
47
|
$ Eztz.timezone(location: [29.65, -95.28])
|
34
48
|
|
35
49
|
=> #<Eztz::TimeZoneResponse:0x007fe71ba2df78 @timestamp=1488834591, @dst_offset=0, @error_message=nil, @raw_offset=-21600, @status="OK", @id="America/Chicago", @name="Central Standard Time">
|
data/Rakefile
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
require "standard/rake"
|
4
6
|
|
5
7
|
Rake::TestTask.new(:test) do |t|
|
6
|
-
t.libs <<
|
7
|
-
t.libs <<
|
8
|
-
t.test_files = FileList[
|
8
|
+
t.libs << "test"
|
9
|
+
t.libs << "lib"
|
10
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
9
11
|
end
|
10
12
|
|
11
13
|
task default: :test
|
data/eztz.gemspec
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require "eztz/version"
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
8
|
+
spec.name = "eztz"
|
9
|
+
spec.version = Eztz::VERSION
|
10
|
+
spec.authors = ["Chris Mason"]
|
11
|
+
spec.email = ["chris@chaione.com"]
|
11
12
|
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
13
|
+
spec.summary = "Ruby wrapper for the Google Time Zone API"
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = "https://github.com/cmason/eztz"
|
16
|
+
spec.license = "MIT"
|
16
17
|
|
17
|
-
spec.files
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
19
|
f.match(%r{^(test|spec|features)/})
|
19
20
|
end
|
20
|
-
spec.bindir
|
21
|
-
spec.executables
|
22
|
-
spec.require_paths = [
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
23
24
|
|
24
|
-
spec.required_ruby_version =
|
25
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7")
|
25
26
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency 'webmock', '~> 2.3'
|
27
|
+
spec.add_development_dependency "bundler", ">= 2.2.33"
|
28
|
+
spec.add_development_dependency "minitest"
|
29
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
30
|
+
spec.add_development_dependency "simplecov", ">= 0.22.0"
|
31
|
+
spec.add_development_dependency "standard"
|
32
|
+
spec.add_development_dependency "webmock"
|
33
33
|
end
|
data/lib/eztz/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
4
5
|
|
5
6
|
module Eztz
|
6
7
|
# The Google Time Zone API client.
|
@@ -12,7 +13,7 @@ module Eztz
|
|
12
13
|
|
13
14
|
def initialize(api_key: Eztz.api_key)
|
14
15
|
@api_key = api_key
|
15
|
-
@uri = URI(
|
16
|
+
@uri = URI("https://maps.googleapis.com/maps/api/timezone/json")
|
16
17
|
end
|
17
18
|
|
18
19
|
# Gets timezone information for a location on earth,
|
@@ -32,7 +33,7 @@ module Eztz
|
|
32
33
|
# @raise [ArgumentError] if location is not provided
|
33
34
|
# @raise [ApiError] if the API returns an error response.
|
34
35
|
# @return [Eztz::TimeZoneResponse] the resulting timezone data.
|
35
|
-
def timezone(location:, timestamp: Time.now.utc.to_i, language:
|
36
|
+
def timezone(location:, timestamp: Time.now.utc.to_i, language: "en")
|
36
37
|
uri.query = query_params(location, timestamp, language)
|
37
38
|
res = Net::HTTP.get_response(uri)
|
38
39
|
raise ApiError, res.body unless res.is_a?(Net::HTTPSuccess)
|
@@ -45,7 +46,7 @@ module Eztz
|
|
45
46
|
|
46
47
|
def query_params(location, timestamp, language)
|
47
48
|
URI.encode_www_form(
|
48
|
-
location: (location.respond_to?(:join) ? location.join(
|
49
|
+
location: (location.respond_to?(:join) ? location.join(",") : location),
|
49
50
|
timestamp: timestamp,
|
50
51
|
language: language,
|
51
52
|
key: api_key
|
data/lib/eztz/errors.rb
CHANGED
data/lib/eztz/response.rb
CHANGED
@@ -36,7 +36,7 @@ module Eztz
|
|
36
36
|
# @!attribute timestamp [r]
|
37
37
|
# @return [Integer] The timestamp used in the request.
|
38
38
|
attr_reader :dst_offset, :error_message, :id, :name,
|
39
|
-
|
39
|
+
:raw_offset, :status, :timestamp
|
40
40
|
|
41
41
|
# @param timestamp [Integer] The timestamp used in the request
|
42
42
|
# @param response [Hash] The parsed JSON response from the api call
|
@@ -44,13 +44,13 @@ module Eztz
|
|
44
44
|
@timestamp = timestamp
|
45
45
|
@dst_offset, @error_message, @raw_offset, @status, @id, @name =
|
46
46
|
response.values_at(
|
47
|
-
|
48
|
-
|
47
|
+
"dstOffset", "error_message", "rawOffset", "status", "timeZoneId",
|
48
|
+
"timeZoneName"
|
49
49
|
)
|
50
50
|
end
|
51
51
|
|
52
52
|
def success?
|
53
|
-
status ==
|
53
|
+
status == "OK"
|
54
54
|
end
|
55
55
|
|
56
56
|
# The local time of the location is the sum of the :timestamp,
|
@@ -64,13 +64,13 @@ module Eztz
|
|
64
64
|
# @return [Hash]
|
65
65
|
def to_h
|
66
66
|
{
|
67
|
-
dst_offset:
|
67
|
+
dst_offset: dst_offset,
|
68
68
|
error_message: error_message,
|
69
|
-
id:
|
70
|
-
name:
|
71
|
-
raw_offset:
|
72
|
-
status:
|
73
|
-
timestamp:
|
69
|
+
id: id,
|
70
|
+
name: name,
|
71
|
+
raw_offset: raw_offset,
|
72
|
+
status: status,
|
73
|
+
timestamp: timestamp
|
74
74
|
}
|
75
75
|
end
|
76
76
|
end
|
data/lib/eztz/version.rb
CHANGED
data/lib/eztz.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
|
3
|
+
require "eztz/client"
|
4
|
+
require "eztz/errors"
|
5
|
+
require "eztz/response"
|
6
|
+
require "eztz/version"
|
6
7
|
|
7
8
|
# Ruby wrapper for the Google Time Zone API.
|
8
9
|
# @example Sample usage
|
@@ -58,10 +59,10 @@ module Eztz
|
|
58
59
|
# @dst_offset=3600, @error_message=nil, @raw_offset=36000,
|
59
60
|
# @status="OK", @id="Australia/Sydney",
|
60
61
|
# @name="Australian Eastern Daylight Time">
|
61
|
-
def timezone(location:, timestamp: Time.now.utc.to_i, language:
|
62
|
+
def timezone(location:, timestamp: Time.now.utc.to_i, language: "en")
|
62
63
|
client.timezone(location: location,
|
63
|
-
|
64
|
-
|
64
|
+
timestamp: timestamp,
|
65
|
+
language: language)
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
metadata
CHANGED
@@ -1,73 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eztz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Mason
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.33
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.33
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 12.3.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.22.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.22.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: standard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -80,34 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.47'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.47'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: webmock
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- - "
|
87
|
+
- - ">="
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '0'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- - "
|
94
|
+
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '0'
|
111
97
|
description: Ruby wrapper for the Google Time Zone API
|
112
98
|
email:
|
113
99
|
- chris@chaione.com
|
@@ -115,16 +101,12 @@ executables: []
|
|
115
101
|
extensions: []
|
116
102
|
extra_rdoc_files: []
|
117
103
|
files:
|
118
|
-
- ".coveralls.yml"
|
119
104
|
- ".editorconfig"
|
105
|
+
- ".github/workflows/test.yml"
|
120
106
|
- ".gitignore"
|
121
|
-
- ".
|
122
|
-
- ".rubocop.yml"
|
123
|
-
- ".ruby-version"
|
124
|
-
- ".travis.yml"
|
107
|
+
- ".standard.yml"
|
125
108
|
- CODE_OF_CONDUCT.md
|
126
109
|
- Gemfile
|
127
|
-
- LICENSE
|
128
110
|
- LICENSE.txt
|
129
111
|
- README.md
|
130
112
|
- Rakefile
|
@@ -140,7 +122,7 @@ homepage: https://github.com/cmason/eztz
|
|
140
122
|
licenses:
|
141
123
|
- MIT
|
142
124
|
metadata: {}
|
143
|
-
post_install_message:
|
125
|
+
post_install_message:
|
144
126
|
rdoc_options: []
|
145
127
|
require_paths:
|
146
128
|
- lib
|
@@ -148,16 +130,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
130
|
requirements:
|
149
131
|
- - ">="
|
150
132
|
- !ruby/object:Gem::Version
|
151
|
-
version: '2.
|
133
|
+
version: '2.7'
|
152
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
135
|
requirements:
|
154
136
|
- - ">="
|
155
137
|
- !ruby/object:Gem::Version
|
156
138
|
version: '0'
|
157
139
|
requirements: []
|
158
|
-
|
159
|
-
|
160
|
-
signing_key:
|
140
|
+
rubygems_version: 3.4.6
|
141
|
+
signing_key:
|
161
142
|
specification_version: 4
|
162
143
|
summary: Ruby wrapper for the Google Time Zone API
|
163
144
|
test_files: []
|
data/.coveralls.yml
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--format nested --colour
|
data/.rubocop.yml
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.4.0
|
data/.travis.yml
DELETED
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Chris Mason
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|