google-maps 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Google::Maps::Place do
4
+ describe ".find" do
5
+ subject { Google::Maps::Place.find(keyword, country).first }
6
+
7
+ context ":nl" do
8
+ before{ stub_response("deventer-nl.json") }
9
+
10
+ let(:keyword) { "Deventer" }
11
+ let(:country) { :nl }
12
+
13
+ its(:text) { should eq "Deventer, Nederland" }
14
+ its(:html) { should eq "<strong>Deventer</strong>, Nederland" }
15
+
16
+ context "keyword with escapeable characters" do
17
+ let(:keyword) { "Deventer \\" }
18
+ let(:country) { :nl }
19
+
20
+ its(:text) { should eq "Deventer, Nederland" }
21
+ its(:html) { should eq "<strong>Deventer</strong>, Nederland" }
22
+ end
23
+ end
24
+
25
+ context ":en" do
26
+ before { stub_response("deventer-en.json") }
27
+
28
+ let(:keyword) { "Deventer" }
29
+ let(:country) { :en }
30
+
31
+ its(:text) { should eq "Deventer, The Netherlands" }
32
+ its(:html) { should eq "<strong>Deventer</strong>, The Netherlands" }
33
+ end
34
+
35
+ context "only highlights words" do
36
+ before { stub_response ("den-haag-nl.json") }
37
+
38
+ let(:keyword) { "Den . * { } Haag \\" }
39
+ let(:country) { :nl }
40
+
41
+ its(:text) { should eq "Den Haag, Nederland" }
42
+ its(:html) { should eq "<strong>Den</strong> <strong>Haag</strong>, Nederland" }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Google::Maps::Route do
4
+ describe "dutch" do
5
+ before(:each) do
6
+ stub_response("amsterdam-deventer-nl.json")
7
+ @route = Google::Maps::Route.new("Science Park, Amsterdam", "Deventer", :nl)
8
+ end
9
+
10
+ it "should be able to calculate a route" do
11
+ @route.distance.text.should == "104 km"
12
+ @route.duration.text.should == "1 uur 12 min."
13
+ @route.distance.value.should == 103712
14
+ @route.duration.value.should == 4337
15
+ end
16
+
17
+ it "should be able to present the text in Dutch" do
18
+ @route.language.should == :nl
19
+ @route.end_address.should == "Deventer, Nederland"
20
+ end
21
+
22
+ it "should be able to return the address for the origin" do
23
+ @route.start_address.should == "Science Park, 1098 Amsterdam, Nederland"
24
+ end
25
+
26
+ it "should be able to return the address for the destination" do
27
+ @route.end_address.should == "Deventer, Nederland"
28
+ end
29
+
30
+ it "should be able to return the latiude and longitude for the origin" do
31
+ @route.start_location.lat.should == 52.35445000000001
32
+ @route.start_location.lng.should == 4.95420
33
+ @route.origin_latlong.should == "52.35445000000001,4.9542"
34
+ end
35
+
36
+ it "should be able to return the latiude and longitude for the destination" do
37
+ @route.end_location.lat.should == 52.25441000000001
38
+ @route.end_location.lng.should == 6.160470
39
+ @route.destination_latlong.should == "52.25441000000001,6.16047"
40
+ end
41
+ end
42
+
43
+ describe "english" do
44
+ it "should be able to present the text in English" do
45
+ stub_response("amsterdam-deventer-en.json")
46
+ route = Google::Maps::Route.new("Science Park, Amsterdam", "Deventer", :en)
47
+ route.language.should == :en
48
+ route.end_address.should == "Deventer, The Netherlands"
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,103 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Google::Maps do
4
+
5
+ describe "Directions" do
6
+ before(:each) do
7
+ stub_response("amsterdam-deventer-en.json")
8
+ end
9
+
10
+ it "should be able to calculate a route" do
11
+ route = Google::Maps.route("Science Park, Amsterdam", "Deventer")
12
+ route.class.should == Google::Maps::Route
13
+ route.distance.text.should == "104 km"
14
+ route.duration.text.should == "1 hour 12 mins"
15
+ route.distance.value.should == 103712
16
+ route.duration.value.should == 4337
17
+ end
18
+
19
+ it "should be able to calculate the distance" do
20
+ Google::Maps.distance("Science Park, Amsterdam", "Deventer").should == "104 km"
21
+ end
22
+
23
+ it "should be able to calculate the duration" do
24
+ Google::Maps.duration("Science Park, Amsterdam", "Deventer").should == "1 hour 12 mins"
25
+ end
26
+ end
27
+
28
+ describe "Places" do
29
+ before(:each) do
30
+ stub_response("deventer-en.json")
31
+ end
32
+
33
+ it "should find a list of places for a keyword" do
34
+ place = Google::Maps.places("Deventer").first
35
+ place.class.should == Google::Maps::Place
36
+ place.text.should == "Deventer, The Netherlands"
37
+ place.html.should == "<strong>Deventer</strong>, The Netherlands"
38
+ end
39
+ end
40
+
41
+ describe "Geocoder" do
42
+ it "should lookup a latlong for an address" do
43
+ stub_response("geocoder/science-park-400-amsterdam-en.json")
44
+
45
+ location = Google::Maps.geocode("Science Park 400, Amsterdam").first
46
+ location.class.should == Google::Maps::Location
47
+ location.address.should == "Science Park Amsterdam 400, University of Amsterdam, 1098 XH Amsterdam, The Netherlands"
48
+ location.latitude.should == 52.3564490
49
+ location.longitude.should == 4.95568890
50
+
51
+ location.lat_lng.should == [52.3564490, 4.95568890]
52
+ end
53
+
54
+ it "should handle multiple location for an address" do
55
+ stub_response("geocoder/amsterdam-en.json")
56
+
57
+ locations = Google::Maps.geocode("Amsterdam")
58
+ locations.should have(2).items
59
+ location = locations.last
60
+ location.address.should == "Amsterdam, NY, USA"
61
+ location.latitude.should == 42.93868560
62
+ location.longitude.should == -74.18818580
63
+ end
64
+
65
+ it "should accept languages other than en" do
66
+ stub_response("geocoder/science-park-400-amsterdam-nl.json")
67
+
68
+ location = Google::Maps.geocode("Science Park 400, Amsterdam", :nl).first
69
+ location.address.should == "Science Park 400, Amsterdam, 1098 XH Amsterdam, Nederland"
70
+ end
71
+
72
+ it "should return an empty array when an address could not be geocoded" do
73
+ stub_response("zero-results.json")
74
+
75
+ Google::Maps.geocode("Amsterdam").should == []
76
+ end
77
+ end
78
+
79
+ describe ".end_point=" do
80
+ it "should set the end_point" do
81
+ Google::Maps.end_point = "http://maps.google.com/"
82
+ Google::Maps.end_point.should == "http://maps.google.com/"
83
+ end
84
+ end
85
+
86
+ describe ".options" do
87
+ it "should return a hash with the current settings" do
88
+ Google::Maps.end_point = "test end point"
89
+ Google::Maps.options == {:end_point => "test end point"}
90
+ end
91
+ end
92
+
93
+ describe ".configure" do
94
+ Google::Maps::Configuration::VALID_OPTIONS_KEYS.each do |key|
95
+ it "should set the #{key}" do
96
+ Google::Maps.configure do |config|
97
+ config.send("#{key}=", key)
98
+ Google::Maps.send(key).should == key
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,36 @@
1
+ require 'rspec'
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_group 'GoogleMaps', 'lib/google-maps'
5
+ add_group 'Specs', 'spec'
6
+ add_filter __FILE__
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.mock_with :mocha
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.filter_run :focus => true
13
+ config.run_all_when_everything_filtered = true
14
+
15
+ config.before(:each) do
16
+ # catch all unmocked requests
17
+ HTTPClient.any_instance.expects(:get_content).never
18
+ end
19
+
20
+ config.after(:each) do
21
+ # reset mock
22
+ HTTPClient.any_instance.unstub(:get_content)
23
+
24
+ # reset configuration
25
+ Google::Maps.reset
26
+ end
27
+ end
28
+
29
+ def stub_response(fixture, url = nil)
30
+ fixture_path = File.expand_path("../fixtures/#{fixture}", __FILE__)
31
+ expectation = HTTPClient.any_instance.expects(:get_content)
32
+ expectation.with(url) if url
33
+ expectation.returns(File.open(fixture_path, "rb").read)
34
+ end
35
+
36
+ load File.expand_path('../../lib/google-maps.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,233 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-maps
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel van Hoesel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.7.5
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.7.5
111
+ - !ruby/object:Gem::Dependency
112
+ name: hashie
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.5
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 2.0.5
125
+ - !ruby/object:Gem::Dependency
126
+ name: httpclient
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 2.3.0.1
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 2.3.0.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: ruby-hmac
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 0.4.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: 0.4.0
153
+ description: This is a ruby wrapper for the Google Maps api
154
+ email:
155
+ - daniel@danielvanhoesel.nl
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - .gitignore
161
+ - Gemfile
162
+ - LICENSE.mkd
163
+ - README.mkd
164
+ - Rakefile
165
+ - google-maps.gemspec
166
+ - lib/google-maps.rb
167
+ - lib/google-maps/api.rb
168
+ - lib/google-maps/configuration.rb
169
+ - lib/google-maps/location.rb
170
+ - lib/google-maps/logger.rb
171
+ - lib/google-maps/place.rb
172
+ - lib/google-maps/route.rb
173
+ - lib/google-maps/version.rb
174
+ - spec/fixtures/amsterdam-deventer-en.json
175
+ - spec/fixtures/amsterdam-deventer-nl.json
176
+ - spec/fixtures/den-haag-nl.json
177
+ - spec/fixtures/deventer-en.json
178
+ - spec/fixtures/deventer-nl.json
179
+ - spec/fixtures/geocoder/amsterdam-en.json
180
+ - spec/fixtures/geocoder/science-park-400-amsterdam-en.json
181
+ - spec/fixtures/geocoder/science-park-400-amsterdam-nl.json
182
+ - spec/fixtures/over_query_limit.json
183
+ - spec/fixtures/place_details.json
184
+ - spec/fixtures/zero-results.json
185
+ - spec/google-maps/api_spec.rb
186
+ - spec/google-maps/logger_spec.rb
187
+ - spec/google-maps/place_details_spec.rb
188
+ - spec/google-maps/place_spec.rb
189
+ - spec/google-maps/route_spec.rb
190
+ - spec/google-maps_spec.rb
191
+ - spec/spec_helper.rb
192
+ homepage: http://zilverline.com/
193
+ licenses: []
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - '>='
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project: google-maps
211
+ rubygems_version: 2.0.14
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Ruby wrapper for the Google Maps API
215
+ test_files:
216
+ - spec/fixtures/amsterdam-deventer-en.json
217
+ - spec/fixtures/amsterdam-deventer-nl.json
218
+ - spec/fixtures/den-haag-nl.json
219
+ - spec/fixtures/deventer-en.json
220
+ - spec/fixtures/deventer-nl.json
221
+ - spec/fixtures/geocoder/amsterdam-en.json
222
+ - spec/fixtures/geocoder/science-park-400-amsterdam-en.json
223
+ - spec/fixtures/geocoder/science-park-400-amsterdam-nl.json
224
+ - spec/fixtures/over_query_limit.json
225
+ - spec/fixtures/place_details.json
226
+ - spec/fixtures/zero-results.json
227
+ - spec/google-maps/api_spec.rb
228
+ - spec/google-maps/logger_spec.rb
229
+ - spec/google-maps/place_details_spec.rb
230
+ - spec/google-maps/place_spec.rb
231
+ - spec/google-maps/route_spec.rb
232
+ - spec/google-maps_spec.rb
233
+ - spec/spec_helper.rb