eztz 0.0.1

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDU5NWRkZjA2ZGVmMjdkMWEwMzA4NjBhMTNlZjRlYTYyMTY5ZWI3Nw==
5
+ data.tar.gz: !binary |-
6
+ ODVmODE5NmZlMDJlMDA0NTA4YWQxNzJkZTNmZTlmZmUwNGRiMTQyOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ N2Y2ZjU2YjZhODFiNDRlZjBiNzU3ZTUyZGFlNDM0YTljOWVmMTEyYzMxMTQz
10
+ YzEyZTQxZWE2N2FkNWQ3NTQzYzcyY2U2MDQyMzA5YzFkMTI1ZGYyYjUzZTU5
11
+ MTgxMDljNWM4ZmEwN2JhOGYwYjRiNTU3NjRiOTE0NzAyZjA4ZDQ=
12
+ data.tar.gz: !binary |-
13
+ MGUxZDFkMjcyNTY2MmE1OTZjM2IyNjcxMmE3M2E1MDM3ZWFjOGRlMGE3N2U4
14
+ MjQyMGJlZGY5NDcwN2Y3NTY0ZTVjOTYyYjgwN2MwZTk1YTUzN2UyYWUyM2My
15
+ MmQ2NGZjYTFjYmFkM2QzOTc4ZGVkODg0NDdlOWM0YzBhYzVhOGM=
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eztz.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
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.
@@ -0,0 +1,50 @@
1
+ # Eztz
2
+
3
+ Ruby wrapper for the [Google Time Zone API](https://developers.google.com/maps/documentation/timezone)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'eztz'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install eztz
18
+
19
+ ## Usage
20
+
21
+ $ Eztz.timezone(lat: -33.86, lng: 151.20)
22
+
23
+ => #<Hashie::Mash dstOffset=3600.0 rawOffset=36000.0 status="OK" timeZoneId="Australia/Sydney" timeZoneName="Australian Eastern Daylight Time">
24
+
25
+ or
26
+
27
+ $ Eztz.timezone(location: '-33.86,151.20')
28
+
29
+ => #<Hashie::Mash dstOffset=3600.0 rawOffset=36000.0 status="OK" timeZoneId="Australia/Sydney" timeZoneName="Australian Eastern Daylight Time">
30
+
31
+ Params should take one of the following forms:
32
+
33
+ { location: "-33.86,151.20" }
34
+ { lat: -33.86, lng: 151.20 }
35
+
36
+ ## Calculating the Local Time
37
+
38
+ 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.
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
47
+
48
+ ## License
49
+
50
+ This code is provided under the MIT license. See [LICENSE](LICENSE) for more details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/eztz/version', __FILE__)
3
+
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.summary = gem.description
10
+ gem.homepage = "https://github.com/cmason/eztz"
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Eztz::VERSION
17
+
18
+ gem.add_development_dependency 'rake'
19
+ gem.add_development_dependency 'rspec', '~> 2.12.0'
20
+ gem.add_development_dependency 'vcr', '~> 2.4.0'
21
+ gem.add_development_dependency 'webmock', '~> 1.9.3'
22
+
23
+ gem.add_dependency 'httparty', '~> 0.10.0'
24
+ gem.add_dependency 'hashie', '>= 1.2.0'
25
+ end
@@ -0,0 +1,22 @@
1
+ require "eztz/client"
2
+ require "eztz/version"
3
+
4
+ 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)
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+
4
+ module Eztz
5
+ class Client
6
+ include HTTParty
7
+ base_uri 'https://maps.googleapis.com'
8
+
9
+ # Gets timezone information for a location on earth,
10
+ # as well as that location's time offset from UTC.
11
+ #
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?
44
+ params[:sensor] ||= false
45
+ params[:timestamp] ||= Time.now.to_i
46
+ Hashie::Mash.new self.get('/maps/api/timezone/json', query: params)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Eztz
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,41 @@
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
+ end
23
+ end
24
+
25
+ context "by location" do
26
+ let(:params) { {location: "37.7749295,-122.4194155", timestamp: 1, sensor: false} }
27
+ it "should get timezone by location" do
28
+ Eztz::Client.should_receive(:get).with("/maps/api/timezone/json", query )
29
+ Eztz.timezone(params)
30
+ end
31
+ end
32
+
33
+ context "by :lat :lng" do
34
+ let(:params) { {lat: 37.7749295, lng: -122.4194155, timestamp: 1, sensor: false } }
35
+ it "should get timezone by lat lng" do
36
+ Eztz::Client.should_receive(:get).with("/maps/api/timezone/json", query )
37
+ Eztz.timezone(params)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,36 @@
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
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,13 @@
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
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eztz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Mason
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.12.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.12.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.4.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.9.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.9.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: hashie
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.0
97
+ description: Ruby wrapper for the Google Time Zone API
98
+ email:
99
+ - chris@chaione.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - eztz.gemspec
110
+ - lib/eztz.rb
111
+ - lib/eztz/client.rb
112
+ - lib/eztz/version.rb
113
+ - spec/acceptance/get_timezone_spec.rb
114
+ - spec/eztz_spec.rb
115
+ - spec/fixtures/cassettes/emtpy_results.yml
116
+ - spec/fixtures/cassettes/valid_timezone_lookup.yml
117
+ - spec/spec_helper.rb
118
+ homepage: https://github.com/cmason/eztz
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.0
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Ruby wrapper for the Google Time Zone API
141
+ test_files:
142
+ - spec/acceptance/get_timezone_spec.rb
143
+ - spec/eztz_spec.rb
144
+ - spec/fixtures/cassettes/emtpy_results.yml
145
+ - spec/fixtures/cassettes/valid_timezone_lookup.yml
146
+ - spec/spec_helper.rb
147
+ has_rdoc: