server-side-google-maps 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 +4 -0
- data/AUTHORS +1 -0
- data/Gemfile +8 -0
- data/LICENSE +3 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/bin/autospec +16 -0
- data/bin/htmldiff +16 -0
- data/bin/httparty +16 -0
- data/bin/ldiff +16 -0
- data/bin/rspec +16 -0
- data/lib/server-side-google-maps.rb +11 -0
- data/lib/server-side-google-maps/directions.rb +137 -0
- data/lib/server-side-google-maps/geo_math.rb +24 -0
- data/lib/server-side-google-maps/route.rb +53 -0
- data/lib/server-side-google-maps/server.rb +13 -0
- data/lib/server-side-google-maps/version.rb +3 -0
- data/server-side-google-maps.gemspec +24 -0
- data/spec/directions_spec.rb +122 -0
- data/spec/files/directions-45.5086700,-73.5536800-to-45.4119000,-75.6984600.txt +344 -0
- data/spec/files/directions-Montreal,QC-to-Ottawa,ON.txt +344 -0
- data/spec/files/directions-Ottawa,ON-to-Toronto,ON.txt +344 -0
- data/spec/route_spec.rb +98 -0
- data/spec/spec.rb +3 -0
- metadata +124 -0
data/spec/route_spec.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec'
|
2
|
+
|
3
|
+
module ServerSideGoogleMaps
|
4
|
+
describe(Route) do
|
5
|
+
describe('#initialize') do
|
6
|
+
it('should require a 2+-item list') do
|
7
|
+
Server.stub('get').and_return({})
|
8
|
+
|
9
|
+
expect { Route.new }.to(raise_exception(ArgumentError))
|
10
|
+
expect { Route.new(['point1']) }.to(raise_exception(ArgumentError))
|
11
|
+
Route.new(['point1', 'point2'])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context('with a mocked Directions') do
|
16
|
+
class Parser < HTTParty::Parser
|
17
|
+
public_class_method(:new)
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
Directions.stub(:get) do |params|
|
22
|
+
basename = if params[:origin] == 'Montreal,QC'
|
23
|
+
'directions-Montreal,QC-to-Ottawa,ON.txt'
|
24
|
+
else
|
25
|
+
'directions-Ottawa,ON-to-Toronto,ON.txt'
|
26
|
+
end
|
27
|
+
|
28
|
+
data = File.read("#{File.dirname(__FILE__)}/files/#{basename}")
|
29
|
+
parser = Parser.new(data, :json)
|
30
|
+
parser.parse
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it('should call Directions.new for each leg') do
|
35
|
+
Directions.should_receive(:new).with('Montreal,QC', 'Ottawa,ON', {}).ordered
|
36
|
+
Directions.should_receive(:new).with('Ottawa,ON', 'Toronto,ON', {}).ordered
|
37
|
+
|
38
|
+
Route.new(['Montreal,QC', 'Ottawa,ON', 'Toronto,ON'])
|
39
|
+
end
|
40
|
+
|
41
|
+
it('should pass :mode') do
|
42
|
+
Directions.should_receive(:new).with('Montreal,QC', 'Ottawa,ON', :mode => :bicycling)
|
43
|
+
|
44
|
+
Route.new(['Montreal,QC', 'Ottawa,ON'], :mode => :bicycling)
|
45
|
+
end
|
46
|
+
|
47
|
+
it('should return appropriate origin_input and destination_input') do
|
48
|
+
route = Route.new(['Montreal,QC', 'Ottawa,ON', 'Toronto,ON'])
|
49
|
+
route.origin_input.should == 'Montreal,QC'
|
50
|
+
route.destination_input.should == 'Toronto,ON'
|
51
|
+
end
|
52
|
+
|
53
|
+
it('should return appropriate origin_address and destination_address') do
|
54
|
+
route = Route.new(['Montreal,QC', 'Ottawa,ON', 'Toronto,ON'])
|
55
|
+
route.origin_address.should == 'Montreal, QC, Canada'
|
56
|
+
route.destination_address.should == 'Toronto, ON, Canada'
|
57
|
+
end
|
58
|
+
|
59
|
+
it('should return appropriate origin_point and destination_point') do
|
60
|
+
route = Route.new(['Montreal,QC', 'Ottawa,ON', 'Toronto,ON'])
|
61
|
+
route.origin_point.should == [ 45.5086700, -73.5536800 ]
|
62
|
+
route.destination_point.should == [ 43.65235, -79.3824 ]
|
63
|
+
end
|
64
|
+
|
65
|
+
it('should concatenate the points from component directions') do
|
66
|
+
route = Route.new(['Montreal,QC', 'Ottawa,ON', 'Toronto,ON'])
|
67
|
+
points = route.points
|
68
|
+
points.length.should == 352
|
69
|
+
points[0].should == [45.50867, -73.55368]
|
70
|
+
points[137].should == [45.4119, -75.69846]
|
71
|
+
points[138].should == [45.40768, -75.69567]
|
72
|
+
points[351].should == [ 43.65235, -79.3824 ]
|
73
|
+
end
|
74
|
+
|
75
|
+
it('should have the proper distance') do
|
76
|
+
route = Route.new(['Montreal,QC', 'Ottawa,ON', 'Toronto,ON'])
|
77
|
+
distance = route.distance
|
78
|
+
distance.should == 649742
|
79
|
+
end
|
80
|
+
|
81
|
+
it('should not alter params') do
|
82
|
+
original_params = {
|
83
|
+
:mode => :driving,
|
84
|
+
:find_shortcuts => [{ :factor => 0.5, :mode => :direct }]
|
85
|
+
}
|
86
|
+
passed_params = {
|
87
|
+
:mode => :driving,
|
88
|
+
:find_shortcuts => [{ :factor => 0.5, :mode => :direct }]
|
89
|
+
}
|
90
|
+
route = Route.new(
|
91
|
+
['Montreal,QC', 'Ottawa,ON', 'Toronto,ON'],
|
92
|
+
passed_params
|
93
|
+
)
|
94
|
+
passed_params.should == original_params
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/spec/spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: server-side-google-maps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Adam Hooper
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-26 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: nayutaya-googlemaps-polyline
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 29
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
- 1
|
48
|
+
version: 0.0.1
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Servers can use Google Maps, too. This library helps fetch and parse data through the Google Maps v3 API. Stick to the terms of usage, though, and don't use the data Google gives you on anything other than a Google map.
|
52
|
+
email:
|
53
|
+
- adam@adamhooper.com
|
54
|
+
executables:
|
55
|
+
- autospec
|
56
|
+
- htmldiff
|
57
|
+
- httparty
|
58
|
+
- ldiff
|
59
|
+
- rspec
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files: []
|
63
|
+
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- AUTHORS
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/autospec
|
72
|
+
- bin/htmldiff
|
73
|
+
- bin/httparty
|
74
|
+
- bin/ldiff
|
75
|
+
- bin/rspec
|
76
|
+
- lib/server-side-google-maps.rb
|
77
|
+
- lib/server-side-google-maps/directions.rb
|
78
|
+
- lib/server-side-google-maps/geo_math.rb
|
79
|
+
- lib/server-side-google-maps/route.rb
|
80
|
+
- lib/server-side-google-maps/server.rb
|
81
|
+
- lib/server-side-google-maps/version.rb
|
82
|
+
- server-side-google-maps.gemspec
|
83
|
+
- spec/directions_spec.rb
|
84
|
+
- spec/files/directions-45.5086700,-73.5536800-to-45.4119000,-75.6984600.txt
|
85
|
+
- spec/files/directions-Montreal,QC-to-Ottawa,ON.txt
|
86
|
+
- spec/files/directions-Ottawa,ON-to-Toronto,ON.txt
|
87
|
+
- spec/route_spec.rb
|
88
|
+
- spec/spec.rb
|
89
|
+
has_rdoc: true
|
90
|
+
homepage: http://github.com/adamh/server-side-google-maps
|
91
|
+
licenses: []
|
92
|
+
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project: server-side-google-maps
|
119
|
+
rubygems_version: 1.3.7
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Performs calculations with Google Maps
|
123
|
+
test_files: []
|
124
|
+
|