geeo_code 0.0.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.
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/Rakefile +2 -0
- data/geeo_code.gemspec +29 -0
- data/lib/geeo_code/version.rb +3 -0
- data/lib/geeo_code.rb +57 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/geeo_code.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/geeo_code/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "geeo_code"
|
6
|
+
s.version = GeeoCode::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Luke van der Hoeven"]
|
9
|
+
s.email = ["hungerandthirst@gmail.com"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/geeo_code"
|
11
|
+
s.summary = "Quick gem to do google geocoding based on the json/xml api (v3)."
|
12
|
+
s.description = "This gem is has a simple, singular purpose to wrap itself warmly around google's
|
13
|
+
geocoding apis and give you back cleanly parsed hashes of the data. Maybe, one day, this will
|
14
|
+
send back Ruby objects rather than simple hashes, but this does the trick for now."
|
15
|
+
|
16
|
+
s.required_rubygems_version = ">= 1.3.6"
|
17
|
+
s.rubyforge_project = "geeo_code"
|
18
|
+
|
19
|
+
s.add_development_dependency "bundler", ">= 1.0.3"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
23
|
+
s.require_path = 'lib'
|
24
|
+
|
25
|
+
require 'bundler'
|
26
|
+
Gem::Specification.new do |s|
|
27
|
+
s.add_bundler_dependencies
|
28
|
+
end
|
29
|
+
end
|
data/lib/geeo_code.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
require 'geeo_code/version'
|
6
|
+
|
7
|
+
class GeeoCode
|
8
|
+
GOOGLE_ENDPOINT = "http://maps.googleapis.com/maps/api/geocode/".freeze
|
9
|
+
|
10
|
+
VALID_OPTIONS = [:proxy, :sensor, :format]
|
11
|
+
|
12
|
+
attr_accessor *VALID_OPTIONS
|
13
|
+
|
14
|
+
def initialize( options={} )
|
15
|
+
options.map {|k,v| send("#{k}=".to_sym, v)}
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield self
|
20
|
+
end
|
21
|
+
|
22
|
+
def reverse(address)
|
23
|
+
begin
|
24
|
+
url = URI.parse("#{GOOGLE_ENDPOINT}#{format}?address=#{CGI::escape(address)}&sensor=#{sensor}")
|
25
|
+
content = open(url, :proxy => proxy)
|
26
|
+
doc = Yajl::Parser.parse(content, :symbolize_keys => true)
|
27
|
+
|
28
|
+
address = {}
|
29
|
+
geometry = {}
|
30
|
+
match_type = "none"
|
31
|
+
# puts doc
|
32
|
+
|
33
|
+
if doc[:status] == "OK"
|
34
|
+
results = doc[:results].first
|
35
|
+
|
36
|
+
data = results[:address_components]
|
37
|
+
data.each do |piece|
|
38
|
+
address[:street_number] = piece[:short_name] if piece[:types].include? "street_number"
|
39
|
+
address[:street_name] = piece[:short_name] if piece[:types].include? "route"
|
40
|
+
address[:city] = piece[:short_name] if piece[:types].include? "locality"
|
41
|
+
address[:state] = piece[:short_name] if piece[:types].include? "administrative_area_level_1"
|
42
|
+
address[:zip_code] = piece[:short_name] if piece[:types].include? "postal_code"
|
43
|
+
end
|
44
|
+
|
45
|
+
geometry = results[:geometry]
|
46
|
+
lat_lang = results[:geometry][:location]
|
47
|
+
match_type = results[:partial_match] ? "partial" : "exact"
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
return {:address => address, :geometry => geometry, :match_type => match_type}
|
52
|
+
rescue Object => err
|
53
|
+
msg = "Error! #{err.message}"
|
54
|
+
puts msg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geeo_code
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Luke van der Hoeven
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-09 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 3
|
31
|
+
version: 1.0.3
|
32
|
+
type: :development
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
description: |-
|
36
|
+
This gem is has a simple, singular purpose to wrap itself warmly around google's
|
37
|
+
geocoding apis and give you back cleanly parsed hashes of the data. Maybe, one day, this will
|
38
|
+
send back Ruby objects rather than simple hashes, but this does the trick for now.
|
39
|
+
email:
|
40
|
+
- hungerandthirst@gmail.com
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Rakefile
|
51
|
+
- geeo_code.gemspec
|
52
|
+
- lib/geeo_code.rb
|
53
|
+
- lib/geeo_code/version.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://rubygems.org/gems/geeo_code
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 3
|
79
|
+
- 6
|
80
|
+
version: 1.3.6
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: geeo_code
|
84
|
+
rubygems_version: 1.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Quick gem to do google geocoding based on the json/xml api (v3).
|
88
|
+
test_files: []
|
89
|
+
|