eztz 0.0.4 → 1.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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTI2MmIyYzdhNjEzZmVlNjhhNzQxNzk0MjY0YzcxMWVkNmYyZDhlNg==
5
- data.tar.gz: !binary |-
6
- OWI4OGMzMWM5MzRmZGRhOWM5YzMzNThlZGI0ZDJkMWE4M2YxNTdkNA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MDMxOGY1ZmYzMTc1ZjU2MjYwZWM2YTg3ODFiZDAzN2U3MTYxN2JlMGQ3Yjc2
10
- MjIzOTNlYzA2YTYwNjA4OTdkMmQ5ZjkyYTM4M2ZiNTZjZDAzOWU5YzdmNDE0
11
- NDY3ZTM1ZDA1YWUxNGM4MzY5MjYzZDM0YTAwZDFmMjNmMTNiZTk=
12
- data.tar.gz: !binary |-
13
- ZWFjYzk4MWZkZDNjODgzNzgzMTE4MjgyMTM1YTk3YTc1NjE4OTY4NDUxY2Ez
14
- ZGEzNWYzZGZhMjYwNWJmZDJmNzU5OWEyN2IyNmJhMmZhNjQ5ZGZhODNjMTIy
15
- MTQ4ZTFjYjgwY2QzNDE5YzM3YmVkM2JlOGU0NWRjMDk5YTA3ODQ=
2
+ SHA1:
3
+ metadata.gz: 664dcc7aa9f9ccd683c49115e13ad195b6328881
4
+ data.tar.gz: 2984feb837d7585f699929a727f9cd1172dd2f4c
5
+ SHA512:
6
+ metadata.gz: 0d6b729d39b0f33ddbac8dbbed358065da10c03ccff53a63ba0d9c084d5b3afb4854aed02532f4ad0ad7f33e96c431e853c751dc8f05d77d571cdabb389d27a2
7
+ data.tar.gz: 6e5a6e2cea8e2349d690363bfabd941f4575f13dc78d55e13bcf51c6aad8abfa7c033746e4771cafcb198e89c592f49b6d690fbf942e820f049426143bb0fccc
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+
@@ -0,0 +1,13 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
13
+
data/.gitignore CHANGED
@@ -1,17 +1,9 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'vendor/**/*'
4
+ - 'test/fixtures/**/*'
5
+ - 'test/**/*'
6
+ - 'tmp/**/*'
7
+ TargetRubyVersion: 2.1
8
+
9
+ Style/Encoding:
10
+ EnforcedStyle: when_needed
11
+ Enabled: true
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ EnforcedStyle: always
@@ -0,0 +1 @@
1
+ 2.4.0
@@ -1,10 +1,8 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - "1.9.2"
4
- - "1.9.3"
5
- - "2.0.0"
6
- - jruby-19mode # JRuby in 1.9 mode
7
- - rbx-19mode
8
- # uncomment this line if your project needs to run something other than `rake`:
9
- script: bundle exec rspec spec
10
-
4
+ - 2.4.0
5
+ - 2.3.3
6
+ - 2.2
7
+ - 2.1
8
+ before_install: gem install bundler -v 1.14.5
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at chris@chaione.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in eztz.gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Chris Mason
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -4,12 +4,15 @@ Ruby wrapper for the [Google Time Zone API](https://developers.google.com/maps/d
4
4
 
5
5
  [![Code Climate](https://codeclimate.com/github/cmason/eztz.png)](https://codeclimate.com/github/cmason/eztz)
6
6
  [![Build Status](https://travis-ci.org/cmason/eztz.png?branch=master)](https://travis-ci.org/cmason/eztz)
7
+ [![Gem Version](https://badge.fury.io/rb/eztz.png)](http://badge.fury.io/rb/eztz)
7
8
 
8
9
  ## Installation
9
10
 
10
11
  Add this line to your application's Gemfile:
11
12
 
12
- gem 'eztz'
13
+ ```ruby
14
+ gem 'eztz'
15
+ ```
13
16
 
14
17
  And then execute:
15
18
 
@@ -21,33 +24,36 @@ Or install it yourself as:
21
24
 
22
25
  ## Usage
23
26
 
24
- $ Eztz.timezone(lat: -33.86, lng: 151.20)
27
+ $ Eztz.timezone(location: '29.65,-95.28')
25
28
 
26
- => #<Hashie::Mash dstOffset=3600.0 rawOffset=36000.0 status="OK" timeZoneId="Australia/Sydney" timeZoneName="Australian Eastern Daylight Time">
29
+ => #<Eztz::TimeZoneResponse:0x007fe71ba2df78 @timestamp=1488834591, @dst_offset=0, @error_message=nil, @raw_offset=-21600, @status="OK", @id="America/Chicago", @name="Central Standard Time">
27
30
 
28
31
  or
29
32
 
30
- $ Eztz.timezone(location: '-33.86,151.20')
33
+ $ Eztz.timezone(location: [29.65, -95.28])
31
34
 
32
- => #<Hashie::Mash dstOffset=3600.0 rawOffset=36000.0 status="OK" timeZoneId="Australia/Sydney" timeZoneName="Australian Eastern Daylight Time">
35
+ => #<Eztz::TimeZoneResponse:0x007fe71ba2df78 @timestamp=1488834591, @dst_offset=0, @error_message=nil, @raw_offset=-21600, @status="OK", @id="America/Chicago", @name="Central Standard Time">
33
36
 
34
- Params should take one of the following forms:
37
+ Optional parameters include:
35
38
 
36
- { location: "-33.86,151.20" }
37
- { lat: -33.86, lng: 151.20 }
39
+ * `timestamp:` specifies the desired time as seconds since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses the timestamp to determine whether or not Daylight Savings should be applied. Times before 1970 can be expressed as negative values. Defaults to the current time.
40
+ * `language:` The language in which to return results Defaults to 'en'. A list of supported languages can be found at developers.google.com/maps/faq#languagesupport
38
41
 
39
- ## Calculating the Local Time
42
+ ## Development
40
43
 
41
- The local time of a given location is the sum of the `Time.now.to_i` , and the `dstOffset` and `rawOffset` fields from the result.
44
+ After checking out the repo, run `bin/setup` to install dependencies.
45
+ Then, run `rake test` to run the tests. You can also run `bin/console`
46
+ for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`.
49
+ To release a new version, update the version number in `version.rb`,
50
+ and then run `bundle exec rake release`, which will create a git tag for the version,
51
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
52
 
43
53
  ## Contributing
44
54
 
45
- 1. Fork it
46
- 2. Create your feature branch (`git checkout -b my-new-feature`)
47
- 3. Commit your changes (`git commit -am 'Added some feature'`)
48
- 4. Push to the branch (`git push origin my-new-feature`)
49
- 5. Create new Pull Request
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cmason/eztz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
50
56
 
51
57
  ## License
52
58
 
53
- This code is provided under the MIT license. See [LICENSE](LICENSE) for more details.
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'test'
7
+ t.libs << 'lib'
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ require 'bundler/setup'
4
+ require 'eztz'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,26 +1,33 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/eztz/version', __FILE__)
1
+ # frozen_string_literal: true
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eztz/version'
3
5
 
4
- Gem::Specification.new do |gem|
5
- gem.name = "eztz"
6
- gem.authors = ["Chris Mason"]
7
- gem.email = ["chris@chaione.com"]
8
- gem.description = %q{Ruby wrapper for the Google Time Zone API}
9
- gem.license = 'MIT'
10
- gem.summary = gem.description
11
- gem.homepage = "https://github.com/cmason/eztz"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'eztz'
8
+ spec.version = Eztz::VERSION
9
+ spec.authors = ['Chris Mason']
10
+ spec.email = ['chris@chaione.com']
12
11
 
13
- gem.files = `git ls-files`.split($\)
14
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
- gem.require_paths = ["lib"]
17
- gem.version = Eztz::VERSION
12
+ spec.summary = 'Ruby wrapper for the Google Time Zone API'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/cmason/eztz'
15
+ spec.license = 'MIT'
18
16
 
19
- gem.add_development_dependency 'rake'
20
- gem.add_development_dependency 'rspec', '~> 2.12.0'
21
- gem.add_development_dependency 'vcr', '~> 2.4.0'
22
- gem.add_development_dependency 'webmock', '~> 1.9.3'
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
23
 
24
- gem.add_dependency 'httparty', '~> 0.10'
25
- gem.add_dependency 'hashie', '>= 1.2.0'
24
+ spec.required_ruby_version = '>= 2.1'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.14'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'minitest', '~> 5.0'
29
+ spec.add_development_dependency 'coveralls'
30
+ spec.add_development_dependency 'codeclimate-test-reporter'
31
+ spec.add_development_dependency 'rubocop', '~> 0.47'
32
+ spec.add_development_dependency 'webmock', '~> 2.3'
26
33
  end
@@ -1,22 +1,67 @@
1
- require "eztz/client"
2
- require "eztz/version"
1
+ # frozen_string_literal: true
2
+ require 'eztz/client'
3
+ require 'eztz/errors'
4
+ require 'eztz/response'
5
+ require 'eztz/version'
3
6
 
7
+ # Ruby wrapper for the Google Time Zone API.
8
+ # @example Sample usage
9
+ # # Set your api key
10
+ # Eztz.api_key = 'YOUR_API_KEY'
11
+ # # location as a string
12
+ # Eztz.timezone(location: "-33.86,151.20")
13
+ # # location as an array
14
+ # Eztz.timezone(location: [-33.86,151.20])
4
15
  module Eztz
5
- # Gets timezone information for a location on earth,
6
- # as well as that location's time offset from UTC.
7
- #
8
- # @param [Hash] params options to get timezone information.
9
- # Must include :location or :lat & :lng
10
- # @option params [String] :location a comma-separated lat,lng tuple. (eg. "-33.86,151.20")
11
- # @option params [String, Float] :lat latitude (eg. -33.86)
12
- # @option params [String, Float] :lng longitude (ex. 151.20)
13
- # @raise [ArgumentError] if :location or :lat and :lng are not provided
14
- # @return [Hashie::Mash] the resulting timezone data.
15
- # @example Get timezone data
16
- # Eztz.timezone(lat: -33.86, lng: 151.20)
17
- # => #<Hashie::Mash dstOffset=3600.0 rawOffset=36000.0 status="OK" timeZoneId="Australia/Sydney" timeZoneName="Australian Eastern Daylight Time">
18
- # @see Client.timezone
19
- def self.timezone(params={})
20
- Eztz::Client.timezone(params)
16
+ class << self
17
+ # @!attribute api_key
18
+ # @return [String] Your application's API key.
19
+ # Api keys can be obtained at
20
+ # https://developers.google.com/maps/documentation/timezone/get-api-key
21
+ attr_accessor :api_key
22
+
23
+ # @example Configure api key with a configuration block
24
+ # Eztz.configure do |config|
25
+ # config.api_key = 'XYZ'
26
+ # end
27
+ def configure
28
+ yield self
29
+ true
30
+ end
31
+
32
+ # The Eztz client
33
+ # @return [Eztz::Client]
34
+ def client
35
+ @client ||= Eztz::Client.new
36
+ end
37
+
38
+ # Gets timezone information for a location on earth,
39
+ # as well as that location's time offset from UTC.
40
+ #
41
+ # @param location [String, Array] a comma-separated lat,lng tuple
42
+ # (eg. "-33.86,151.20"), representing the location to look up. Can also be
43
+ # an array (eg. [-33.86, 151.20]).
44
+ # @param timestamp [Integer] specifies the desired time as seconds
45
+ # since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses
46
+ # the timestamp to determine whether or not Daylight Savings should be
47
+ # applied. Times before 1970 can be expressed as negative values.
48
+ # Defaults to the current time.
49
+ # @param language [String] The language in which to return results
50
+ # Defaults to 'en'. A list of supported languages can be found at
51
+ # https://developers.google.com/maps/faq#languagesupport
52
+ # @raise [ArgumentError] if location is not provided
53
+ # @raise [ApiError] if the API returns an error response.
54
+ # @return [Eztz::TimeZoneResponse] the resulting timezone data.
55
+ # @example Get the timezone for a location
56
+ # Eztz.timezone(location: "-33.86,151.20")
57
+ # => #<Eztz::TimeZoneResponse:0x007fe71c906298 @timestamp=1488580176,
58
+ # @dst_offset=3600, @error_message=nil, @raw_offset=36000,
59
+ # @status="OK", @id="Australia/Sydney",
60
+ # @name="Australian Eastern Daylight Time">
61
+ def timezone(location:, timestamp: Time.now.utc.to_i, language: 'en')
62
+ client.timezone(location: location,
63
+ timestamp: timestamp,
64
+ language: language)
65
+ end
21
66
  end
22
67
  end
@@ -1,49 +1,55 @@
1
- require 'httparty'
2
- require 'hashie'
1
+ # frozen_string_literal: true
2
+ require 'net/http'
3
+ require 'json'
3
4
 
4
5
  module Eztz
6
+ # The Google Time Zone API client.
7
+ # If you need to make requests with multiple api keys, then you'll probably
8
+ # want to use this class directly. Otherwise, it will be easier to use
9
+ # {::Eztz#timezone Eztz.timezone}
5
10
  class Client
6
- include HTTParty
7
- base_uri 'https://maps.googleapis.com'
11
+ attr_reader :api_key
12
+
13
+ def initialize(api_key: Eztz.api_key)
14
+ @api_key = api_key
15
+ @uri = URI('https://maps.googleapis.com/maps/api/timezone/json')
16
+ end
8
17
 
9
18
  # Gets timezone information for a location on earth,
10
19
  # as well as that location's time offset from UTC.
11
20
  #
12
- # @param [Hash] params options to get timezone information.
13
- # Must include :location or :lat & :lng
14
- # @option params [String] :location a comma-separated lat,lng tuple. (eg. "-33.86,151.20")
15
- # @option params [String, Float] :lat latitude (eg. -33.86)
16
- # @option params [String, Float] :lng longitude (ex. 151.20)
17
- # @option params [Boolean] :sensor specifies whether the application requesting data is using a sensor. Defaults to _false_
18
- # @option params [Integer] :timestamp specifies the desired time as seconds since midnight, January 1, 1970 UTC. Defaults to _now_
19
- # @option params [String] :language the language in which to return results. Defaults to _en_.
20
- # @raise [ArgumentError] if :location or :lat and :lng are not provided
21
- # @return [Hashie::Mash] the resulting timezone data. Response has the following properties:
22
- # * *dstOffset* : the offset for daylight-savings time in seconds.
23
- # This will be zero if the time zone is not in Daylight Savings Time during the specified timestamp.
24
- # * *rawOffset* : the offset from UTC (in seconds) for the given location.
25
- # This does not take into effect daylight savings.
26
- # * *timeZoneId* : a string containing the ID of the time zone, such as "America/Los_Angeles" or "Australia/Sydney".
27
- # * *timeZoneName* : a string containing the long form name of the time zone.
28
- # This field will be localized if the language parameter is set.
29
- # eg. "Pacific Daylight Time" or "Australian Eastern Daylight Time"
30
- # * *status* : a string indicating the status of the response. Status will be one of the following:
31
- # * *OK* - indicates that the request was successful.
32
- # * *INVALID_REQUEST* - indicates that the request was malformed.
33
- # * *OVER_QUERY_LIMIT* - indicates the requestor has exceeded quota.
34
- # * *REQUEST_DENIED* - indicates that the the API did not complete the request. Confirm that the request was sent over http instead of https.
35
- # * *UNKNOWN_ERROR* - indicates an unknown error.
36
- # * *ZERO_RESULTS* - indicates that no time zone data could be found for the specified position or time.
37
- # Confirm that the request is for a location on land, and not over water.
38
- # @example Get timezone data
39
- # Eztz::Client.timezone(location: "-33.86,151.20")
40
- # => #<Hashie::Mash dstOffset=3600.0 rawOffset=36000.0 status="OK" timeZoneId="Australia/Sydney" timeZoneName="Australian Eastern Daylight Time">
41
- def self.timezone(params={})
42
- params[:location] = "#{params.delete(:lat)},#{params.delete(:lng)}" if params[:lat] && params[:lng]
43
- raise ArgumentError, 'You must provide a location' if params[:location].nil? || params[:location].empty? || params[:location] == ','
44
- params[:sensor] ||= false
45
- params[:timestamp] ||= Time.now.to_i
46
- Hashie::Mash.new self.get('/maps/api/timezone/json', query: params)
21
+ # @param location [String, Array] a comma-separated lat,lng tuple
22
+ # (eg. "-33.86,151.20"), representing the location to look up. Can also be
23
+ # an array (eg. [-33.86, 151.20]).
24
+ # @param timestamp [Integer] specifies the desired time as seconds
25
+ # since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses
26
+ # the timestamp to determine whether or not Daylight Savings should be
27
+ # applied. Times before 1970 can be expressed as negative values.
28
+ # Defaults to the current time.
29
+ # @param language [String] The language in which to return results
30
+ # Defaults to 'en'. A list of supported languages can be found at
31
+ # https://developers.google.com/maps/faq#languagesupport
32
+ # @raise [ArgumentError] if location is not provided
33
+ # @raise [ApiError] if the API returns an error response.
34
+ # @return [Eztz::TimeZoneResponse] the resulting timezone data.
35
+ def timezone(location:, timestamp: Time.now.utc.to_i, language: 'en')
36
+ uri.query = query_params(location, timestamp, language)
37
+ res = Net::HTTP.get_response(uri)
38
+ raise ApiError, res.body unless res.is_a?(Net::HTTPSuccess)
39
+ TimeZoneResponse.new(timestamp, JSON.parse(res.body))
40
+ end
41
+
42
+ private
43
+
44
+ attr_reader :uri
45
+
46
+ def query_params(location, timestamp, language)
47
+ URI.encode_www_form(
48
+ location: (location.respond_to?(:join) ? location.join(',') : location),
49
+ timestamp: timestamp,
50
+ language: language,
51
+ key: api_key
52
+ )
47
53
  end
48
54
  end
49
55
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+
4
+ module Eztz
5
+ # Thrown when the API returns an error response.
6
+ class ApiError < StandardError
7
+ attr_reader :message
8
+
9
+ def initialize(response)
10
+ @message = response
11
+ end
12
+
13
+ def to_s
14
+ @message.to_s
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eztz
4
+ # Encapsulates the data from the timezone api
5
+ class TimeZoneResponse
6
+ # @!attribute dst_offset [r]
7
+ # @return [Integer] The offset for daylight-savings time in seconds.
8
+ # This will be zero if the time zone is not in Daylight Savings Time
9
+ # during the specified timestamp.
10
+ # @!attribute error_message [r]
11
+ # @return [String] More detailed information about the reasons behind the
12
+ # given status code, if other than OK.
13
+ # @!attribute id [r]
14
+ # @return [String] A string containing the ID of the time zone, such as
15
+ # "America/Los_Angeles" or "Australia/Sydney".
16
+ # @!attribute name [r]
17
+ # @return [String] A string containing the long form name of the time
18
+ # zone. This field will be localized if the language parameter was set.
19
+ # eg. "Pacific Daylight Time" or "Australian Eastern Daylight Time"
20
+ # @!attribute raw_offset [r]
21
+ # @return [Integer] The offset from UTC (in seconds) for the given
22
+ # location. This does not take into effect daylight savings.
23
+ # @!attribute status [r]
24
+ # @return [String] a string indicating the status of the response. Status
25
+ # will be one of the following:
26
+ # * *OK* - indicates that the request was successful.
27
+ # * *INVALID_REQUEST* - indicates that the request was malformed.
28
+ # * *OVER_QUERY_LIMIT* - indicates the requestor has exceeded quota.
29
+ # * *REQUEST_DENIED* - indicates that the the API did not complete the
30
+ # request. Confirm that the request was sent over http instead of
31
+ # https.
32
+ # * *UNKNOWN_ERROR* - indicates an unknown error.
33
+ # * *ZERO_RESULTS* - indicates that no time zone data could be found
34
+ # for the specified position or time. Confirm that the request is for
35
+ # a location on land, and not over water.
36
+ # @!attribute timestamp [r]
37
+ # @return [Integer] The timestamp used in the request.
38
+ attr_reader :dst_offset, :error_message, :id, :name,
39
+ :raw_offset, :status, :timestamp
40
+
41
+ # @param timestamp [Integer] The timestamp used in the request
42
+ # @param response [Hash] The parsed JSON response from the api call
43
+ def initialize(timestamp, response)
44
+ @timestamp = timestamp
45
+ @dst_offset, @error_message, @raw_offset, @status, @id, @name =
46
+ response.values_at(
47
+ 'dstOffset', 'error_message', 'rawOffset', 'status', 'timeZoneId',
48
+ 'timeZoneName'
49
+ )
50
+ end
51
+
52
+ def success?
53
+ status == 'OK'
54
+ end
55
+
56
+ # The local time of the location is the sum of the :timestamp,
57
+ # :dst_offset and :raw_offset.
58
+ # @return [Time]
59
+ def local_time
60
+ Time.at(timestamp.to_i + dst_offset.to_i + raw_offset.to_i)
61
+ end
62
+
63
+ # The object as a Hash.
64
+ # @return [Hash]
65
+ def to_h
66
+ {
67
+ dst_offset: dst_offset,
68
+ error_message: error_message,
69
+ id: id,
70
+ name: name,
71
+ raw_offset: raw_offset,
72
+ status: status,
73
+ timestamp: timestamp
74
+ }
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Eztz
2
- VERSION = "0.0.4"
3
+ VERSION = '1.0.0'.freeze
3
4
  end
metadata CHANGED
@@ -1,99 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eztz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Mason
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2013-09-04 00:00:00.000000000 Z
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ! '>='
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: '10.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ! '>='
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
40
+ version: '10.0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: rspec
42
+ name: minitest
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ~>
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 2.12.0
47
+ version: '5.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ~>
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 2.12.0
54
+ version: '5.0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: vcr
56
+ name: coveralls
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: 2.4.0
61
+ version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: 2.4.0
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: webmock
70
+ name: codeclimate-test-reporter
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ~>
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: 1.9.3
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ~>
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: 1.9.3
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: httparty
84
+ name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ~>
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.10'
76
- type: :runtime
89
+ version: '0.47'
90
+ type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ~>
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.10'
96
+ version: '0.47'
83
97
  - !ruby/object:Gem::Dependency
84
- name: hashie
98
+ name: webmock
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ! '>='
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 1.2.0
90
- type: :runtime
103
+ version: '2.3'
104
+ type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ! '>='
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 1.2.0
110
+ version: '2.3'
97
111
  description: Ruby wrapper for the Google Time Zone API
98
112
  email:
99
113
  - chris@chaione.com
@@ -101,22 +115,27 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
- - .gitignore
105
- - .rspec
106
- - .travis.yml
118
+ - ".coveralls.yml"
119
+ - ".editorconfig"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".ruby-version"
124
+ - ".travis.yml"
125
+ - CODE_OF_CONDUCT.md
107
126
  - Gemfile
108
127
  - LICENSE
128
+ - LICENSE.txt
109
129
  - README.md
110
130
  - Rakefile
131
+ - bin/console
132
+ - bin/setup
111
133
  - eztz.gemspec
112
134
  - lib/eztz.rb
113
135
  - lib/eztz/client.rb
136
+ - lib/eztz/errors.rb
137
+ - lib/eztz/response.rb
114
138
  - lib/eztz/version.rb
115
- - spec/acceptance/get_timezone_spec.rb
116
- - spec/eztz_spec.rb
117
- - spec/fixtures/cassettes/emtpy_results.yml
118
- - spec/fixtures/cassettes/valid_timezone_lookup.yml
119
- - spec/spec_helper.rb
120
139
  homepage: https://github.com/cmason/eztz
121
140
  licenses:
122
141
  - MIT
@@ -127,23 +146,18 @@ require_paths:
127
146
  - lib
128
147
  required_ruby_version: !ruby/object:Gem::Requirement
129
148
  requirements:
130
- - - ! '>='
149
+ - - ">="
131
150
  - !ruby/object:Gem::Version
132
- version: '0'
151
+ version: '2.1'
133
152
  required_rubygems_version: !ruby/object:Gem::Requirement
134
153
  requirements:
135
- - - ! '>='
154
+ - - ">="
136
155
  - !ruby/object:Gem::Version
137
156
  version: '0'
138
157
  requirements: []
139
158
  rubyforge_project:
140
- rubygems_version: 2.0.0
159
+ rubygems_version: 2.6.8
141
160
  signing_key:
142
161
  specification_version: 4
143
162
  summary: Ruby wrapper for the Google Time Zone API
144
- test_files:
145
- - spec/acceptance/get_timezone_spec.rb
146
- - spec/eztz_spec.rb
147
- - spec/fixtures/cassettes/emtpy_results.yml
148
- - spec/fixtures/cassettes/valid_timezone_lookup.yml
149
- - spec/spec_helper.rb
163
+ test_files: []
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eztz do
4
- context "lookup timezone" do
5
- it "by location" do
6
- VCR.use_cassette("valid_timezone_lookup") do
7
- tz = Eztz.timezone(location: "37.7749295,-122.4194155", timestamp: 1362096689)
8
- tz.dstOffset.should == 0.0
9
- tz.rawOffset.should == -28800.0
10
- tz.status.should == 'OK'
11
- tz.timeZoneId.should == "America/Los_Angeles"
12
- tz.timeZoneName.should == "Pacific Standard Time"
13
- end
14
- end
15
-
16
- it "by :lat :lng" do
17
- VCR.use_cassette("valid_timezone_lookup") do
18
- tz = Eztz.timezone(lat: 37.7749295, lng: -122.4194155, timestamp: 1362096689)
19
- tz.dstOffset.should == 0.0
20
- tz.rawOffset.should == -28800.0
21
- tz.status.should == 'OK'
22
- tz.timeZoneId.should == "America/Los_Angeles"
23
- tz.timeZoneName.should == "Pacific Standard Time"
24
- end
25
- end
26
-
27
- it "with no results" do
28
- VCR.use_cassette("emtpy_results") do
29
- tz = Eztz.timezone(lat: 0, lng: 0, timestamp: 1362096689)
30
- tz.status.should == 'ZERO_RESULTS'
31
- tz.timeZpneId.should be_nil
32
- end
33
- end
34
- end
35
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Eztz do
4
- it "should define a version" do
5
- Eztz::VERSION.should_not be_nil
6
- end
7
-
8
- context "timezone lookup" do
9
- let(:query) {
10
- {
11
- query: {
12
- location:"37.7749295,-122.4194155",
13
- timestamp:1,
14
- sensor:false
15
- }
16
- }
17
- }
18
-
19
- context "with invalid parameters" do
20
- it "should raise an argument error" do
21
- expect { Eztz.timezone }.to raise_error ArgumentError
22
- expect { Eztz.timezone lat: '', lng: ''}.to raise_error ArgumentError
23
- end
24
- end
25
-
26
- context "by location" do
27
- let(:params) { {location: "37.7749295,-122.4194155", timestamp: 1, sensor: false} }
28
- it "should get timezone by location" do
29
- Eztz::Client.should_receive(:get).with("/maps/api/timezone/json", query )
30
- Eztz.timezone(params)
31
- end
32
- end
33
-
34
- context "by :lat :lng" do
35
- let(:params) { {lat: 37.7749295, lng: -122.4194155, timestamp: 1, sensor: false } }
36
- it "should get timezone by lat lng" do
37
- Eztz::Client.should_receive(:get).with("/maps/api/timezone/json", query )
38
- Eztz.timezone(params)
39
- end
40
- end
41
- end
42
- end
@@ -1,36 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://maps.googleapis.com/maps/api/timezone/json?location=0,0&sensor=false&timestamp=1362096689
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers: {}
10
- response:
11
- status:
12
- code: 200
13
- message: OK
14
- headers:
15
- Content-Type:
16
- - application/json; charset=UTF-8
17
- Access-Control-Allow-Origin:
18
- - ! '*'
19
- Date:
20
- - Fri, 01 Mar 2013 14:55:57 GMT
21
- Server:
22
- - mafe
23
- Cache-Control:
24
- - private
25
- X-Xss-Protection:
26
- - 1; mode=block
27
- X-Frame-Options:
28
- - SAMEORIGIN
29
- Transfer-Encoding:
30
- - chunked
31
- body:
32
- encoding: US-ASCII
33
- string: ! "{\n \"status\" : \"ZERO_RESULTS\"\n}\n"
34
- http_version:
35
- recorded_at: Fri, 01 Mar 2013 14:55:57 GMT
36
- recorded_with: VCR 2.4.0
@@ -1,38 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://maps.googleapis.com/maps/api/timezone/json?location=37.7749295,-122.4194155&sensor=false&timestamp=1362096689
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers: {}
10
- response:
11
- status:
12
- code: 200
13
- message: OK
14
- headers:
15
- Content-Type:
16
- - application/json; charset=UTF-8
17
- Access-Control-Allow-Origin:
18
- - ! '*'
19
- Date:
20
- - Fri, 01 Mar 2013 00:11:30 GMT
21
- Server:
22
- - mafe
23
- Cache-Control:
24
- - private
25
- X-Xss-Protection:
26
- - 1; mode=block
27
- X-Frame-Options:
28
- - SAMEORIGIN
29
- Transfer-Encoding:
30
- - chunked
31
- body:
32
- encoding: US-ASCII
33
- string: ! "{\n \"dstOffset\" : 0.0,\n \"rawOffset\" : -28800.0,\n \"status\"
34
- : \"OK\",\n \"timeZoneId\" : \"America/Los_Angeles\",\n \"timeZoneName\"
35
- : \"Pacific Standard Time\"\n}\n"
36
- http_version:
37
- recorded_at: Fri, 01 Mar 2013 00:11:30 GMT
38
- recorded_with: VCR 2.4.0
@@ -1,13 +0,0 @@
1
- lib = File.expand_path('../../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'rubygems'
4
- require 'rspec'
5
- require 'vcr'
6
- require 'httparty'
7
- require 'eztz'
8
-
9
- VCR.configure do |c|
10
- c.cassette_library_dir = 'spec/fixtures/cassettes'
11
- c.hook_into :webmock
12
- c.allow_http_connections_when_no_cassette = true
13
- end