gdirections 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/lib/gdirections.rb +53 -0
- data/spec/gdirections_spec.rb +22 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +11 -0
- metadata +120 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andrew Stevens
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
<h1>gdirections</h1>
|
2
|
+
|
3
|
+
A quick wrapper for Google Maps directions API that support waypoints.
|
4
|
+
|
5
|
+
Returns an object version of the directions results, http://code.google.com/apis/maps/documentation/directions/#JSON
|
6
|
+
|
7
|
+
Example:
|
8
|
+
<pre>
|
9
|
+
result = Gdirections.get_directions(:origin => "Bevely Hills, CA 90210", :destination => "Minneapolis, MN 55141")
|
10
|
+
route = result.routes.first
|
11
|
+
puts route.legs.first.steps.map{|s| "#{s.html_instructions}, #{s.distance.text}"}
|
12
|
+
</pre>
|
13
|
+
|
14
|
+
Patches and additions are quite welcome. Perhaps you have a clever shortcut or calculation you could add?
|
15
|
+
|
16
|
+
<h2>Note on Patches/Pull Requests</h2>
|
17
|
+
|
18
|
+
* Fork the project.
|
19
|
+
* Make your feature addition or bug fix.
|
20
|
+
* Add tests for it. This is important so I don't break it in a
|
21
|
+
future version unintentionally.
|
22
|
+
* Commit, do not mess with rakefile, version, or history.
|
23
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
24
|
+
* Send me a pull request. Bonus points for topic branches.
|
25
|
+
|
26
|
+
<h2>Copyright</h2>
|
27
|
+
|
28
|
+
Copyright (c) 2010 Andrew Stevens. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "gdirections"
|
8
|
+
gem.summary = %Q{Simple google directions client}
|
9
|
+
gem.description = %Q{fetches directions from Google Maps API and returns the result as an object}
|
10
|
+
gem.email = "astevens@tstmedia.com"
|
11
|
+
gem.homepage = "http://github.com/astevens/gdirections"
|
12
|
+
gem.authors = ["Andrew Stevens"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.3"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
gem.add_dependency "httparty"
|
16
|
+
gem.add_dependency "hashie"
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :spec => :check_dependencies
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
require 'rake/rdoctask'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "gdirections #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/gdirections.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'hashie'
|
4
|
+
|
5
|
+
module Gdirections
|
6
|
+
include HTTParty
|
7
|
+
format :json
|
8
|
+
base_uri "http://maps.googleapis.com"
|
9
|
+
|
10
|
+
def self.get_directions(options = {})
|
11
|
+
options = {
|
12
|
+
:origin => nil,
|
13
|
+
:destination => nil,
|
14
|
+
:mode => :driving,
|
15
|
+
:sensor => :false,
|
16
|
+
:waypoints => nil,
|
17
|
+
:optimize => 'true'
|
18
|
+
}.merge(options)
|
19
|
+
|
20
|
+
raise ArgumentError, "Origin required" if options[:origin].nil?
|
21
|
+
raise ArgumentError, "Destination required" if options[:destination].nil?
|
22
|
+
|
23
|
+
if options[:waypoints] && options[:waypoints].is_a?(Array)
|
24
|
+
options[:waypoints] = "optimize:#{(options.delete(:optimize) == true).to_s}|" + options[:waypoints].join('|')
|
25
|
+
end
|
26
|
+
|
27
|
+
result = get("/maps/api/directions/json", :query => options)
|
28
|
+
if result
|
29
|
+
Route.new(result.parsed_response)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Route < Hashie::Mash
|
34
|
+
|
35
|
+
def route
|
36
|
+
self.routes.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def legs
|
40
|
+
self.route.legs
|
41
|
+
end
|
42
|
+
|
43
|
+
def distance_in_miles
|
44
|
+
(self.route.legs.map{|l| l.duration.value}.inject{|v,l| v+l} / 1610.22).round
|
45
|
+
end
|
46
|
+
|
47
|
+
def time_in_minutes
|
48
|
+
(self.route.legs.map{|l| l.duration.value}.inject{|v,l| v+l} / 60).ceil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end # Gdirections
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
describe "Gdirections" do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
@result = Gdirections.get_directions(
|
8
|
+
:origin => "Bevely Hills, CA 90210",
|
9
|
+
:destination => "Minneapolis, MN 55141",
|
10
|
+
:waypoints => ["Hoboken, NJ", "Las Vegas, NV", "Anchorage, AK"]
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should get a result from google" do
|
15
|
+
@result.should_not_be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should handle waypoints" do
|
19
|
+
@result.route.waypoint_order.count.should eql(3)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'gdirections'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
require 'httparty'
|
7
|
+
require 'hashie'
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gdirections
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrew Stevens
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-27 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
version: "1.3"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: httparty
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: hashie
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :runtime
|
63
|
+
version_requirements: *id003
|
64
|
+
description: fetches directions from Google Maps API and returns the result as an object
|
65
|
+
email: astevens@tstmedia.com
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files:
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
files:
|
74
|
+
- .document
|
75
|
+
- .gitignore
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- VERSION
|
80
|
+
- lib/gdirections.rb
|
81
|
+
- spec/gdirections_spec.rb
|
82
|
+
- spec/spec.opts
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
has_rdoc: true
|
85
|
+
homepage: http://github.com/astevens/gdirections
|
86
|
+
licenses: []
|
87
|
+
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options:
|
90
|
+
- --charset=UTF-8
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.3.7
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Simple google directions client
|
118
|
+
test_files:
|
119
|
+
- spec/gdirections_spec.rb
|
120
|
+
- spec/spec_helper.rb
|