locotimezone 1.0.1 → 1.0.2
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/.gitignore +1 -0
- data/.rspec +2 -0
- data/README.md +4 -4
- data/Rakefile +5 -9
- data/lib/locotimezone.rb +8 -14
- data/lib/locotimezone/geolocate.rb +5 -6
- data/lib/locotimezone/{loco_time.rb → locotime.rb} +5 -5
- data/lib/locotimezone/timezone.rb +1 -1
- data/lib/locotimezone/version.rb +1 -1
- data/locotimezone.gemspec +16 -14
- metadata +71 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 337171fec57c496eedd9e382daeba4613d28d119
|
4
|
+
data.tar.gz: 5e2f61e63b6e3cc818a781fe5f29fce5b7542043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37ac2f7f62e90c0b9d27426e0f6cbbfcec54904e33f4f3005aaef66105ed17ca9bf003e4987eca89643e783c34b55932107a05d14aba8945c45278a6b8249517
|
7
|
+
data.tar.gz: 5e07f8f7c83cc98d304a74ae92fe50d62e45444c68f0108b02af12db93f6305609a906dd57c5a9111a7e42016c95b35a093de8b630122470037254f2ff14020e
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
[](https://www.codetriage.com/apmiller108/locotimezone)
|
2
|
-
|
3
1
|
[](https://travis-ci.org/apmiller108/locotimezone)
|
4
2
|
|
5
3
|
# Locotimezone
|
6
4
|
Transform a street address into geoloction and timezone data. Essentially, this
|
7
5
|
is an adapter for the [Google Maps Time Zone API](https://developers.google.com/maps/documentation/timezone/intro) and the [The Google Maps Geolocation API](https://developers.google.com/maps/documentation/geolocation/intro).
|
8
6
|
|
9
|
-
All requests to the Google APIs are done over
|
7
|
+
All requests to the Google APIs are done over HTTPS.
|
10
8
|
|
11
9
|
## Installation
|
12
10
|
Add this line to your application's Gemfile:
|
@@ -146,7 +144,9 @@ Locotimezone.locotime location: { lat: 0, lng: 0 }
|
|
146
144
|
|
147
145
|
`Locotimezone.configuration` takes a block where the following can be setup:
|
148
146
|
* `google_api_key`. Create an API key and enable APIs in your [Google
|
149
|
-
Developer Console](https://console.developers.google.com).
|
147
|
+
Developer Console](https://console.developers.google.com). You will also need to enable
|
148
|
+
Google Maps Geocoding API and Google Maps Time Zone API. While using an API key is optional,
|
149
|
+
it's recommended since you will get larger request quota.
|
150
150
|
* `attributes`. For overriding the default attribute names used for Rails models.
|
151
151
|
The defaults are `:latitude`, `:longitude`, and `:timezone_id`. See example
|
152
152
|
above under [Rails usage](#rails-usage)
|
data/Rakefile
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
t.test_files = FileList['test/**/*_test.rb']
|
8
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task default: :spec
|
9
7
|
|
10
8
|
task :run do
|
11
9
|
exec 'pry -r locotimezone -I ./lib -e '\
|
12
10
|
'"Locotimezone.configure { |c| c.google_api_key = ENV[\'GOOGLE_API_KEY\'] }"'
|
13
11
|
end
|
14
|
-
|
15
|
-
task :default => :test
|
data/lib/locotimezone.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'locotimezone/version'
|
2
|
-
require 'locotimezone/
|
2
|
+
require 'locotimezone/locotime'
|
3
3
|
require 'locotimezone/geolocate'
|
4
4
|
require 'locotimezone/timezone'
|
5
5
|
require 'locotimezone/configuration'
|
@@ -7,35 +7,29 @@ require 'locotimezone/active_record_helper'
|
|
7
7
|
require 'locotimezone/railtie' if defined?(Rails)
|
8
8
|
|
9
9
|
module Locotimezone
|
10
|
-
|
11
10
|
class << self
|
12
11
|
attr_accessor :configuration
|
13
12
|
end
|
14
13
|
|
15
14
|
def self.locotime(options = {})
|
16
|
-
set_default_configuration
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
skip: options.fetch(:skip, nil)
|
21
|
-
).transform
|
15
|
+
set_default_configuration if configuration.nil?
|
16
|
+
Locotime.new(location: options.fetch(:location, nil),
|
17
|
+
address: options.fetch(:address, nil),
|
18
|
+
skip: options.fetch(:skip, nil)).call
|
22
19
|
end
|
23
20
|
|
24
21
|
def self.configure
|
25
|
-
self.configuration ||= Configuration.new
|
22
|
+
self.configuration ||= Configuration.new
|
26
23
|
yield configuration if block_given?
|
27
24
|
self
|
28
25
|
end
|
29
26
|
|
30
27
|
def self.reset_configuration
|
31
28
|
self.configuration = Configuration.new
|
29
|
+
set_default_configuration
|
32
30
|
end
|
33
31
|
|
34
32
|
def self.set_default_configuration
|
35
|
-
|
36
|
-
Locotimezone.configure do |config|
|
37
|
-
config.google_api_key = ''
|
38
|
-
end
|
39
|
-
end
|
33
|
+
Locotimezone.configure { |config| config.google_api_key = '' }
|
40
34
|
end
|
41
35
|
end
|
@@ -6,7 +6,7 @@ module Locotimezone
|
|
6
6
|
@address = address
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def call
|
10
10
|
response = open(geolocation_query_url) { |f| JSON.parse f.read }
|
11
11
|
rescue OpenURI::HTTPError
|
12
12
|
{}
|
@@ -14,11 +14,11 @@ module Locotimezone
|
|
14
14
|
format_results response
|
15
15
|
end
|
16
16
|
|
17
|
-
private
|
17
|
+
private
|
18
18
|
|
19
19
|
def geolocation_query_url
|
20
|
-
|
21
|
-
|
20
|
+
"https://maps.googleapis.com/maps/api/geocode/json?address="\
|
21
|
+
"#{address}&key=#{Locotimezone.configuration.google_api_key}"
|
22
22
|
end
|
23
23
|
|
24
24
|
def format_results(response)
|
@@ -30,8 +30,7 @@ module Locotimezone
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def symbolize_keys(response)
|
33
|
-
response.map { |k,v| [k.to_sym, v] }.to_h
|
33
|
+
response.map { |k, v| [k.to_sym, v] }.to_h
|
34
34
|
end
|
35
|
-
|
36
35
|
end
|
37
36
|
end
|
@@ -2,7 +2,7 @@ require 'open-uri'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
module Locotimezone
|
5
|
-
class
|
5
|
+
class Locotime
|
6
6
|
attr_reader :skip, :address
|
7
7
|
attr_accessor :location
|
8
8
|
|
@@ -12,7 +12,7 @@ module Locotimezone
|
|
12
12
|
@skip = location ? :location : skip
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def call
|
16
16
|
validate_options
|
17
17
|
location_data = get_location unless skip == :location
|
18
18
|
timezone_data = get_timezone unless skip == :timezone
|
@@ -25,16 +25,16 @@ module Locotimezone
|
|
25
25
|
if address.nil? && (skip == :timezone || skip.nil?)
|
26
26
|
raise ArgumentError, 'locotimezone is missing address or location.'
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
29
29
|
|
30
30
|
def get_location
|
31
|
-
results = Geolocate.new(address).
|
31
|
+
results = Geolocate.new(address).call
|
32
32
|
self.location = results[:location] || {}
|
33
33
|
results
|
34
34
|
end
|
35
35
|
|
36
36
|
def get_timezone
|
37
|
-
Timezone.new(location).
|
37
|
+
Timezone.new(location).call
|
38
38
|
end
|
39
39
|
|
40
40
|
def build_hash(location_data, timezone_data)
|
data/lib/locotimezone/version.rb
CHANGED
data/locotimezone.gemspec
CHANGED
@@ -1,35 +1,37 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'locotimezone/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'locotimezone'
|
8
7
|
spec.version = Locotimezone::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['Alex Miller']
|
9
|
+
spec.email = ['apmiller108@yahoo.com']
|
11
10
|
|
12
11
|
spec.summary = %q{Get timezone and gelocation data for a street address.}
|
13
12
|
spec.description = %q{Transform a street address into geoloction and timezone data.}
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/apmiller108/locotimezone'
|
14
|
+
spec.license = 'MIT'
|
16
15
|
spec.required_ruby_version = '>= 2.2.1'
|
17
16
|
|
18
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
19
18
|
# delete this section to allow pushing this gem to any host.
|
20
19
|
if spec.respond_to?(:metadata)
|
21
|
-
spec.metadata['allowed_push_host'] =
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
21
|
else
|
23
|
-
raise
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
24
23
|
end
|
25
24
|
|
26
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
-
spec.bindir =
|
26
|
+
spec.bindir = 'bin'
|
28
27
|
spec.executables = ['locotimezone']
|
29
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ['lib']
|
30
29
|
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
30
|
+
spec.add_development_dependency 'activerecord', '~> 5.1', '>= 5.1.3'
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
32
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
35
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.11'
|
36
|
+
spec.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
|
35
37
|
end
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locotimezone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.1.3
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.1.3
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: bundler
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +44,20 @@ dependencies:
|
|
24
44
|
- - "~>"
|
25
45
|
- !ruby/object:Gem::Version
|
26
46
|
version: '1.11'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.10.4
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.10.4
|
27
61
|
- !ruby/object:Gem::Dependency
|
28
62
|
name: rake
|
29
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,33 +73,59 @@ dependencies:
|
|
39
73
|
- !ruby/object:Gem::Version
|
40
74
|
version: '10.0'
|
41
75
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
76
|
+
name: rspec
|
43
77
|
requirement: !ruby/object:Gem::Requirement
|
44
78
|
requirements:
|
45
79
|
- - "~>"
|
46
80
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
81
|
+
version: '3.6'
|
48
82
|
type: :development
|
49
83
|
prerelease: false
|
50
84
|
version_requirements: !ruby/object:Gem::Requirement
|
51
85
|
requirements:
|
52
86
|
- - "~>"
|
53
87
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
88
|
+
version: '3.6'
|
55
89
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
90
|
+
name: sqlite3
|
57
91
|
requirement: !ruby/object:Gem::Requirement
|
58
92
|
requirements:
|
59
93
|
- - "~>"
|
60
94
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
95
|
+
version: '1.3'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.3.11
|
62
99
|
type: :development
|
63
100
|
prerelease: false
|
64
101
|
version_requirements: !ruby/object:Gem::Requirement
|
65
102
|
requirements:
|
66
103
|
- - "~>"
|
67
104
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
105
|
+
version: '1.3'
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.3.11
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: webmock
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '3.0'
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 3.0.1
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.0'
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 3.0.1
|
69
129
|
description: Transform a street address into geoloction and timezone data.
|
70
130
|
email:
|
71
131
|
- apmiller108@yahoo.com
|
@@ -75,6 +135,7 @@ extensions: []
|
|
75
135
|
extra_rdoc_files: []
|
76
136
|
files:
|
77
137
|
- ".gitignore"
|
138
|
+
- ".rspec"
|
78
139
|
- ".travis.yml"
|
79
140
|
- Gemfile
|
80
141
|
- LICENSE.txt
|
@@ -87,7 +148,7 @@ files:
|
|
87
148
|
- lib/locotimezone/active_record_helper.rb
|
88
149
|
- lib/locotimezone/configuration.rb
|
89
150
|
- lib/locotimezone/geolocate.rb
|
90
|
-
- lib/locotimezone/
|
151
|
+
- lib/locotimezone/locotime.rb
|
91
152
|
- lib/locotimezone/railtie.rb
|
92
153
|
- lib/locotimezone/timezone.rb
|
93
154
|
- lib/locotimezone/version.rb
|
@@ -113,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
174
|
version: '0'
|
114
175
|
requirements: []
|
115
176
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
177
|
+
rubygems_version: 2.5.1
|
117
178
|
signing_key:
|
118
179
|
specification_version: 4
|
119
180
|
summary: Get timezone and gelocation data for a street address.
|