gmaps_geocoding 1.3.4 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/Rakefile +5 -3
- data/gmaps_geocoding.gemspec +5 -0
- data/lib/gmaps_geocoding/api.rb +9 -7
- data/lib/gmaps_geocoding/config.rb +10 -8
- data/lib/gmaps_geocoding/version.rb +3 -1
- data/lib/gmaps_geocoding.rb +2 -0
- data/test/gmaps_geocoding_api_test.rb +1 -0
- data/test/gmaps_geocoding_config_test.rb +3 -1
- data/test/test_helper.rb +2 -0
- metadata +36 -23
- data/.versions.conf +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 879f5c59fb86a9909999a0f8a9062a7485a139a4c5fc506e6872dddce6e5abdd
|
4
|
+
data.tar.gz: df9fe796aa6bebc8a0f2a34e1d89962e4a37df839efdb5795cc132b2cd2f233c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b28adb7b132fc86f5b07e830cfa486e121ac0beb39f34b43b0dcba27975630cf63506301759659433eec2020b411faf20560fe3845becc2f43b513ceec41eaa0
|
7
|
+
data.tar.gz: cd082faaf5fa289fe01ba16ec4be23f3b1e63bf62bcabeb5fdc68b1d85e8a5fc773edd56a6f1a685e77fdf62a0c92db42d899e1b5f2bc678875bbb497381efb9
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.4.0@gmaps_geocoding
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
3
5
|
require 'rubocop/rake_task'
|
@@ -10,7 +12,7 @@ Rake::TestTask.new do |t|
|
|
10
12
|
t.test_files = FileList['test/**/*_test.rb']
|
11
13
|
t.verbose = true
|
12
14
|
end
|
13
|
-
task default: [
|
15
|
+
task default: %i[test rubocop]
|
14
16
|
|
15
17
|
RuboCop::RakeTask.new do |task|
|
16
18
|
task.formatters = ['simple']
|
@@ -19,6 +21,6 @@ end
|
|
19
21
|
|
20
22
|
desc 'Generate documentation'
|
21
23
|
YARD::Rake::YardocTask.new do |t|
|
22
|
-
t.files = %w
|
23
|
-
t.options = %w
|
24
|
+
t.files = %w[lib/**/*.rb - LICENSE.txt]
|
25
|
+
t.options = %w[--main README.md --no-private]
|
24
26
|
end
|
data/gmaps_geocoding.gemspec
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'English'
|
3
5
|
|
4
6
|
lib = File.expand_path('../lib', __FILE__)
|
5
7
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
8
|
require 'gmaps_geocoding/version'
|
7
9
|
|
10
|
+
# rubocop:disable Metrics/BlockLength
|
8
11
|
Gem::Specification.new do |s|
|
9
12
|
s.name = 'gmaps_geocoding'
|
10
13
|
s.version = GmapsGeocoding::VERSION
|
@@ -36,4 +39,6 @@ Gem::Specification.new do |s|
|
|
36
39
|
s.add_development_dependency 'test-unit', '~> 3.0'
|
37
40
|
s.add_development_dependency 'rubocop', '~> 0.49', '>= 0.49.0'
|
38
41
|
s.add_development_dependency 'coveralls', '~> 0'
|
42
|
+
s.add_development_dependency 'foreman'
|
39
43
|
end
|
44
|
+
# rubocop:enable Metrics/BlockLength
|
data/lib/gmaps_geocoding/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
require 'ox'
|
3
5
|
require 'oj'
|
@@ -18,7 +20,7 @@ module GmapsGeocoding
|
|
18
20
|
@logger = opts.delete(:logger)
|
19
21
|
unless @logger
|
20
22
|
@logger = Logger.new(STDERR) do |l|
|
21
|
-
l.progname = 'gmaps_geocoding'
|
23
|
+
l.progname = 'gmaps_geocoding'
|
22
24
|
l.level = $DEBUG ? Logger::DEBUG : Logger::INFO
|
23
25
|
end
|
24
26
|
end
|
@@ -41,7 +43,7 @@ module GmapsGeocoding
|
|
41
43
|
# result = api.location
|
42
44
|
#
|
43
45
|
def location
|
44
|
-
|
46
|
+
raise 'Invalid configuration parameters check the Google Geocoding API documentation' unless @config.valid?
|
45
47
|
rest_client = retrieve_geocoding_data
|
46
48
|
case @config.json_format?
|
47
49
|
when true
|
@@ -76,9 +78,9 @@ module GmapsGeocoding
|
|
76
78
|
# rubocop:disable Metrics/AbcSize
|
77
79
|
def finest_latlng(data)
|
78
80
|
result = retrieve_finest_location(data)
|
79
|
-
return [result['ROOFTOP'][:lng], result['ROOFTOP'][:lat]] if result.include?('ROOFTOP'
|
80
|
-
return [result['RANGE_INTERPOLATED'][:lng], result['RANGE_INTERPOLATED'][:lat]] if result.include?('RANGE_INTERPOLATED'
|
81
|
-
return [result['GEOMETRIC_CENTER'][:lng], result['GEOMETRIC_CENTER'][:lat]] if result.include?('GEOMETRIC_CENTER'
|
81
|
+
return [result['ROOFTOP'][:lng], result['ROOFTOP'][:lat]] if result.include?('ROOFTOP')
|
82
|
+
return [result['RANGE_INTERPOLATED'][:lng], result['RANGE_INTERPOLATED'][:lat]] if result.include?('RANGE_INTERPOLATED')
|
83
|
+
return [result['GEOMETRIC_CENTER'][:lng], result['GEOMETRIC_CENTER'][:lat]] if result.include?('GEOMETRIC_CENTER')
|
82
84
|
[result['APPROXIMATE'][:lng], result['APPROXIMATE'][:lat]]
|
83
85
|
rescue
|
84
86
|
[0.0, 0.0].freeze
|
@@ -119,10 +121,10 @@ module GmapsGeocoding
|
|
119
121
|
def xml_to_hash(xml_str)
|
120
122
|
xml = Ox.parse(xml_str)
|
121
123
|
r = xml_node_to_ruby(xml)
|
122
|
-
if r.include?('GeocodeResponse'
|
124
|
+
if r.include?('GeocodeResponse')
|
123
125
|
r['GeocodeResponse']
|
124
126
|
else
|
125
|
-
{ status: 'UNKNOWN_ERROR'
|
127
|
+
{ status: 'UNKNOWN_ERROR' }
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Gmaps geocoding module
|
2
4
|
module GmapsGeocoding
|
3
5
|
# Configuration valid keys
|
4
|
-
VALID_KEYS = [
|
6
|
+
VALID_KEYS = %i[url output key address latlng components sensor bounds language region place_id result_type location_type].freeze
|
5
7
|
|
6
8
|
# Valid query parameters
|
7
|
-
VALID_QUERY_PARAMS = VALID_KEYS - [
|
9
|
+
VALID_QUERY_PARAMS = VALID_KEYS - %i[url output].freeze
|
8
10
|
|
9
11
|
# Configuration class for GmapsGeocoding API.
|
10
12
|
class Config
|
@@ -13,9 +15,9 @@ module GmapsGeocoding
|
|
13
15
|
|
14
16
|
# Default configuration values
|
15
17
|
DEFAULT_CONFIG = {
|
16
|
-
url: 'https://maps.googleapis.com/maps/api/geocode'
|
17
|
-
output: 'json'
|
18
|
-
sensor: 'false'
|
18
|
+
url: 'https://maps.googleapis.com/maps/api/geocode',
|
19
|
+
output: 'json',
|
20
|
+
sensor: 'false'
|
19
21
|
}.freeze
|
20
22
|
|
21
23
|
def initialize(opts = {})
|
@@ -38,14 +40,14 @@ module GmapsGeocoding
|
|
38
40
|
#
|
39
41
|
# @return [true, false] Return _true_ or _false_
|
40
42
|
def json_format?
|
41
|
-
'json'.
|
43
|
+
'json'.eql?(output)
|
42
44
|
end
|
43
45
|
|
44
46
|
# Check if the output format of the query is set to _xml_
|
45
47
|
#
|
46
48
|
# @return [true, false] Return _true_ or _false_
|
47
49
|
def xml_format?
|
48
|
-
'xml'.
|
50
|
+
'xml'.eql?(output)
|
49
51
|
end
|
50
52
|
|
51
53
|
private
|
@@ -63,7 +65,7 @@ module GmapsGeocoding
|
|
63
65
|
#
|
64
66
|
# According to the specifications: {https://developers.google.com/maps/documentation/geocoding/#GeocodingResponses}
|
65
67
|
def output_param_valid?
|
66
|
-
%w
|
68
|
+
%w[json xml].include?(output)
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
data/lib/gmaps_geocoding.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../lib/gmaps_geocoding'
|
2
4
|
require_relative 'test_helper'
|
3
5
|
|
@@ -16,7 +18,7 @@ class GmapsGeocodingConfigTest < Test::Unit::TestCase
|
|
16
18
|
config = GmapsGeocoding::Config.new
|
17
19
|
assert_not_nil config
|
18
20
|
|
19
|
-
assert_equal true, config.url.size
|
21
|
+
assert_equal true, config.url.size.positive?
|
20
22
|
assert_equal 'json', config.output
|
21
23
|
assert_nil config.address
|
22
24
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps_geocoding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Kakesa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.0'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 2.0.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '2.0'
|
30
27
|
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: 2.0.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: oj
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "<"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '4'
|
40
37
|
- - ">="
|
41
38
|
- !ruby/object:Gem::Version
|
42
39
|
version: 2.18.0
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '4'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "<"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '4'
|
50
47
|
- - ">="
|
51
48
|
- !ruby/object:Gem::Version
|
52
49
|
version: 2.18.0
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '4'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: oj_mimic_json
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -210,22 +210,22 @@ dependencies:
|
|
210
210
|
name: rubocop
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
|
-
- - "~>"
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
version: '0.49'
|
216
213
|
- - ">="
|
217
214
|
- !ruby/object:Gem::Version
|
218
215
|
version: 0.49.0
|
216
|
+
- - "~>"
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: '0.49'
|
219
219
|
type: :development
|
220
220
|
prerelease: false
|
221
221
|
version_requirements: !ruby/object:Gem::Requirement
|
222
222
|
requirements:
|
223
|
-
- - "~>"
|
224
|
-
- !ruby/object:Gem::Version
|
225
|
-
version: '0.49'
|
226
223
|
- - ">="
|
227
224
|
- !ruby/object:Gem::Version
|
228
225
|
version: 0.49.0
|
226
|
+
- - "~>"
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0.49'
|
229
229
|
- !ruby/object:Gem::Dependency
|
230
230
|
name: coveralls
|
231
231
|
requirement: !ruby/object:Gem::Requirement
|
@@ -240,6 +240,20 @@ dependencies:
|
|
240
240
|
- - "~>"
|
241
241
|
- !ruby/object:Gem::Version
|
242
242
|
version: '0'
|
243
|
+
- !ruby/object:Gem::Dependency
|
244
|
+
name: foreman
|
245
|
+
requirement: !ruby/object:Gem::Requirement
|
246
|
+
requirements:
|
247
|
+
- - ">="
|
248
|
+
- !ruby/object:Gem::Version
|
249
|
+
version: '0'
|
250
|
+
type: :development
|
251
|
+
prerelease: false
|
252
|
+
version_requirements: !ruby/object:Gem::Requirement
|
253
|
+
requirements:
|
254
|
+
- - ">="
|
255
|
+
- !ruby/object:Gem::Version
|
256
|
+
version: '0'
|
243
257
|
description: |2
|
244
258
|
A simple Ruby gem for Google Maps Geocoding API.
|
245
259
|
This gem returns a Ruby Hash object of the result.
|
@@ -251,8 +265,8 @@ extra_rdoc_files: []
|
|
251
265
|
files:
|
252
266
|
- ".gitignore"
|
253
267
|
- ".rubocop.yml"
|
268
|
+
- ".ruby-version"
|
254
269
|
- ".travis.yml"
|
255
|
-
- ".versions.conf"
|
256
270
|
- Gemfile
|
257
271
|
- LICENSE.txt
|
258
272
|
- README.md
|
@@ -284,8 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
298
|
- !ruby/object:Gem::Version
|
285
299
|
version: '0'
|
286
300
|
requirements: []
|
287
|
-
|
288
|
-
rubygems_version: 2.7.7
|
301
|
+
rubygems_version: 3.0.8
|
289
302
|
signing_key:
|
290
303
|
specification_version: 4
|
291
304
|
summary: Use Google Geocoding API from Ruby.
|
data/.versions.conf
DELETED