gmaps_geocoding 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/gmaps_geocoding.gemspec +11 -11
- data/lib/gmaps_geocoding/api.rb +14 -9
- data/lib/gmaps_geocoding/config.rb +9 -8
- data/lib/gmaps_geocoding/version.rb +1 -1
- data/test/gmaps_geocoding_test.rb +3 -3
- 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: 57722991dd7d3928d47cac69f2551e04a7a563d6
|
4
|
+
data.tar.gz: ac94b52d5d0f2e33816b64ac7e25c916e00eb502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9c6d51376ae4bb6969c7a4f85e69f624194b3b6a497f7267fc68a7a908c3e122370f068a6693ebd5015e8db602b56b37d8f6debc85cbcde31c8bfffc5b4a429
|
7
|
+
data.tar.gz: 767a0276c82863de68110a33aa05c87302d12f36bb230193873983044d133bfc31fa23aac138676673667d63683af035211fdc0f75d47a09eec27e3d5b76d57a
|
data/Rakefile
CHANGED
data/gmaps_geocoding.gemspec
CHANGED
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'gmaps_geocoding/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
s.authors
|
10
|
-
s.email
|
11
|
-
s.description
|
7
|
+
s.name = 'gmaps_geocoding'
|
8
|
+
s.version = GmapsGeocoding::VERSION
|
9
|
+
s.authors = ['Christian Kakesa']
|
10
|
+
s.email = ['christian.kakesa@gmail.com']
|
11
|
+
s.description = %q{
|
12
12
|
A simple Ruby gem for Google Maps Geocoding API.
|
13
13
|
This gem return a Ruby Hash object of the result.
|
14
14
|
}
|
15
|
-
s.summary
|
16
|
-
s.homepage
|
17
|
-
s.license
|
15
|
+
s.summary = %q{Use Google Geocoding API from Ruby.}
|
16
|
+
s.homepage = 'https://github.com/fenicks/gmaps_geocoding'
|
17
|
+
s.license = 'MIT'
|
18
18
|
|
19
|
-
s.files
|
20
|
-
s.executables
|
21
|
-
s.test_files
|
19
|
+
s.files = `git ls-files`.split($/)
|
20
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
22
22
|
s.require_paths = ['lib']
|
23
23
|
|
24
24
|
s.add_runtime_dependency 'rest-client', '~> 1.6.7'
|
data/lib/gmaps_geocoding/api.rb
CHANGED
@@ -68,9 +68,14 @@ module GmapsGeocoding
|
|
68
68
|
def get_finest_latlng(data_result)
|
69
69
|
tmp_result = {}
|
70
70
|
data = data_result
|
71
|
-
data.
|
72
|
-
|
73
|
-
|
71
|
+
if data.kind_of?(Array)
|
72
|
+
data.each do |d|
|
73
|
+
tmp_result["#{d['geometry']['location_type']}"] = {lng: d['geometry']['location']['lng'].to_f,
|
74
|
+
lat: d['geometry']['location']['lat'].to_f}
|
75
|
+
end
|
76
|
+
else
|
77
|
+
tmp_result["#{data['geometry']['location_type']}"] = {lng: data['geometry']['location']['lng'].to_f,
|
78
|
+
lat: data['geometry']['location']['lat'].to_f}
|
74
79
|
end
|
75
80
|
if tmp_result.include?('ROOFTOP')
|
76
81
|
[tmp_result['ROOFTOP'][:lng], tmp_result['ROOFTOP'][:lat]]
|
@@ -86,13 +91,13 @@ module GmapsGeocoding
|
|
86
91
|
private
|
87
92
|
def build_url_query
|
88
93
|
query = {}
|
89
|
-
query[:address]
|
90
|
-
query[:latlng]
|
94
|
+
query[:address] = @config.address if @config.address
|
95
|
+
query[:latlng] = @config.latlng if @config.latlng
|
91
96
|
query[:components] = @config.components if @config.components
|
92
|
-
query[:sensor]
|
93
|
-
query[:bounds]
|
94
|
-
query[:language]
|
95
|
-
query[:region]
|
97
|
+
query[:sensor] = @config.sensor if @config.sensor
|
98
|
+
query[:bounds] = @config.bounds if @config.bounds
|
99
|
+
query[:language] = @config.language if @config.language
|
100
|
+
query[:region] = @config.region if @config.region
|
96
101
|
url = "#{@config.url}/#{@config.output}"
|
97
102
|
{url: url, query: query}
|
98
103
|
end
|
@@ -5,15 +5,15 @@ module GmapsGeocoding
|
|
5
5
|
class Config
|
6
6
|
def initialize(opts = {})
|
7
7
|
@options = {url: 'https://maps.googleapis.com/maps/api/geocode'}
|
8
|
-
@options[:output]
|
9
|
-
@options[:address]
|
10
|
-
@options[:latlng]
|
8
|
+
@options[:output] = ENV['GOOGLE_MAPS_GEOCODING_OUTPUT'] || opts[:output] || 'json'
|
9
|
+
@options[:address] = ENV['GOOGLE_MAPS_GEOCODING_ADDRESS'] || opts[:address] || ''
|
10
|
+
@options[:latlng] = ENV['GOOGLE_MAPS_GEOCODING_LATLNG'] || opts[:latlng] || ''
|
11
11
|
@options[:components] = ENV['GOOGLE_MAPS_GEOCODING_COMPONENTS'] || opts[:components] || ''
|
12
|
-
@options[:sensor]
|
13
|
-
@options[:bounds]
|
14
|
-
@options[:language]
|
15
|
-
@options[:region]
|
16
|
-
@options.merge!(opts).reject!{|_, v| v.to_s.length == 0 }
|
12
|
+
@options[:sensor] = ENV['GOOGLE_MAPS_GEOCODING_SENSOR'] || opts[:sensor] || 'false'
|
13
|
+
@options[:bounds] = ENV['GOOGLE_MAPS_GEOCODING_BOUNDS'] || opts[:bounds] || ''
|
14
|
+
@options[:language] = ENV['GOOGLE_MAPS_GEOCODING_LANGUAGE'] || opts[:language] || ''
|
15
|
+
@options[:region] = ENV['GOOGLE_MAPS_GEOCODING_REGION'] || opts[:region] || ''
|
16
|
+
@options.merge!(opts).reject! { |_, v| v.to_s.length == 0 }
|
17
17
|
end
|
18
18
|
|
19
19
|
# URL of the Google Maps Geocoding Service
|
@@ -46,6 +46,7 @@ module GmapsGeocoding
|
|
46
46
|
def latlng
|
47
47
|
@options[:latlng]
|
48
48
|
end
|
49
|
+
|
49
50
|
# A component filter for which you wish to obtain a geocode
|
50
51
|
#
|
51
52
|
# {https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering}
|
@@ -16,7 +16,7 @@ class GmapsGeocodingTest < Test::Unit::TestCase
|
|
16
16
|
assert_equal true, config.valid?
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
def test_config_latlng_set
|
20
20
|
config = GmapsGeocoding::Config.new({latlng: '40.714224,-73.961452'})
|
21
21
|
assert_not_nil config
|
22
22
|
assert_equal true, config.valid?
|
@@ -43,7 +43,7 @@ class GmapsGeocodingTest < Test::Unit::TestCase
|
|
43
43
|
assert_kind_of Hash, result_location
|
44
44
|
assert_include result_location, 'results'
|
45
45
|
|
46
|
-
result_latlng =
|
46
|
+
result_latlng = api.get_finest_latlng(result_location['results'])
|
47
47
|
assert_not_nil result_latlng
|
48
48
|
assert_instance_of Array, result_latlng
|
49
49
|
end
|
@@ -58,7 +58,7 @@ class GmapsGeocodingTest < Test::Unit::TestCase
|
|
58
58
|
assert_kind_of Hash, result_location
|
59
59
|
assert_include result_location, 'result'
|
60
60
|
|
61
|
-
result_latlng =
|
61
|
+
result_latlng = api.get_finest_latlng(result_location['result'])
|
62
62
|
assert_not_nil result_latlng
|
63
63
|
assert_instance_of Array, result_latlng
|
64
64
|
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: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Kakesa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07
|
11
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|