google_maps_geocoder 0.3.0 → 0.3.1
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 +15 -0
- data/.ruby-version +1 -0
- data/.travis.yml +0 -3
- data/LICENSE.txt +1 -1
- data/README.md +28 -4
- data/Rakefile +0 -2
- data/google_maps_geocoder.gemspec +4 -5
- data/lib/google_maps_geocoder.rb +14 -13
- data/lib/version.rb +1 -1
- data/spec/lib/google_maps_geocoder_spec.rb +24 -24
- data/spec/spec_helper.rb +1 -3
- metadata +6 -18
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2IzNjAyZDM5YWVlOWM3YjM0NTQ0Yjk4ZWU3NWNiYjk2NDBiOTliYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDA3NGI5YmFkZmQ3ZmI1NjExOTU4N2UwOTMyZGU5M2Q0N2RhMTJmMw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZGFiNmM3MDg0Y2FmZDMwMjBiOTFkOTA5MmQ5NTU1ZGQ1NWMxMjgxMDJmODVm
|
10
|
+
Y2ExNTIwZGY4M2ZiZDIwYmRhYmZlY2M4NGNmNDY4OWJjYmZkODA2Y2NlY2M5
|
11
|
+
ZDAzZmY2YThmYzhjZTM3MmZmOWEyY2M1ZWJlODQ4MGE0N2YyYjQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDNhMzgyOWQzODE5NDk1NDdlZGQ5MzZlZTRjNTYxNzMyMTIzNDcyMTg3Nzgw
|
14
|
+
NjMyNjI2ZTFhOGY2YmVlYjA2N2Y3Y2NjNDhjMmFhZDhiZTgzOTZhN2RjMzE0
|
15
|
+
NDhlMDdhYmRiNGNhMmE1YjJhMDU0NWU3ZDQyMWUxMWQzMjM2OTA=
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p385
|
data/.travis.yml
CHANGED
data/LICENSE.txt
CHANGED
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,37 +1,61 @@
|
|
1
|
-
# GoogleMapsGeocoder [](http://travis-ci.org/ivanoblomov/google_maps_geocoder)
|
1
|
+
# GoogleMapsGeocoder [](https://codeclimate.com/github/ivanoblomov/google_maps_geocoder) [](http://travis-ci.org/ivanoblomov/google_maps_geocoder) [](https://gemnasium.com/ivanoblomov/google_maps_geocoder)
|
2
2
|
|
3
3
|
A simple PORO wrapper for geocoding with Google Maps.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
In <b>Rails 3</b>, add this to your Gemfile and run "bundle":
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'google_maps_geocoder'
|
11
|
+
```
|
12
|
+
|
13
|
+
In <b>Rails 2</b>, add this to your environment.rb file:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
config.gem 'google_maps_geocoder'
|
17
|
+
```
|
18
|
+
|
19
|
+
Or try it out in <b>irb</b> with:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require './lib/google_maps_geocoder'
|
23
|
+
```
|
24
|
+
|
25
|
+
## Ready to Go in One Step
|
6
26
|
|
7
27
|
```ruby
|
8
28
|
chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania Washington'
|
9
29
|
```
|
10
30
|
|
11
|
-
##
|
31
|
+
## Usage
|
12
32
|
|
13
33
|
Get the complete, formatted address:
|
14
34
|
|
15
35
|
```ruby
|
16
36
|
chez_barack.formatted_address
|
37
|
+
=> "1600 Pennsylvania Avenue Northwest, President's Park, Washington, DC 20500, USA"
|
17
38
|
```
|
18
39
|
|
19
40
|
...standardized name of the city:
|
20
41
|
|
21
42
|
```ruby
|
22
43
|
chez_barack.city
|
44
|
+
=> "Washington"
|
23
45
|
```
|
24
46
|
|
25
47
|
...full name of the state or region:
|
26
48
|
|
27
49
|
```ruby
|
28
50
|
chez_barack.state_long_name
|
51
|
+
=> "District of Columbia"
|
29
52
|
```
|
30
53
|
|
31
54
|
...standard abbreviation for the state/region:
|
32
55
|
|
33
56
|
```ruby
|
34
57
|
chez_barack.state_short_name
|
58
|
+
=> "DC"
|
35
59
|
```
|
36
60
|
|
37
61
|
## API
|
@@ -64,4 +88,4 @@ The complete, hopefully self-explanatory, API is:
|
|
64
88
|
|
65
89
|
## Copyright
|
66
90
|
|
67
|
-
Copyright (c) 2011 Roderick Monje. See LICENSE.txt for further details.
|
91
|
+
Copyright (c) 2011 Roderick Monje. See LICENSE.txt for further details.
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require File.expand_path
|
2
|
-
|
1
|
+
require File.expand_path '../lib/version', __FILE__
|
3
2
|
Gem::Specification.new do |s|
|
4
3
|
s.name = "google_maps_geocoder"
|
5
4
|
s.version = GoogleMapsGeocoder::VERSION.dup
|
@@ -15,8 +14,8 @@ Gem::Specification.new do |s|
|
|
15
14
|
s.add_runtime_dependency 'activesupport', '>= 0'
|
16
15
|
s.add_runtime_dependency 'rack', '>= 0'
|
17
16
|
|
18
|
-
s.files = `git ls-files`.split
|
19
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename
|
17
|
+
s.files = `git ls-files`.split "\n"
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split "\n"
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename f}
|
21
20
|
s.require_paths = ["lib"]
|
22
21
|
end
|
data/lib/google_maps_geocoder.rb
CHANGED
@@ -25,18 +25,10 @@ class GoogleMapsGeocoder
|
|
25
25
|
# white_house.formatted_address
|
26
26
|
# => "1600 Pennsylvania Avenue Northwest, President's Park, Washington, DC 20500, USA"
|
27
27
|
def initialize data
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
@json = data
|
34
|
-
address = data['formatted_address']
|
35
|
-
end
|
36
|
-
|
37
|
-
@city, @country_short_name, @country_long_name, @county, @formatted_address, @formatted_street_address, @lat, @lng, @postal_code, @state_long_name, @state_short_name = parse_city, parse_country_short_name, parse_country_long_name, parse_county, parse_formatted_address, parse_formatted_street_address, parse_lat, parse_lng, parse_postal_code, parse_state_long_name, parse_state_short_name
|
38
|
-
|
39
|
-
logger = Logger.new(STDERR)
|
28
|
+
@json = data.is_a?(String) ? json_from_url(data) : data
|
29
|
+
raise "Geocoding \"#{data}\" exceeded query limit! Google returned...\n#{@json.inspect}" if @json.blank? || @json['status'] != 'OK'
|
30
|
+
set_attributes_from_json
|
31
|
+
logger = Logger.new STDERR
|
40
32
|
logger.info('GoogleMapsGeocoder') { "Geocoded \"#{data}\" => \"#{self.formatted_address}\"" }
|
41
33
|
end
|
42
34
|
|
@@ -66,6 +58,11 @@ class GoogleMapsGeocoder
|
|
66
58
|
|
67
59
|
private
|
68
60
|
|
61
|
+
def json_from_url url
|
62
|
+
response = Net::HTTP.get_response(URI.parse "http://maps.googleapis.com/maps/api/geocode/json?address=#{Rack::Utils.escape(url)}&sensor=false")
|
63
|
+
ActiveSupport::JSON.decode response.body
|
64
|
+
end
|
65
|
+
|
69
66
|
def parse_address_component_type(type, name='long_name')
|
70
67
|
_address_component = @json['results'][0]['address_components'].detect{ |ac| ac['types'] && ac['types'].include?(type) }
|
71
68
|
_address_component && _address_component[name]
|
@@ -114,4 +111,8 @@ class GoogleMapsGeocoder
|
|
114
111
|
def parse_state_short_name
|
115
112
|
parse_address_component_type('administrative_area_level_1', 'short_name')
|
116
113
|
end
|
117
|
-
|
114
|
+
|
115
|
+
def set_attributes_from_json
|
116
|
+
@city, @country_short_name, @country_long_name, @county, @formatted_address, @formatted_street_address, @lat, @lng, @postal_code, @state_long_name, @state_short_name = parse_city, parse_country_short_name, parse_country_long_name, parse_county, parse_formatted_address, parse_formatted_street_address, parse_lat, parse_lng, parse_postal_code, parse_state_long_name, parse_state_short_name
|
117
|
+
end
|
118
|
+
end
|
data/lib/version.rb
CHANGED
@@ -19,44 +19,44 @@ describe GoogleMapsGeocoder do
|
|
19
19
|
|
20
20
|
context 'with "837 Union Street Brooklyn NY"' do
|
21
21
|
subject { @exact_match }
|
22
|
-
|
22
|
+
it { expect(subject).to be_exact_match }
|
23
23
|
|
24
24
|
context 'address' do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
it { expect(subject.formatted_street_address).to eq '837 Union Street' }
|
26
|
+
it { expect(subject.city).to eq 'Brooklyn' }
|
27
|
+
it { expect(subject.county).to match /Kings/ }
|
28
|
+
it { expect(subject.state_long_name).to eq 'New York' }
|
29
|
+
it { expect(subject.state_short_name).to eq 'NY' }
|
30
|
+
it { expect(subject.postal_code).to match /112[0-9]{2}/ }
|
31
|
+
it { expect(subject.country_short_name).to eq 'US' }
|
32
|
+
it { expect(subject.country_long_name).to eq 'United States' }
|
33
|
+
it { expect(subject.formatted_address).to match /837 Union Street, Brooklyn, NY 112[0-9]{2}, USA/ }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'coordinates' do
|
37
|
-
|
38
|
-
|
37
|
+
it { expect(subject.lat).to be_within(0.005).of(40.6748151) }
|
38
|
+
it { expect(subject.lng).to be_within(0.005).of(-73.9760302) }
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context 'with "1600 Pennsylvania Washington"' do
|
43
43
|
subject { @partial_match }
|
44
|
-
|
44
|
+
it { should be_partial_match }
|
45
45
|
|
46
46
|
context 'address' do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
it { expect(subject.formatted_street_address).to eq '1600 Pennsylvania Avenue Northwest' }
|
48
|
+
it { expect(subject.city).to eq 'Washington' }
|
49
|
+
it { expect(subject.state_long_name).to eq 'District of Columbia' }
|
50
|
+
it { expect(subject.state_short_name).to eq 'DC' }
|
51
|
+
it { expect(subject.postal_code).to match /2050[0-9]/ }
|
52
|
+
it { expect(subject.country_short_name).to eq 'US' }
|
53
|
+
it { expect(subject.country_long_name).to eq 'United States' }
|
54
|
+
it { expect(subject.formatted_address).to match(/1600 Pennsylvania Avenue Northwest, President's Park, Washington, DC 2050[0-9], USA/) }
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'coordinates' do
|
58
|
-
|
59
|
-
|
58
|
+
it { expect(subject.lat).to be_within(0.005).of(38.8976964) }
|
59
|
+
it { expect(subject.lng).to be_within(0.005).of(-77.0365191) }
|
60
60
|
end
|
61
61
|
end
|
62
|
-
end
|
62
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
SimpleCov.start
|
3
|
-
|
4
3
|
require 'rubygems'
|
5
4
|
require 'bundler'
|
6
5
|
begin
|
@@ -10,7 +9,6 @@ rescue Bundler::BundlerError => e
|
|
10
9
|
$stderr.puts "Run `bundle install` to install missing gems"
|
11
10
|
exit e.status_code
|
12
11
|
end
|
13
|
-
|
14
12
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
-
require 'google_maps_geocoder'
|
14
|
+
require 'google_maps_geocoder'
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_maps_geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Roderick Monje
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: simplecov
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: activesupport
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -78,7 +69,6 @@ dependencies:
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rack
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ! '>='
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ! '>='
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -100,6 +89,7 @@ extra_rdoc_files: []
|
|
100
89
|
files:
|
101
90
|
- .document
|
102
91
|
- .gitignore
|
92
|
+
- .ruby-version
|
103
93
|
- .travis.yml
|
104
94
|
- Gemfile
|
105
95
|
- LICENSE.txt
|
@@ -112,29 +102,27 @@ files:
|
|
112
102
|
- spec/spec_helper.rb
|
113
103
|
homepage: http://github.com/ivanoblomov/google_maps_geocoder
|
114
104
|
licenses: []
|
105
|
+
metadata: {}
|
115
106
|
post_install_message:
|
116
107
|
rdoc_options: []
|
117
108
|
require_paths:
|
118
109
|
- lib
|
119
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
-
none: false
|
121
111
|
requirements:
|
122
112
|
- - ! '>='
|
123
113
|
- !ruby/object:Gem::Version
|
124
114
|
version: '0'
|
125
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
-
none: false
|
127
116
|
requirements:
|
128
117
|
- - ! '>='
|
129
118
|
- !ruby/object:Gem::Version
|
130
119
|
version: '0'
|
131
120
|
requirements: []
|
132
121
|
rubyforge_project:
|
133
|
-
rubygems_version:
|
122
|
+
rubygems_version: 2.0.6
|
134
123
|
signing_key:
|
135
|
-
specification_version:
|
124
|
+
specification_version: 4
|
136
125
|
summary: A simple PORO wrapper for geocoding with Google Maps.
|
137
126
|
test_files:
|
138
127
|
- spec/lib/google_maps_geocoder_spec.rb
|
139
128
|
- spec/spec_helper.rb
|
140
|
-
has_rdoc:
|