google-geocoder 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/Rakefile +31 -26
- data/VERSION +1 -1
- data/bin/geo +7 -5
- data/google-geocoder.gemspec +9 -9
- data/lib/{google_geocoder.rb → google_geocoder/google_geocoder.rb} +29 -18
- metadata +7 -7
data/CHANGES
CHANGED
data/Rakefile
CHANGED
@@ -9,34 +9,39 @@ require 'rcov/rcovtask'
|
|
9
9
|
|
10
10
|
task :default => :gemspec
|
11
11
|
|
12
|
-
begin
|
13
|
-
require 'bundler'
|
14
|
-
|
15
12
|
begin
|
16
|
-
require '
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
13
|
+
require 'bundler'
|
14
|
+
|
15
|
+
begin
|
16
|
+
require 'jeweler'
|
17
|
+
|
18
|
+
Jeweler::Tasks.new do |gemspec|
|
19
|
+
gemspec.name = "google-geocoder"
|
20
|
+
gemspec.summary = "Simple client for Google Geocode API (Summary)."
|
21
|
+
gemspec.description = "Simple client for Google Geocode API."
|
22
|
+
gemspec.email = "alexander.shvets@gmail.com"
|
23
|
+
gemspec.homepage = "http://github.com/shvets/google-geocoder"
|
24
|
+
gemspec.authors = ["Alexander Shvets"]
|
25
|
+
gemspec.files = FileList["CHANGES", "google-geocoder.gemspec", "Rakefile", "README", "VERSION",
|
26
|
+
"lib/**/*", "bin/**/*"]
|
27
|
+
|
28
|
+
gemspec.executables = ['geo', 'g']
|
29
|
+
gemspec.requirements = ["none"]
|
30
|
+
gemspec.bindir = "bin"
|
31
|
+
|
32
|
+
gemspec.add_bundler_dependencies
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
puts "Jeweler not available. Install it s with: [sudo] gem install jeweler"
|
34
36
|
end
|
35
37
|
rescue LoadError
|
36
|
-
puts "
|
38
|
+
puts "Bundler not available. Install it s with: [sudo] gem install bundler"
|
37
39
|
end
|
38
|
-
|
39
|
-
|
40
|
+
|
41
|
+
desc "Remove temp files"
|
42
|
+
task "clean" do
|
43
|
+
`rm pkg`
|
44
|
+
`rm google-geocoder.gemspec`
|
40
45
|
end
|
41
46
|
|
42
47
|
desc "Release the gem"
|
@@ -50,14 +55,14 @@ task :"release:gem" do
|
|
50
55
|
puts "Commit message:"
|
51
56
|
message = STDIN.gets
|
52
57
|
|
53
|
-
version = "#{File.open(File::dirname(__FILE__) + "/VERSION").readlines().first}"
|
58
|
+
version = "#{File.open(File::dirname(__FILE__) + "/VERSION").readlines().first.strip}"
|
54
59
|
|
55
60
|
%x(
|
56
61
|
git commit -m "#{message}"
|
57
62
|
|
58
63
|
git push origin master
|
59
64
|
|
60
|
-
gem push pkg/google-geocoder-#{version}.gem
|
65
|
+
gem push pkg/google-geocoder-#{version}.gem
|
61
66
|
)
|
62
67
|
end
|
63
68
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/geo
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
$:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
|
4
4
|
|
5
5
|
require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
|
6
|
-
require 'google_geocoder'
|
6
|
+
require 'google_geocoder/google_geocoder'
|
7
7
|
|
8
8
|
#$KCODE='u'
|
9
9
|
|
@@ -23,15 +23,17 @@ class Geo
|
|
23
23
|
puts USAGE and return
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
cmd_line = ARGV.join(' ')
|
27
27
|
|
28
|
-
case
|
29
|
-
|
28
|
+
case cmd_line
|
30
29
|
when /(-v)|(--version)/ then
|
31
30
|
puts "Version: #{File.open(File::dirname(__FILE__) + "/../VERSION").readlines().first}"
|
31
|
+
when /(-open)/ then
|
32
|
+
query = cmd_line[5..-1].strip
|
33
|
+
@geocoder.open_in_browser(query)
|
32
34
|
when /(.*)/ then
|
33
35
|
begin
|
34
|
-
result = @geocoder.query(
|
36
|
+
result = @geocoder.query(cmd_line)
|
35
37
|
|
36
38
|
puts "No results." if result.size == 0
|
37
39
|
rescue Exception => e
|
data/google-geocoder.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{google-geocoder}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexander Shvets"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-01}
|
13
13
|
s.description = %q{Simple client for Google Geocode API.}
|
14
14
|
s.email = %q{alexander.shvets@gmail.com}
|
15
15
|
s.executables = ["geo", "g"]
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"bin/geo",
|
27
27
|
"bin/geo.bat",
|
28
28
|
"google-geocoder.gemspec",
|
29
|
-
"lib/google_geocoder.rb"
|
29
|
+
"lib/google_geocoder/google_geocoder.rb"
|
30
30
|
]
|
31
31
|
s.homepage = %q{http://github.com/shvets/google-geocoder}
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -44,19 +44,19 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.specification_version = 3
|
45
45
|
|
46
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
-
s.add_runtime_dependency(%q<json_pure>, ["
|
48
|
-
s.add_runtime_dependency(%q<
|
47
|
+
s.add_runtime_dependency(%q<json_pure>, ["~> 1.1.4"])
|
48
|
+
s.add_runtime_dependency(%q<launchy>, [">= 0"])
|
49
49
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
50
50
|
s.add_development_dependency(%q<gemcutter>, [">= 0"])
|
51
51
|
else
|
52
|
-
s.add_dependency(%q<json_pure>, ["
|
53
|
-
s.add_dependency(%q<
|
52
|
+
s.add_dependency(%q<json_pure>, ["~> 1.1.4"])
|
53
|
+
s.add_dependency(%q<launchy>, [">= 0"])
|
54
54
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
55
55
|
s.add_dependency(%q<gemcutter>, [">= 0"])
|
56
56
|
end
|
57
57
|
else
|
58
|
-
s.add_dependency(%q<json_pure>, ["
|
59
|
-
s.add_dependency(%q<
|
58
|
+
s.add_dependency(%q<json_pure>, ["~> 1.1.4"])
|
59
|
+
s.add_dependency(%q<launchy>, [">= 0"])
|
60
60
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
61
61
|
s.add_dependency(%q<gemcutter>, [">= 0"])
|
62
62
|
end
|
@@ -3,30 +3,32 @@
|
|
3
3
|
require 'open-uri'
|
4
4
|
require 'cgi'
|
5
5
|
require 'json'
|
6
|
+
require 'launchy'
|
6
7
|
|
7
8
|
# Example:
|
8
9
|
# {
|
9
10
|
# "results"=> [
|
10
11
|
# {"address_components"=>
|
11
|
-
# [{"long_name"=>"Paris", "types"=>["locality", "political"], "short_name"=>"Paris"},
|
12
|
-
# {"long_name"=>"Paris", "types"=>["administrative_area_level_2", "political" ], "short_name"=>"75"},
|
12
|
+
# [{"long_name"=>"Paris", "types"=>["locality", "political"], "short_name"=>"Paris"},
|
13
|
+
# {"long_name"=>"Paris", "types"=>["administrative_area_level_2", "political" ], "short_name"=>"75"},
|
13
14
|
# {"long_name"=>"Ile-de-France", "types"=>["administrative_area_level_1", "political"], "short_name"=>"IDF"},
|
14
15
|
# {"long_name"=>"France", "types"=>["country", "political"], "short_name"=>"FR"}
|
15
|
-
# ],
|
16
|
+
# ],
|
16
17
|
# "geometry"=>{
|
17
|
-
# "bounds"=>{"northeast"=>{"lng"=>2.4699099, "lat"=>48.9021461}, "southwest"=>{"lng"=>2.2241006, "lat"=>48.8155414}},
|
18
|
-
# "location"=>{"lng"=>2.3509871, "lat"=>48.8566667},
|
19
|
-
# "location_type"=>"APPROXIMATE",
|
18
|
+
# "bounds"=>{"northeast"=>{"lng"=>2.4699099, "lat"=>48.9021461}, "southwest"=>{"lng"=>2.2241006, "lat"=>48.8155414}},
|
19
|
+
# "location"=>{"lng"=>2.3509871, "lat"=>48.8566667},
|
20
|
+
# "location_type"=>"APPROXIMATE",
|
20
21
|
# "viewport"=>{"northeast"=>{"lng"=>2.4790465, "lat"=>48.915363}, "southwest"=>{"lng"=>2.2229277, "lat"=>48.7979015}}
|
21
22
|
# },
|
22
|
-
# "types"=>["locality", "political"],
|
23
|
+
# "types"=>["locality", "political"],
|
23
24
|
# "formatted_address"=>"Paris, France"}
|
24
|
-
# ],
|
25
|
+
# ],
|
25
26
|
# "status"=>"OK"
|
26
27
|
# }
|
27
28
|
|
28
29
|
module Google
|
29
30
|
class Geocoder
|
31
|
+
|
30
32
|
def self.Exception(*names)
|
31
33
|
cl = Module === self ? self : Object
|
32
34
|
names.each {|n| cl.const_set(n, Class.new(Exception))}
|
@@ -35,17 +37,18 @@ module Google
|
|
35
37
|
Exception :MissingLocation, :GeocoderServerIsDown, :InvalidResponse
|
36
38
|
|
37
39
|
URL_STRING = "http://maps.googleapis.com/maps/api/geocode"
|
40
|
+
MAPS_URL_STRING = "http://maps.google.com/maps?f=q&source=s_q&iwloc=A&hl=en"
|
38
41
|
|
39
42
|
def query(location)
|
40
|
-
raise(MissingLocation) if location.nil?
|
41
|
-
|
42
|
-
request = "#{URL_STRING}/json?address=#{CGI.escape(location)}&sensor=false"
|
43
|
-
|
43
|
+
raise(MissingLocation) if location.nil?
|
44
|
+
|
45
|
+
request = "#{URL_STRING}/json?address=#{CGI.escape(location)}&sensor=false"
|
46
|
+
|
44
47
|
begin
|
45
48
|
response = call_service(request)
|
46
49
|
|
47
50
|
raise(GeocoderServerIsDown) if response.empty?
|
48
|
-
|
51
|
+
|
49
52
|
if response['status'] == "ZERO_RESULTS"
|
50
53
|
[]
|
51
54
|
else
|
@@ -69,18 +72,26 @@ module Google
|
|
69
72
|
puts "Administrative Area (level 2): #{administrative_area_l2['long_name']} (#{administrative_area_l2['short_name']})" unless administrative_area_l2.nil?
|
70
73
|
|
71
74
|
puts "Latitude: #{latitude}"
|
72
|
-
puts "Longitude: #{longitude}"
|
75
|
+
puts "Longitude: #{longitude}"
|
73
76
|
|
74
|
-
[latitude, longitude]
|
77
|
+
[latitude, longitude]
|
75
78
|
end
|
76
79
|
rescue OpenURI::HTTPError
|
77
80
|
raise(GeocoderServerIsDown)
|
78
|
-
end
|
81
|
+
end
|
79
82
|
end
|
80
83
|
|
84
|
+
def open_in_browser q
|
85
|
+
location = q.gsub(/\s/, '+')
|
86
|
+
lng, lat = query(q)
|
87
|
+
|
88
|
+
Launchy::Browser.run("#{MAPS_URL_STRING}&geocode=&q=#{location}&sll=#{lng},#{lat}&hnear=#{location}")
|
89
|
+
end
|
90
|
+
|
81
91
|
private
|
82
92
|
|
83
93
|
def call_service(request)
|
94
|
+
|
84
95
|
response = {}
|
85
96
|
|
86
97
|
open(request) do |stream|
|
@@ -93,14 +104,14 @@ module Google
|
|
93
104
|
|
94
105
|
response
|
95
106
|
end
|
96
|
-
|
107
|
+
|
97
108
|
def address_component(parent, type)
|
98
109
|
parent.each do |child|
|
99
110
|
if child["types"].include? type
|
100
111
|
return child
|
101
112
|
end
|
102
113
|
end
|
103
|
-
|
114
|
+
|
104
115
|
nil
|
105
116
|
end
|
106
117
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.3
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexander Shvets
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-01 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
28
|
-
- -
|
28
|
+
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
hash: 27
|
31
31
|
segments:
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
|
-
name:
|
40
|
+
name: launchy
|
41
41
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- bin/geo
|
96
96
|
- bin/geo.bat
|
97
97
|
- google-geocoder.gemspec
|
98
|
-
- lib/google_geocoder.rb
|
98
|
+
- lib/google_geocoder/google_geocoder.rb
|
99
99
|
- spec/geocoder_spec.rb
|
100
100
|
- spec/spec_helper.rb
|
101
101
|
has_rdoc: true
|