gmaps_geocoding 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce042c8153814605f23987fa685e04e97d645c17
4
- data.tar.gz: cb452da2de881780f2181980bff931b977e2e541
3
+ metadata.gz: 3b5e8f1bc785e0ddee97bdc381830b4a6b3d728c
4
+ data.tar.gz: b29c97b2bf0aec977373e9e32edf55603daf49b6
5
5
  SHA512:
6
- metadata.gz: 0d95573f126ec6cfc5784b0d61f85b26b8c01930230f64b9fbe089c940b5b1f7faecf8aae77ab1ae90707433b3b6a07bcb21d5d323ab04c2a89c89cf4e7bde0a
7
- data.tar.gz: 09e80b0f6b157c3b3a0f2d21a3a1326ce492c82e89a1f8a20c4ceaeb8ab9854547c6d0edd9bbfb4290d59cbd59a50d433545d51866024d32693582e652f3aafc
6
+ metadata.gz: 34b7bb966efb1ee1d27d35a50a00bb027844a183cf8de821c4299de00cae085df59f8ef905b4bbe4dc21593a48bd189e92b78b6d0fdb867a041197a71e43b700
7
+ data.tar.gz: c23de144517af7aca69d6d2aa787dc7cecb81905dbabd60c62643e888a607a9ed6203208ae955565e8d812af7eabae0effab5abc6368efb19890b3a281ec541c
data/.rubocop.yml CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Metrics/LineLength:
4
4
  Description: 'Limit lines to 310 characters.'
5
- Enabled: true
6
- Max: 310
5
+ Enabled: false
6
+ Max: 120
7
7
 
8
8
  Metrics/MethodLength:
9
9
  Description: 'Try to avoid methods longer than 50 lines of code.'
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
- * GOOGLE_MAPS_GEOCODING_OUTPUT
28
- * GOOGLE_MAPS_GEOCODING_ADDRESS
29
- * GOOGLE_MAPS_GEOCODING_LATLNG
30
- * GOOGLE_MAPS_GEOCODING_COMPONENTS
31
- * GOOGLE_MAPS_GEOCODING_SENSOR
32
- * GOOGLE_MAPS_GEOCODING_BOUNDS
33
- * GOOGLE_MAPS_GEOCODING_LANGUAGE
34
- * GOOGLE_MAPS_GEOCODING_REGION
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
 
@@ -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
- query = {}
111
- [:address, :latlng, :components, :sensor, :bounds, :language, :region].each do |k|
110
+ query_params = {}
111
+ VALID_QUERY_PARAMS.each do |k|
112
112
  val = @config.send(k)
113
- query[k] = val if val
113
+ query_params[k] = val if val
114
114
  end
115
- url = "#{@config.url}/#{@config.output}"
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[:query]
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
- # Configuration valid keys
6
- VALID_KEYS = [:url, :output, :address, :latlng, :components, :sensor, :bounds, :language, :region].freeze
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
- @options = {}
17
- @options.merge!(DEFAULT_CONFIG)
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 = if k.eql?(:url)
21
- opts.delete(k)
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
- (@options.include?(:address) && !@options.include?(:latlng)) ||
126
- (!@options.include?(:address) && @options.include?(:latlng)) ||
127
- @options.include?(:components)
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
@@ -1,3 +1,3 @@
1
1
  module GmapsGeocoding
2
- VERSION = '1.1.3'.freeze
2
+ VERSION = '1.1.4'.freeze
3
3
  end
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.3
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-08-11 00:00:00.000000000 Z
11
+ date: 2015-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client