gmaps_geocoding 1.1.3 → 1.1.4
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/.rubocop.yml +2 -2
- data/README.md +13 -8
- data/lib/gmaps_geocoding/api.rb +11 -12
- data/lib/gmaps_geocoding/config.rb +20 -88
- data/lib/gmaps_geocoding/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b5e8f1bc785e0ddee97bdc381830b4a6b3d728c
|
4
|
+
data.tar.gz: b29c97b2bf0aec977373e9e32edf55603daf49b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34b7bb966efb1ee1d27d35a50a00bb027844a183cf8de821c4299de00cae085df59f8ef905b4bbe4dc21593a48bd189e92b78b6d0fdb867a041197a71e43b700
|
7
|
+
data.tar.gz: c23de144517af7aca69d6d2aa787dc7cecb81905dbabd60c62643e888a607a9ed6203208ae955565e8d812af7eabae0effab5abc6368efb19890b3a281ec541c
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -24,14 +24,19 @@ See [Google Maps Geocoding service documentation](https://developers.google.com/
|
|
24
24
|
|
25
25
|
All options could be overriden with corresponding environment variable:
|
26
26
|
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
30
|
-
*
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
34
|
-
*
|
27
|
+
* `GOOGLE_MAPS_GEOCODING_URL`: HTTP endpoint to the Google geocoding service by default is set to [https://maps.googleapis.com/maps/api/geocode](https://maps.googleapis.com/maps/api/geocode).
|
28
|
+
* `GOOGLE_MAPS_GEOCODING_OUTPUT`: By default is set to `json`
|
29
|
+
* `GOOGLE_MAPS_GEOCODING_KEY`
|
30
|
+
* `GOOGLE_MAPS_GEOCODING_ADDRESS`
|
31
|
+
* `GOOGLE_MAPS_GEOCODING_LATLNG`
|
32
|
+
* `GOOGLE_MAPS_GEOCODING_COMPONENTS`
|
33
|
+
* `GOOGLE_MAPS_GEOCODING_SENSOR`: By default is set to `false`
|
34
|
+
* `GOOGLE_MAPS_GEOCODING_BOUNDS`
|
35
|
+
* `GOOGLE_MAPS_GEOCODING_LANGUAGE`
|
36
|
+
* `GOOGLE_MAPS_GEOCODING_REGION`
|
37
|
+
* `GOOGLE_MAPS_GEOCODING_PLACE_ID`
|
38
|
+
* `GOOGLE_MAPS_GEOCODING_RESULT_TYPE`
|
39
|
+
* `GOOGLE_MAPS_GEOCODING_LOCATION_TYPE`
|
35
40
|
|
36
41
|
### Easy way to use for both JSON and XML format
|
37
42
|
|
data/lib/gmaps_geocoding/api.rb
CHANGED
@@ -48,10 +48,10 @@ module GmapsGeocoding
|
|
48
48
|
Yajl::Parser.parse(rest_client)
|
49
49
|
else
|
50
50
|
r = Nori.new.parse(rest_client)
|
51
|
-
if r.include?('GeocodeResponse')
|
51
|
+
if r.include?('GeocodeResponse'.freeze)
|
52
52
|
r['GeocodeResponse']
|
53
53
|
else
|
54
|
-
{ status: 'UNKNOWN_ERROR' }
|
54
|
+
{ status: 'UNKNOWN_ERROR'.freeze }
|
55
55
|
end
|
56
56
|
end
|
57
57
|
return result
|
@@ -84,12 +84,12 @@ module GmapsGeocoding
|
|
84
84
|
# rubocop:disable Metrics/AbcSize
|
85
85
|
def finest_latlng(data)
|
86
86
|
result = retrieve_finest_location(data)
|
87
|
-
return [result['ROOFTOP'][:lng], result['ROOFTOP'][:lat]] if result.include?('ROOFTOP')
|
88
|
-
return [result['RANGE_INTERPOLATED'][:lng], result['RANGE_INTERPOLATED'][:lat]] if result.include?('RANGE_INTERPOLATED')
|
89
|
-
return [result['GEOMETRIC_CENTER'][:lng], result['GEOMETRIC_CENTER'][:lat]] if result.include?('GEOMETRIC_CENTER')
|
87
|
+
return [result['ROOFTOP'][:lng], result['ROOFTOP'][:lat]] if result.include?('ROOFTOP'.freeze)
|
88
|
+
return [result['RANGE_INTERPOLATED'][:lng], result['RANGE_INTERPOLATED'][:lat]] if result.include?('RANGE_INTERPOLATED'.freeze)
|
89
|
+
return [result['GEOMETRIC_CENTER'][:lng], result['GEOMETRIC_CENTER'][:lat]] if result.include?('GEOMETRIC_CENTER'.freeze)
|
90
90
|
[result['APPROXIMATE'][:lng], result['APPROXIMATE'][:lat]]
|
91
91
|
rescue
|
92
|
-
[0.0, 0.0]
|
92
|
+
[0.0, 0.0].freeze
|
93
93
|
end
|
94
94
|
# rubocop:enable Metrics/AbcSize
|
95
95
|
|
@@ -107,18 +107,17 @@ module GmapsGeocoding
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def build_url_query
|
110
|
-
|
111
|
-
|
110
|
+
query_params = {}
|
111
|
+
VALID_QUERY_PARAMS.each do |k|
|
112
112
|
val = @config.send(k)
|
113
|
-
|
113
|
+
query_params[k] = val if val
|
114
114
|
end
|
115
|
-
url
|
116
|
-
{ url: url, query: query }.freeze
|
115
|
+
{ url: "#{@config.url}/#{@config.output}", params: query_params }.freeze
|
117
116
|
end
|
118
117
|
|
119
118
|
def retrieve_geocoding_data
|
120
119
|
data = build_url_query
|
121
|
-
RestClient.get data[:url], params: data[:
|
120
|
+
RestClient.get data[:url], params: data[:params]
|
122
121
|
end
|
123
122
|
end
|
124
123
|
end
|
@@ -1,100 +1,32 @@
|
|
1
1
|
# Gmaps geocoding module
|
2
2
|
module GmapsGeocoding
|
3
|
+
# Configuration valid keys
|
4
|
+
VALID_KEYS = [:url, :output, :key, :address, :latlng, :components, :sensor, :bounds, :language, :region, :place_id, :result_type, :location_type].freeze
|
5
|
+
|
6
|
+
# Valid query parameters
|
7
|
+
VALID_QUERY_PARAMS = VALID_KEYS - [:url, :output].freeze
|
8
|
+
|
3
9
|
# Configuration class for GmapsGeocoding API.
|
4
10
|
class Config
|
5
|
-
#
|
6
|
-
VALID_KEYS
|
11
|
+
# All valid keys is stored in instance attribute
|
12
|
+
attr_accessor(*VALID_KEYS)
|
7
13
|
|
8
14
|
# Default configuration values
|
9
15
|
DEFAULT_CONFIG = {
|
10
|
-
url: 'https://maps.googleapis.com/maps/api/geocode',
|
11
|
-
output: 'json',
|
12
|
-
sensor: 'false'
|
16
|
+
url: 'https://maps.googleapis.com/maps/api/geocode'.freeze,
|
17
|
+
output: 'json'.freeze,
|
18
|
+
sensor: 'false'.freeze
|
13
19
|
}.freeze
|
14
20
|
|
15
21
|
def initialize(opts = {})
|
16
|
-
|
17
|
-
|
18
|
-
opts.each do |k, _|
|
22
|
+
opts = DEFAULT_CONFIG.merge(opts)
|
23
|
+
VALID_KEYS.each do |k, _|
|
19
24
|
next unless VALID_KEYS.include?(k)
|
20
|
-
val =
|
21
|
-
|
22
|
-
else
|
23
|
-
ENV["GOOGLE_MAPS_GEOCODING_#{k.to_s.upcase}"] || opts.delete(k)
|
24
|
-
end
|
25
|
-
@options[k] = val if val
|
25
|
+
val = ENV["GOOGLE_MAPS_GEOCODING_#{k.to_s.upcase}"] || opts.delete(k)
|
26
|
+
send("#{k}=", val) if val
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
# URL of the Google Maps Geocoding Service
|
30
|
-
#
|
31
|
-
# @return [String] URL of the Google Maps Geocoding Service
|
32
|
-
def url
|
33
|
-
@options[:url]
|
34
|
-
end
|
35
|
-
|
36
|
-
# Output format of the Google Maps Geocoding Service
|
37
|
-
#
|
38
|
-
# @return [String] Output format of the Google Maps Geocoding Service. Only _xml_ or _json_ formats are available
|
39
|
-
def output
|
40
|
-
@options[:output]
|
41
|
-
end
|
42
|
-
|
43
|
-
# The address that you want to geocode
|
44
|
-
#
|
45
|
-
# @return [String] The address that you want to geocode.
|
46
|
-
def address
|
47
|
-
@options[:address]
|
48
|
-
end
|
49
|
-
|
50
|
-
# The textual latitude/longitude value for which you wish to obtain the closest, human-readable address
|
51
|
-
#
|
52
|
-
# @example
|
53
|
-
# "40.714224,-73.961452"
|
54
|
-
#
|
55
|
-
# @return [String] The textual latitude/longitude value for which you wish to obtain the closest, human-readable address
|
56
|
-
def latlng
|
57
|
-
@options[:latlng]
|
58
|
-
end
|
59
|
-
|
60
|
-
# A component filter for which you wish to obtain a geocode
|
61
|
-
#
|
62
|
-
# {https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering}
|
63
|
-
# @return [String] A component filter for which you wish to obtain a geocode
|
64
|
-
def components
|
65
|
-
@options[:components]
|
66
|
-
end
|
67
|
-
|
68
|
-
# Indicates whether or not the geocoding request comes from a device with a location sensor.
|
69
|
-
#
|
70
|
-
# @return [String] Indicates whether or not the geocoding request comes from a device with a location sensor. Must be either "true" or "false".
|
71
|
-
def sensor
|
72
|
-
@options[:sensor]
|
73
|
-
end
|
74
|
-
|
75
|
-
# The bounding box of the viewport within which to bias geocode results more prominently
|
76
|
-
#
|
77
|
-
# {https://developers.google.com/maps/documentation/geocoding/#Viewports}
|
78
|
-
# @return [String] The bounding box of the viewport within which to bias geocode results more prominently
|
79
|
-
def bounds
|
80
|
-
@options[:bounds]
|
81
|
-
end
|
82
|
-
|
83
|
-
# The language in which to return results
|
84
|
-
#
|
85
|
-
# @return [String] The language in which to return results. {https://developers.google.com/maps/faq#languagesupport Supported languages}.
|
86
|
-
def language
|
87
|
-
@options[:language]
|
88
|
-
end
|
89
|
-
|
90
|
-
# The region code, specified as a ccTLD ("top-level domain") two-character value
|
91
|
-
#
|
92
|
-
# {https://developers.google.com/maps/documentation/geocoding/#RegionCodes}
|
93
|
-
# @return [String] The region code, specified as a ccTLD ("top-level domain") two-character value
|
94
|
-
def region
|
95
|
-
@options[:region]
|
96
|
-
end
|
97
|
-
|
98
30
|
# Check if the configuration object is valid
|
99
31
|
#
|
100
32
|
# @return [true, false] Return _true_ or _false_
|
@@ -106,14 +38,14 @@ module GmapsGeocoding
|
|
106
38
|
#
|
107
39
|
# @return [true, false] Return _true_ or _false_
|
108
40
|
def json_format?
|
109
|
-
'json'.eql?(output)
|
41
|
+
'json'.freeze.eql?(output)
|
110
42
|
end
|
111
43
|
|
112
44
|
# Check if the output format of the query is set to _xml_
|
113
45
|
#
|
114
46
|
# @return [true, false] Return _true_ or _false_
|
115
47
|
def xml_format?
|
116
|
-
'xml'.eql?(output)
|
48
|
+
'xml'.freeze.eql?(output)
|
117
49
|
end
|
118
50
|
|
119
51
|
private
|
@@ -122,9 +54,9 @@ module GmapsGeocoding
|
|
122
54
|
#
|
123
55
|
# According to the specifications: {https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests}
|
124
56
|
def query_valid?
|
125
|
-
(
|
126
|
-
(
|
127
|
-
|
57
|
+
(address && latlng.nil?) ||
|
58
|
+
(latlng && address.nil?) ||
|
59
|
+
!components.nil?
|
128
60
|
end
|
129
61
|
|
130
62
|
# Check if the output format is valid
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps_geocoding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Kakesa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|