gmaps_directions 0.1.0 → 0.2.0
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/README.rdoc +6 -5
- data/VERSION +1 -1
- data/gmaps_directions.gemspec +83 -0
- data/lib/gmaps_directions.rb +18 -11
- data/spec/gmaps_directions_spec.rb +38 -38
- metadata +32 -31
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ Google Maps on your server-side and not on the client. The Google Maps API for
|
|
5
5
|
that is dead simple and due to this I wrapped calling the API in this little gem.
|
6
6
|
|
7
7
|
The gem talks to the Google Maps Directions Web Service API. Detailed documentation
|
8
|
-
for that can be found here
|
8
|
+
for that can be found here[http://code.google.com/apis/maps/documentation/directions]
|
9
9
|
This API allows up to 2.500 direction requests. At the current version there is no
|
10
10
|
way to use the non-public interface for Google Premium Maps customers. If you want that
|
11
11
|
feature right now drop me a patch or wait until I need it too (which might not take too
|
@@ -21,16 +21,17 @@ Here is an example of how to use the Gem. As you can see, it is really more than
|
|
21
21
|
require 'rubygems'
|
22
22
|
require 'gmaps_directions'
|
23
23
|
|
24
|
-
|
24
|
+
routes = GmapsDirections::API.find_directions :from => "1 Infinite Loop, Cupertino",
|
25
25
|
:to => "1200 Park Avenue, Emmerville"
|
26
|
+
route = routes.first
|
26
27
|
|
27
|
-
route.duration.should ==
|
28
|
+
route.duration.should == 3482
|
28
29
|
route.formatted_duration.should == "58 mins"
|
29
|
-
route.distance.should ==
|
30
|
+
route.distance.should == 84827
|
30
31
|
route.formatted_distance.should == "84.8 km"
|
31
32
|
route.start_address.should == "1 Infinite Loop, Cupertino, CA 95014, USA"
|
32
33
|
route.end_address.should == "1200 Park Ave, Emeryville, CA 94608, USA"
|
33
|
-
route.start_location.should == { "
|
34
|
+
route.start_location.should == { "lng" => -122.03125, "lat" => 37.3317 }
|
34
35
|
route.end_location.should == { "lat" => 37.8317100, "lng" => -122.2833000 }
|
35
36
|
route.status.should == "OK"
|
36
37
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{gmaps_directions}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dirk Breuer"]
|
12
|
+
s.date = %q{2011-07-12}
|
13
|
+
s.description = %q{
|
14
|
+
Sometimes you need to calculate the directions between two different points
|
15
|
+
via Google Maps on your server-side and not on the client. The Google Maps
|
16
|
+
API for that is dead simple and due to this I wrapped calling the API in
|
17
|
+
this little gem.
|
18
|
+
}
|
19
|
+
s.email = %q{dirk.breuer@gmail.com}
|
20
|
+
s.extra_rdoc_files = [
|
21
|
+
"LICENSE.txt",
|
22
|
+
"README.rdoc"
|
23
|
+
]
|
24
|
+
s.files = [
|
25
|
+
".document",
|
26
|
+
".rspec",
|
27
|
+
"Gemfile",
|
28
|
+
"LICENSE.txt",
|
29
|
+
"README.rdoc",
|
30
|
+
"Rakefile",
|
31
|
+
"VERSION",
|
32
|
+
"gmaps_directions.gemspec",
|
33
|
+
"lib/gmaps_directions.rb",
|
34
|
+
"spec/gmaps_directions_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/railsbros_dirk/gmaps_directions}
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.6.2}
|
41
|
+
s.summary = %q{A simple Gem to use the Google Maps distance API from Ruby}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/gmaps_directions_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.4"])
|
52
|
+
s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.8.1"])
|
53
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.8.1"])
|
58
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.4"])
|
59
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.5"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
62
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.8.1"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.5.0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.8.1"])
|
68
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
69
|
+
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
73
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.8.1"])
|
74
|
+
s.add_dependency(%q<rspec>, ["~> 2.5.0"])
|
75
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
77
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
78
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.8.1"])
|
79
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
|
80
|
+
s.add_dependency(%q<rspec>, ["~> 2.5"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
data/lib/gmaps_directions.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'yajl'
|
2
2
|
require 'yajl/http_stream'
|
3
3
|
require 'uri'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
4
5
|
require 'active_support/configurable'
|
5
6
|
require 'active_support/ordered_options'
|
6
7
|
|
@@ -32,7 +33,13 @@ module GmapsDirections
|
|
32
33
|
def find_directions(options = {})
|
33
34
|
api_driver = new(:start_address => options[:from], :end_address => options[:to])
|
34
35
|
api_driver.call_google
|
35
|
-
|
36
|
+
if api_driver.parsed_directions_response.present? && api_driver.parsed_directions_response["routes"].present?
|
37
|
+
return api_driver.parsed_directions_response["routes"].inject([]) do |routes, route_hash|
|
38
|
+
routes << Route.new(route_hash, api_driver.parsed_directions_response["status"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
return []
|
42
|
+
end
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
@@ -63,16 +70,16 @@ module GmapsDirections
|
|
63
70
|
:start_address, :end_address, :start_location, :end_location,
|
64
71
|
:status
|
65
72
|
|
66
|
-
def initialize(
|
67
|
-
@duration =
|
68
|
-
@formatted_duration =
|
69
|
-
@distance =
|
70
|
-
@formatted_distance =
|
71
|
-
@start_address =
|
72
|
-
@end_address =
|
73
|
-
@start_location =
|
74
|
-
@end_location =
|
75
|
-
@status =
|
73
|
+
def initialize(gmaps_route_hash, status)
|
74
|
+
@duration = gmaps_route_hash["legs"].first["duration"]["value"]
|
75
|
+
@formatted_duration = gmaps_route_hash["legs"].first["duration"]["text"]
|
76
|
+
@distance = gmaps_route_hash["legs"].first["distance"]["value"]
|
77
|
+
@formatted_distance = gmaps_route_hash["legs"].first["distance"]["text"]
|
78
|
+
@start_address = gmaps_route_hash["legs"].first["start_address"]
|
79
|
+
@end_address = gmaps_route_hash["legs"].first["end_address"]
|
80
|
+
@start_location = gmaps_route_hash["legs"].first["start_location"]
|
81
|
+
@end_location = gmaps_route_hash["legs"].first["end_location"]
|
82
|
+
@status = status
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
@@ -7,7 +7,7 @@ describe "GmapsDirections" do
|
|
7
7
|
end_address = "Just Avenue 42, 11111 Sin City"
|
8
8
|
|
9
9
|
directions_api_url = URI.parse("http://maps.googleapis.com/maps/api/directions/json?origin=#{URI.encode(start_address)}&destination=#{URI.encode(end_address)}&mode=driving&units=metric&language=en&sensor=false&alternatives=false")
|
10
|
-
Yajl::HttpStream.should_receive(:get).with(directions_api_url)
|
10
|
+
Yajl::HttpStream.should_receive(:get).with(directions_api_url).and_yield({"routes" => [double("route_hash")], "status" => "OK"})
|
11
11
|
GmapsDirections::Route.should_receive(:new)
|
12
12
|
|
13
13
|
GmapsDirections::API.find_directions :from => start_address, :to => end_address
|
@@ -55,40 +55,38 @@ describe "GmapsDirections" do
|
|
55
55
|
before(:each) do
|
56
56
|
@route = GmapsDirections::Route.new(
|
57
57
|
{
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
61
|
-
|
62
|
-
"steps" => [ {
|
63
|
-
"travel_mode" => "DRIVING",
|
64
|
-
"start_location" => { "lat" => 50.9280500, "lng" => 6.9397100 },
|
65
|
-
"end_location" => { "lat" => 50.9274800, "lng" => 6.9397800 },
|
66
|
-
"polyline" => { },
|
67
|
-
"duration" => { "value" => 11, "text" => "1 min" },
|
68
|
-
"html_instructions" => "",
|
69
|
-
"distance" => { "value" => 63, "text" => "63 m" }
|
70
|
-
} ],
|
71
|
-
"duration" => {
|
72
|
-
"value" => 476,
|
73
|
-
"text" => "8 mins"
|
74
|
-
},
|
75
|
-
"distance" => {
|
76
|
-
"value" => 3166,
|
77
|
-
"text" => "3.2 km"
|
78
|
-
},
|
58
|
+
"summary" => "Luxemburger Str./B265",
|
59
|
+
"legs" => [ {
|
60
|
+
"steps" => [ {
|
61
|
+
"travel_mode" => "DRIVING",
|
79
62
|
"start_location" => { "lat" => 50.9280500, "lng" => 6.9397100 },
|
80
|
-
"end_location" => { "lat" => 50.
|
81
|
-
"
|
82
|
-
"
|
83
|
-
"
|
63
|
+
"end_location" => { "lat" => 50.9274800, "lng" => 6.9397800 },
|
64
|
+
"polyline" => { },
|
65
|
+
"duration" => { "value" => 11, "text" => "1 min" },
|
66
|
+
"html_instructions" => "",
|
67
|
+
"distance" => { "value" => 63, "text" => "63 m" }
|
84
68
|
} ],
|
85
|
-
"
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
"
|
90
|
-
|
91
|
-
|
69
|
+
"duration" => {
|
70
|
+
"value" => 476,
|
71
|
+
"text" => "8 mins"
|
72
|
+
},
|
73
|
+
"distance" => {
|
74
|
+
"value" => 3166,
|
75
|
+
"text" => "3.2 km"
|
76
|
+
},
|
77
|
+
"start_location" => { "lat" => 50.9280500, "lng" => 6.9397100 },
|
78
|
+
"end_location" => { "lat" => 50.9093600, "lng" => 6.9246200 },
|
79
|
+
"start_address" => "Somestr. 23, 99999 Any City, USA",
|
80
|
+
"end_address" => "Just Avenue 42, 11111 Sin City, USA",
|
81
|
+
"via_waypoint" => [ ]
|
82
|
+
} ],
|
83
|
+
"copyrights" => "Map data ©2011 Tele Atlas",
|
84
|
+
"overview_polyline" => { },
|
85
|
+
"warnings" => [ ],
|
86
|
+
"waypoint_order" => [ ],
|
87
|
+
"bounds" => { }
|
88
|
+
},
|
89
|
+
"OK"
|
92
90
|
)
|
93
91
|
end
|
94
92
|
|
@@ -131,16 +129,18 @@ describe "GmapsDirections" do
|
|
131
129
|
end
|
132
130
|
|
133
131
|
it 'should perform a real request see if everything is parsed correctly' do
|
134
|
-
|
135
|
-
|
132
|
+
routes = GmapsDirections::API.find_directions :from => "1 Infinite Loop, Cupertino",
|
133
|
+
:to => "1200 Park Avenue, Emmerville"
|
136
134
|
|
137
|
-
route.
|
135
|
+
route = routes.first
|
136
|
+
|
137
|
+
route.duration.should == 3482
|
138
138
|
route.formatted_duration.should == "58 mins"
|
139
|
-
route.distance.should ==
|
139
|
+
route.distance.should == 84827
|
140
140
|
route.formatted_distance.should == "84.8 km"
|
141
141
|
route.start_address.should == "1 Infinite Loop, Cupertino, CA 95014, USA"
|
142
142
|
route.end_address.should == "1200 Park Ave, Emeryville, CA 94608, USA"
|
143
|
-
route.start_location.should == { "
|
143
|
+
route.start_location.should == { "lng" => -122.03125, "lat" => 37.3317 }
|
144
144
|
route.end_location.should == { "lat" => 37.8317100, "lng" => -122.2833000 }
|
145
145
|
route.status.should == "OK"
|
146
146
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps_directions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dirk Breuer
|
@@ -15,13 +15,14 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-12 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
22
23
|
prerelease: false
|
23
24
|
type: :runtime
|
24
|
-
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
26
|
none: false
|
26
27
|
requirements:
|
27
28
|
- - ~>
|
@@ -32,12 +33,12 @@ dependencies:
|
|
32
33
|
- 0
|
33
34
|
- 4
|
34
35
|
version: 3.0.4
|
35
|
-
|
36
|
-
version_requirements: *id001
|
36
|
+
requirement: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
+
name: yajl-ruby
|
38
39
|
prerelease: false
|
39
40
|
type: :runtime
|
40
|
-
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
42
|
none: false
|
42
43
|
requirements:
|
43
44
|
- - ~>
|
@@ -48,12 +49,12 @@ dependencies:
|
|
48
49
|
- 8
|
49
50
|
- 1
|
50
51
|
version: 0.8.1
|
51
|
-
|
52
|
-
version_requirements: *id002
|
52
|
+
requirement: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
54
55
|
prerelease: false
|
55
56
|
type: :development
|
56
|
-
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
58
|
none: false
|
58
59
|
requirements:
|
59
60
|
- - ~>
|
@@ -64,12 +65,12 @@ dependencies:
|
|
64
65
|
- 5
|
65
66
|
- 0
|
66
67
|
version: 2.5.0
|
67
|
-
|
68
|
-
version_requirements: *id003
|
68
|
+
requirement: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
70
71
|
prerelease: false
|
71
72
|
type: :development
|
72
|
-
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
73
74
|
none: false
|
74
75
|
requirements:
|
75
76
|
- - ~>
|
@@ -80,12 +81,12 @@ dependencies:
|
|
80
81
|
- 0
|
81
82
|
- 0
|
82
83
|
version: 1.0.0
|
83
|
-
|
84
|
-
version_requirements: *id004
|
84
|
+
requirement: *id004
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
|
+
name: jeweler
|
86
87
|
prerelease: false
|
87
88
|
type: :development
|
88
|
-
|
89
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
89
90
|
none: false
|
90
91
|
requirements:
|
91
92
|
- - ~>
|
@@ -96,12 +97,12 @@ dependencies:
|
|
96
97
|
- 5
|
97
98
|
- 2
|
98
99
|
version: 1.5.2
|
99
|
-
|
100
|
-
version_requirements: *id005
|
100
|
+
requirement: *id005
|
101
101
|
- !ruby/object:Gem::Dependency
|
102
|
+
name: rcov
|
102
103
|
prerelease: false
|
103
104
|
type: :development
|
104
|
-
|
105
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
105
106
|
none: false
|
106
107
|
requirements:
|
107
108
|
- - ">="
|
@@ -110,12 +111,12 @@ dependencies:
|
|
110
111
|
segments:
|
111
112
|
- 0
|
112
113
|
version: "0"
|
113
|
-
|
114
|
-
version_requirements: *id006
|
114
|
+
requirement: *id006
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
|
+
name: yajl-ruby
|
116
117
|
prerelease: false
|
117
118
|
type: :runtime
|
118
|
-
|
119
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
119
120
|
none: false
|
120
121
|
requirements:
|
121
122
|
- - ~>
|
@@ -126,12 +127,12 @@ dependencies:
|
|
126
127
|
- 8
|
127
128
|
- 1
|
128
129
|
version: 0.8.1
|
129
|
-
|
130
|
-
version_requirements: *id007
|
130
|
+
requirement: *id007
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
|
+
name: activesupport
|
132
133
|
prerelease: false
|
133
134
|
type: :runtime
|
134
|
-
|
135
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
135
136
|
none: false
|
136
137
|
requirements:
|
137
138
|
- - ~>
|
@@ -142,12 +143,12 @@ dependencies:
|
|
142
143
|
- 0
|
143
144
|
- 4
|
144
145
|
version: 3.0.4
|
145
|
-
|
146
|
-
version_requirements: *id008
|
146
|
+
requirement: *id008
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
|
+
name: rspec
|
148
149
|
prerelease: false
|
149
150
|
type: :development
|
150
|
-
|
151
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
151
152
|
none: false
|
152
153
|
requirements:
|
153
154
|
- - ~>
|
@@ -157,8 +158,7 @@ dependencies:
|
|
157
158
|
- 2
|
158
159
|
- 5
|
159
160
|
version: "2.5"
|
160
|
-
|
161
|
-
version_requirements: *id009
|
161
|
+
requirement: *id009
|
162
162
|
description: "\n Sometimes you need to calculate the directions between two different points\n via Google Maps on your server-side and not on the client. The Google Maps\n API for that is dead simple and due to this I wrapped calling the API in\n this little gem.\n "
|
163
163
|
email: dirk.breuer@gmail.com
|
164
164
|
executables: []
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- README.rdoc
|
177
177
|
- Rakefile
|
178
178
|
- VERSION
|
179
|
+
- gmaps_directions.gemspec
|
179
180
|
- lib/gmaps_directions.rb
|
180
181
|
- spec/gmaps_directions_spec.rb
|
181
182
|
- spec/spec_helper.rb
|