mapquest_directions 0.1.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/Manifest +9 -0
- data/README.textile +70 -0
- data/Rakefile +15 -0
- data/init.rb +1 -0
- data/lib/mapquest_directions.rb +69 -0
- data/mapquest_directions.gemspec +33 -0
- data/spec/lib/mapquest_directions.xml +2 -0
- data/spec/lib/mapquest_directions_fail.xml +2 -0
- data/spec/lib/mapquest_directions_spec.rb +58 -0
- data/spec/spec_helper.rb +13 -0
- metadata +98 -0
data/Manifest
ADDED
data/README.textile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
h2. Usage
|
2
|
+
|
3
|
+
Get a MapQuest API key, and store in your app under MAPQUEST_KEY
|
4
|
+
<pre>MAPQUEST_KEY = 'your_api_key'</pre>
|
5
|
+
|
6
|
+
<pre>directions = MapQuestDirections.new(origin, destination)</pre>
|
7
|
+
where _origin_ and _destination_ are strings of addresses or places that MapQuest can find an address for. Example: "816 Meridian St., 37207"
|
8
|
+
|
9
|
+
Get drive time or distance of whole trip
|
10
|
+
<pre>
|
11
|
+
drive_time_in_minutes = directions.drive_time_in_minutes
|
12
|
+
distance_in_miles = directions.distance_in_miles
|
13
|
+
</pre>
|
14
|
+
|
15
|
+
Get the XML MapQuest returns with every turn, or the API call URL
|
16
|
+
<pre>
|
17
|
+
xml = directions.xml
|
18
|
+
xml_call = directions.xml_call
|
19
|
+
</pre>
|
20
|
+
|
21
|
+
h3. Error situations
|
22
|
+
|
23
|
+
<pre>directions.status</pre> shows you the status code returned by MapQuest. 0 means worked. Other codes (500, 403) mean problem.
|
24
|
+
|
25
|
+
If MapQuest can't recognize your places or gives an error, the distance_in_miles and drive_time_in_minutes will each return 0. You can call <pre>directions.status</pre> and it should tell you a number code for the problem. You can call <pre>directions.xml</pre> to read the full text.
|
26
|
+
|
27
|
+
h2. Installation
|
28
|
+
|
29
|
+
h3. gem
|
30
|
+
|
31
|
+
rails 2.3
|
32
|
+
# gem install mapquest_directions
|
33
|
+
# add config.gem "mapquest_directions" to your environment.rb file
|
34
|
+
|
35
|
+
rails 3.0
|
36
|
+
# gem 'mapquest_directions' in your Gemfile
|
37
|
+
# <pre>bundle install</pre> from command line
|
38
|
+
|
39
|
+
h3. Rails plugin
|
40
|
+
|
41
|
+
Rails 2.3
|
42
|
+
<pre>script/plugin install git://github.com/joshcrews/mapquest-directions-ruby.git</pre>
|
43
|
+
|
44
|
+
Rails 3.0
|
45
|
+
<pre>rails plugin install git://github.com/joshcrews/mapquest-directions-ruby.git</pre>
|
46
|
+
|
47
|
+
h3. Compatibility
|
48
|
+
|
49
|
+
Tested on Rails 2.3.8
|
50
|
+
|
51
|
+
Not yet tested on Rails 3. It probably is Rails 3 compatible, because it's just a single class with a few methods. It's probably compatible with every ruby project ever.
|
52
|
+
|
53
|
+
h3. MapQuest maps API key
|
54
|
+
|
55
|
+
You'll need a MapQuest Map API key
|
56
|
+
|
57
|
+
http://developer.mapquest.com/
|
58
|
+
|
59
|
+
Include it as the constant MAPQUEST_KEY in an app configuration file (environment.rb, config/initializers/api_keys.rb)
|
60
|
+
|
61
|
+
h3. Need turn-by-turn directions?
|
62
|
+
|
63
|
+
Not yet included in this gem, but you can do it with nokogiri to parse the XML that comes back when you do
|
64
|
+
<pre>MapQuestDirections.new(origin, destination).xml</pre>
|
65
|
+
And then nokogiri can cycle through each <maneuver> and you can pick out what you need.
|
66
|
+
|
67
|
+
h2. License
|
68
|
+
|
69
|
+
Anyone can use this code in any way.
|
70
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Rakefile
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
Echoe.new('mapquest_directions', '0.1.0') do |p|
|
7
|
+
p.description = "Ruby-wrapper for MapQuest Directions API. Can return the drive time and driving distance between two places"
|
8
|
+
p.url = "http://github.com/joshcrews/MapQuest-Directions-Ruby"
|
9
|
+
p.author = "Josh Crews"
|
10
|
+
p.email = "josh@joshcrews.com"
|
11
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
12
|
+
p.development_dependencies = ['nokogiri >=1.4.1']
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'mapquest_directions'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
class MapQuestDirections
|
5
|
+
|
6
|
+
def initialize(location_1, location_2)
|
7
|
+
@base_url = "http://www.mapquestapi.com/directions/v1/route?key=#{MAPQUEST_KEY}&outFormat=xml&"
|
8
|
+
@location_1 = location_1
|
9
|
+
@location_2 = location_2
|
10
|
+
options = "from=#{transcribe(@location_1)}&to=#{transcribe(@location_2)}"
|
11
|
+
@xml_call = @base_url + options
|
12
|
+
@status = find_status
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_status
|
16
|
+
doc = Nokogiri::XML(xml)
|
17
|
+
doc.css("statusCode").text
|
18
|
+
end
|
19
|
+
|
20
|
+
def xml
|
21
|
+
unless @xml.nil?
|
22
|
+
@xml
|
23
|
+
else
|
24
|
+
@xml ||= get_url(@xml_call)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def xml_call
|
29
|
+
@xml_call
|
30
|
+
end
|
31
|
+
|
32
|
+
def drive_time_in_minutes
|
33
|
+
if @status != "0"
|
34
|
+
drive_time = 0
|
35
|
+
else
|
36
|
+
doc = Nokogiri::XML(xml)
|
37
|
+
drive_time = doc.css("time").first.text
|
38
|
+
convert_to_minutes(drive_time)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def distance_in_miles
|
43
|
+
if @status != "0"
|
44
|
+
distance_in_miles = 0
|
45
|
+
else
|
46
|
+
doc = Nokogiri::XML(xml)
|
47
|
+
distance_in_miles = doc.css("distance").first.text.to_i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def status
|
52
|
+
@status
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def convert_to_minutes(text)
|
58
|
+
(text.to_i / 60).ceil
|
59
|
+
end
|
60
|
+
|
61
|
+
def transcribe(location)
|
62
|
+
location.gsub(" ", "+")
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_url(url)
|
66
|
+
Net::HTTP.get(::URI.parse(url))
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{mapquest_directions}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Josh Crews"]
|
9
|
+
s.date = %q{2010-08-19}
|
10
|
+
s.description = %q{Ruby-wrapper for MapQuest Directions API. Can return the drive time and driving distance between two places}
|
11
|
+
s.email = %q{josh@joshcrews.com}
|
12
|
+
s.extra_rdoc_files = ["README.textile", "lib/mapquest_directions.rb"]
|
13
|
+
s.files = ["README.textile", "Rakefile", "init.rb", "lib/mapquest_directions.rb", "spec/lib/mapquest_directions.xml", "spec/lib/mapquest_directions_fail.xml", "spec/lib/mapquest_directions_spec.rb", "spec/spec_helper.rb", "Manifest", "mapquest_directions.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/joshcrews/MapQuest-Directions-Ruby}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mapquest_directions", "--main", "README.textile"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{mapquest_directions}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Ruby-wrapper for MapQuest Directions API. Can return the drive time and driving distance between two places}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_development_dependency(%q<nokogiri>, [">= 1.4.1"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.1"])
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<response><info><statusCode>0</statusCode><messages/><copyright><imageUrl>http://tile21.mqcdn.com/res/mqlogo.gif</imageUrl><imageAltText>© 2010 MapQuest, Inc.</imageAltText><text>© 2010 MapQuest, Inc.</text></copyright></info><route><sessionId>4c6c8e89-019b-0001-02b7-4979-0024e83e3993</sessionId><options><shapeFormat>raw</shapeFormat><generalize>-1.0</generalize><maxLinkId>0</maxLinkId><narrativeType>text</narrativeType><stateBoundaryDisplay>true</stateBoundaryDisplay><countryBoundaryDisplay>true</countryBoundaryDisplay><sideOfStreetDisplay>true</sideOfStreetDisplay><destinationManeuverDisplay>true</destinationManeuverDisplay><avoidTimedConditions>false</avoidTimedConditions><enhancedNarrative>false</enhancedNarrative><timeType>0</timeType><routeType>FASTEST</routeType><locale>en_US</locale><unit>M</unit><tryAvoidLinkIds></tryAvoidLinkIds><mustAvoidLinkIds></mustAvoidLinkIds><manmaps>true</manmaps></options><boundingBox><ul><lat>36.185138</lat><lng>-86.940116</lng></ul><lr><lat>32.554519</lat><lng>-85.481231</lng></lr></boundingBox><distance>310.2900085449219</distance><time>18209</time><formattedTime>05:03:29</formattedTime><legs><leg><distance>310.29</distance><time>18209</time><formattedTime>05:03:29</formattedTime><index>0</index><maneuvers><maneuver><startPoint><lat>36.185138</lat><lng>-86.768287</lng></startPoint><maneuverNotes/><distance>0.093</distance><time>22</time><formattedTime>00:00:22</formattedTime><attributes>0</attributes><turnType>2</turnType><direction>4</direction><narrative>Start out going SOUTH on MERIDIAN ST toward ARRINGTON ST.</narrative><directionName>South</directionName><index>0</index><streets><street>MERIDIAN ST</street></streets><signs/><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-2,36.185138,-86.768287,0,0|purple-3,36.183811,-86.768478,0,0|¢er=36.1844745,-86.7683825&zoom=13&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1965438145&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>36.183811</lat><lng>-86.768478</lng></startPoint><maneuverNotes/><distance>0.296</distance><time>73</time><formattedTime>00:01:13</formattedTime><attributes>0</attributes><turnType>2</turnType><direction>7</direction><narrative>Turn RIGHT onto HANCOCK ST.</narrative><directionName>West</directionName><index>1</index><streets><street>HANCOCK ST</street></streets><signs/><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-3,36.183811,-86.768478,0,0|purple-4,36.184398,-86.773712,0,0|¢er=36.184104500000004,-86.771095&zoom=12&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1965438145&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>36.184398</lat><lng>-86.773712</lng></startPoint><maneuverNotes/><distance>0.522</distance><time>75</time><formattedTime>00:01:15</formattedTime><attributes>0</attributes><turnType>6</turnType><direction>4</direction><narrative>Turn LEFT onto N 1ST ST/US-31W/US-41/US-431/TN-11. Continue to follow N 1ST ST.</narrative><directionName>South</directionName><index>2</index><streets><street>N 1ST ST</street></streets><signs/><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_left_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-4,36.184398,-86.773712,0,0|purple-5,36.17691,-86.774551,0,0|¢er=36.180654000000004,-86.77413150000001&zoom=10&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1965438145&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>36.17691</lat><lng>-86.774551</lng></startPoint><maneuverNotes/><distance>0.03</distance><time>6</time><formattedTime>00:00:06</formattedTime><attributes>0</attributes><turnType>6</turnType><direction>8</direction><narrative>Turn LEFT onto SPRING ST.</narrative><directionName>East</directionName><index>3</index><streets><street>SPRING ST</street></streets><signs/><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_left_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-5,36.17691,-86.774551,0,0|purple-6,36.176799,-86.774032,0,0|¢er=36.176854500000005,-86.7742915&zoom=15&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1965438145&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>36.176799</lat><lng>-86.774032</lng></startPoint><maneuverNotes/><distance>1.584</distance><time>134</time><formattedTime>00:02:14</formattedTime><attributes>128</attributes><turnType>10</turnType><direction>8</direction><narrative>Merge onto I-24 E.</narrative><directionName>East</directionName><index>4</index><streets><street>INTERSTATE 24 E</street></streets><signs><sign><type>1</type><direction>8</direction><text>24</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00001CO_SM&n=24&d=EAST]]></url></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_merge_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-6,36.176799,-86.774032,0,0|purple-7,36.157688,-86.760406,0,0|¢er=36.1672435,-86.76721900000001&zoom=9&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1965438145&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>36.157688</lat><lng>-86.760406</lng></startPoint><maneuverNotes/><distance>1.047</distance><time>92</time><formattedTime>00:01:32</formattedTime><attributes>128</attributes><turnType>10</turnType><direction>7</direction><narrative>Merge onto I-40 W via EXIT 50B toward I-65 S/MEMPHIS/HUNTSVILLE.</narrative><directionName>West</directionName><index>5</index><streets><street>INTERSTATE 40 W</street></streets><signs><sign><type>1</type><direction>7</direction><text>40</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00001CO_SM&n=40&d=WEST]]></url></sign><sign><type>1001</type><direction>0</direction><text>50B</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RSEXITRIGHTNUM_SM&n=50B&d=]]></url></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_merge_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-7,36.157688,-86.760406,0,0|purple-8,36.149211,-86.774963,0,0|¢er=36.1534495,-86.7676845&zoom=10&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1965438145&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>36.149211</lat><lng>-86.774963</lng></startPoint><maneuverNotes/><distance>188.83301</distance><time>10207</time><formattedTime>02:50:07</formattedTime><attributes>128</attributes><turnType>11</turnType><direction>4</direction><narrative>Merge onto I-65 S via EXIT 210B on the LEFT toward HUNTSVILLE (Crossing into ALABAMA).</narrative><directionName>South</directionName><index>6</index><streets><street>INTERSTATE 65 S</street></streets><signs><sign><type>1</type><direction>4</direction><text>65</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00001CO_SM&n=65&d=SOUTH]]></url></sign><sign><type>1001</type><direction>0</direction><text>210B</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RSEXITLEFTNUM_SM&n=210B&d=]]></url></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_merge_left_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-8,36.149211,-86.774963,0,0|purple-9,33.523189,-86.826721,0,0|¢er=34.836200000000005,-86.852096&zoom=2&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1965438145&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>33.523189</lat><lng>-86.826721</lng></startPoint><maneuverNotes/><distance>1.234</distance><time>94</time><formattedTime>00:01:34</formattedTime><attributes>128</attributes><turnType>11</turnType><direction>8</direction><narrative>Merge onto I-20 E/I-59 N via EXIT 261A on the LEFT toward ATLANTA/GADSDEN.</narrative><directionName>East</directionName><index>7</index><streets><street>INTERSTATE 20 E</street><street>INTERSTATE 59 N</street></streets><signs><sign><type>1</type><direction>8</direction><text>20</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00001CO_SM&n=20&d=EAST]]></url></sign><sign><type>1</type><direction>1</direction><text>59</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00001CO_SM&n=59&d=NORTH]]></url></sign><sign><type>1001</type><direction>0</direction><text>261A</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RSEXITLEFTNUM_SM&n=261A&d=]]></url></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_merge_left_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-9,33.523189,-86.826721,0,0|purple-10,33.52423,-86.807746,0,0|¢er=33.522014,-86.8172335&zoom=10&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1965438145&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>33.52423</lat><lng>-86.807746</lng></startPoint><maneuverNotes/><distance>3.204</distance><time>247</time><formattedTime>00:04:07</formattedTime><attributes>128</attributes><turnType>10</turnType><direction>8</direction><narrative>Merge onto US-280 E/US-31 S/ELTON B STEPHENS EXPY/AL-3 S via EXIT 126A.</narrative><directionName>East</directionName><index>8</index><streets><street>US HIGHWAY 280 E</street><street>US HIGHWAY 31 S</street><street>ELTON B STEPHENS EXPY</street><street>STATE ROUTE 3 S</street></streets><signs><sign><type>2</type><direction>8</direction><text>280</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00002BW_SM&n=280&d=EAST]]></url></sign><sign><type>2</type><direction>4</direction><text>31</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00002BW_SM&n=31&d=SOUTH]]></url></sign><sign><type>3</type><direction>4</direction><text>3</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00003BW_SM&n=3&d=SOUTH]]></url></sign><sign><type>1001</type><direction>0</direction><text>126A</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RSEXITRIGHTNUM_SM&n=126A&d=]]></url></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_merge_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-10,33.52423,-86.807746,0,0|purple-11,33.48822,-86.786872,0,0|¢er=33.506994,-86.797309&zoom=8&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1975826365&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>33.48822</lat><lng>-86.786872</lng></startPoint><maneuverNotes/><distance>101.94401</distance><time>6238</time><formattedTime>01:43:58</formattedTime><attributes>0</attributes><turnType>10</turnType><direction>8</direction><narrative>Merge onto US-280 E/AL-38 E toward SYLACAUGA/ZOO-GARDENS.</narrative><directionName>East</directionName><index>9</index><streets><street>US HIGHWAY 280 E</street><street>STATE ROUTE 38 E</street></streets><signs><sign><type>2</type><direction>8</direction><text>280</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00002BW_SM&n=280&d=EAST]]></url></sign><sign><type>3</type><direction>8</direction><text>38</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00003BW_SM&n=38&d=EAST]]></url></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_merge_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-11,33.48822,-86.786872,0,0|purple-12,32.6763,-85.486328,0,0|¢er=33.08226,-86.1366&zoom=4&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1975826365&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>32.6763</lat><lng>-85.486328</lng></startPoint><maneuverNotes/><distance>2.857</distance><time>214</time><formattedTime>00:03:34</formattedTime><attributes>0</attributes><turnType>2</turnType><direction>4</direction><narrative>Turn RIGHT onto AL-147.</narrative><directionName>South</directionName><index>10</index><streets><street>STATE ROUTE 147</street></streets><signs><sign><type>3</type><direction>0</direction><text>147</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00003BW_SM&n=147]]></url></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-12,32.6763,-85.486328,0,0|purple-13,32.637149,-85.481666,0,0|¢er=32.656724499999996,-85.48603750000001&zoom=8&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1975826365&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>32.637149</lat><lng>-85.481666</lng></startPoint><maneuverNotes/><distance>5.052</distance><time>386</time><formattedTime>00:06:26</formattedTime><attributes>0</attributes><turnType>1</turnType><direction>6</direction><narrative>Turn SLIGHT RIGHT onto AL-267/SHUG JORDAN PKWY.</narrative><directionName>Southwest</directionName><index>11</index><streets><street>STATE ROUTE 267</street><street>SHUG JORDAN PKWY</street></streets><signs><sign><type>3</type><direction>0</direction><text>267</text><extraText></extraText><url><![CDATA[http://api-signs.mqcdn.com/?s=rs&t=RS00003BW_SM&n=267]]></url></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_slight_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-13,32.637149,-85.481666,0,0|purple-14,32.57796,-85.498443,0,0|¢er=32.6075545,-85.49468949999999&zoom=7&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1975826365&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>32.57796</lat><lng>-85.498443</lng></startPoint><maneuverNotes/><distance>1.706</distance><time>155</time><formattedTime>00:02:35</formattedTime><attributes>0</attributes><turnType>1</turnType><direction>6</direction><narrative>Turn SLIGHT RIGHT onto S COLLEGE ST/AL-147. Continue to follow S COLLEGE ST.</narrative><directionName>Southwest</directionName><index>12</index><streets><street>S COLLEGE ST</street></streets><signs/><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_slight_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-14,32.57796,-85.498443,0,0|purple-15,32.55513,-85.508186,0,0|¢er=32.566545,-85.503116&zoom=8&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1975826365&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>32.55513</lat><lng>-85.508186</lng></startPoint><maneuverNotes/><distance>1.021</distance><time>129</time><formattedTime>00:02:09</formattedTime><attributes>0</attributes><turnType>6</turnType><direction>8</direction><narrative>Turn LEFT onto CR-863/SHELL TOOMER PKWY.</narrative><directionName>East</directionName><index>13</index><streets><street>COUNTY ROUTE 863</street><street>SHELL TOOMER PKWY</street></streets><signs><sign><type>4</type><direction>0</direction><text>863</text><extraText></extraText></sign></signs><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_left_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-15,32.55513,-85.508186,0,0|purple-16,32.55466,-85.490821,0,0|¢er=32.554824499999995,-85.4995035&zoom=10&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1975826365&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>32.55466</lat><lng>-85.490821</lng></startPoint><maneuverNotes/><distance>0.818</distance><time>130</time><formattedTime>00:02:10</formattedTime><attributes>0</attributes><turnType>6</turnType><direction>1</direction><narrative>Turn LEFT onto CANARY DR.</narrative><directionName>North</directionName><index>14</index><streets><street>CANARY DR</street></streets><signs/><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_left_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-16,32.55466,-85.490821,0,0|purple-17,32.566139,-85.489463,0,0|¢er=32.5603995,-85.49039400000001&zoom=9&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1975826365&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint><lat>32.566139</lat><lng>-85.489463</lng></startPoint><maneuverNotes/><distance>0.049</distance><time>7</time><formattedTime>00:00:07</formattedTime><attributes>0</attributes><turnType>2</turnType><direction>3</direction><narrative>Turn RIGHT to stay on CANARY DR.</narrative><directionName>Northeast</directionName><index>15</index><streets><street>CANARY DR</street></streets><signs/><iconUrl><![CDATA[http://content.mapquest.com/mqsite/turnsigns/rs_right_sm.gif]]></iconUrl><linkIds/><mapUrl><![CDATA[http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-17,32.566139,-85.489463,0,0|purple-18,32.566478,-85.488723,0,0|¢er=32.5663085,-85.489093&zoom=15&key=Dmjtd|luu725uyn5,2x=o5-5zb0d&rand=1975826365&session=4c6c8e89-019b-0001-02b7-4979-0024e83e3993]]></mapUrl></maneuver><maneuver><startPoint/><maneuverNotes/><distance>0.0</distance><time>0</time><formattedTime>00:00:00</formattedTime><attributes>0</attributes><turnType>-1</turnType><direction>0</direction><narrative>1963 CANARY DR is on the RIGHT.</narrative><directionName></directionName><index>16</index><streets/><signs/><linkIds/><mapUrl><![CDATA[]]></mapUrl></maneuver></maneuvers><hasTollRoad>false</hasTollRoad><hasFerry>false</hasFerry><hasHighway>true</hasHighway><hasSeasonalClosure>false</hasSeasonalClosure><hasUnpaved>false</hasUnpaved><hasCountryCross>false</hasCountryCross></leg></legs><hasTollRoad>false</hasTollRoad><hasFerry>false</hasFerry><hasHighway>true</hasHighway><hasSeasonalClosure>false</hasSeasonalClosure><hasUnpaved>false</hasUnpaved><hasCountryCross>false</hasCountryCross><locations><location><street>816 Meridian St</street><adminArea5 type="City">Nashville</adminArea5><adminArea3 type="State">TN</adminArea3><adminArea4 type="County">Davidson County</adminArea4><postalCode>37207-5850</postalCode><adminArea1 type="Country">US</adminArea1><geocodeQuality>POINT</geocodeQuality><geocodeQualityCode>P1AAA</geocodeQualityCode><dragPoint>false</dragPoint><sideOfStreet>L</sideOfStreet><displayLatLng><latLng><lat>36.185138</lat><lng>-86.76828</lng></latLng></displayLatLng><linkId>31393483</linkId><type>s</type><latLng><lat>36.18514</lat><lng>-86.76828</lng></latLng></location><location><street>1963 Canary Dr</street><adminArea5 type="City">Auburn</adminArea5><adminArea3 type="State">AL</adminArea3><adminArea4 type="County">Lee County</adminArea4><postalCode>36830-6901</postalCode><adminArea1 type="Country">US</adminArea1><geocodeQuality>POINT</geocodeQuality><geocodeQualityCode>P1AAA</geocodeQualityCode><dragPoint>false</dragPoint><sideOfStreet>R</sideOfStreet><displayLatLng><latLng><lat>32.566478</lat><lng>-85.488723</lng></latLng></displayLatLng><linkId>105113616</linkId><type>s</type><latLng><lat>32.56648</lat><lng>-85.48872</lng></latLng></location></locations><locationSequence>0,1</locationSequence></route></response>
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<response><info><statusCode>500</statusCode><messages><message>Server is not configured to authorize geocode requests from this client</message></messages><copyright><imageUrl>http://tile21.mqcdn.com/res/mqlogo.gif</imageUrl><imageAltText>© 2010 MapQuest, Inc.</imageAltText><text>© 2010 MapQuest, Inc.</text></copyright></info><collections/></response>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
context "Mapquest API" do
|
4
|
+
before(:all) do
|
5
|
+
@origin = "816 Meridian St., 37207"
|
6
|
+
@destination = "1963 Canary Dr., 36830"
|
7
|
+
end
|
8
|
+
|
9
|
+
context "API working" do
|
10
|
+
|
11
|
+
describe "directions work" do
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
MapQuestDirections.any_instance.stubs(:xml).returns(File.read("spec/lib/mapquest_directions.xml"))
|
15
|
+
@directions = MapQuestDirections.new(@origin, @destination)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return distance in miles" do
|
19
|
+
@directions.distance_in_miles.should == 310
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return drive time in minutes" do
|
23
|
+
@directions.drive_time_in_minutes.should == 303
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have a status code of 0" do
|
27
|
+
@directions.status.should == "0"
|
28
|
+
end
|
29
|
+
|
30
|
+
end #describe
|
31
|
+
end # API working
|
32
|
+
|
33
|
+
context "API not working" do
|
34
|
+
|
35
|
+
describe "Geocode distance estimation work" do
|
36
|
+
|
37
|
+
before(:each) do
|
38
|
+
MapQuestDirections.any_instance.stubs(:xml).returns(File.read("spec/lib/mapquest_directions_fail.xml"))
|
39
|
+
@directions = MapQuestDirections.new(@origin, @destination)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return distance in miles" do
|
43
|
+
@directions.distance_in_miles.should == 0
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return drive time in minutes" do
|
47
|
+
@directions.drive_time_in_minutes.should == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should have a status code other than 0" do
|
51
|
+
@directions.status.should_not == "0"
|
52
|
+
end
|
53
|
+
|
54
|
+
end #describe
|
55
|
+
end # API not working
|
56
|
+
|
57
|
+
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mocha'
|
3
|
+
require 'ruby-debug'
|
4
|
+
|
5
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
6
|
+
require 'mapquest_directions'
|
7
|
+
|
8
|
+
MAPQUEST_KEY = "replace_me"
|
9
|
+
# http://developer.mapquest.com/
|
10
|
+
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
config.mock_with :mocha
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mapquest_directions
|
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
|
+
- Josh Crews
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-19 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nokogiri
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 1
|
34
|
+
version: 1.4.1
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Ruby-wrapper for MapQuest Directions API. Can return the drive time and driving distance between two places
|
38
|
+
email: josh@joshcrews.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.textile
|
45
|
+
- lib/mapquest_directions.rb
|
46
|
+
files:
|
47
|
+
- README.textile
|
48
|
+
- Rakefile
|
49
|
+
- init.rb
|
50
|
+
- lib/mapquest_directions.rb
|
51
|
+
- spec/lib/mapquest_directions.xml
|
52
|
+
- spec/lib/mapquest_directions_fail.xml
|
53
|
+
- spec/lib/mapquest_directions_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- Manifest
|
56
|
+
- mapquest_directions.gemspec
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/joshcrews/MapQuest-Directions-Ruby
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --line-numbers
|
64
|
+
- --inline-source
|
65
|
+
- --title
|
66
|
+
- Mapquest_directions
|
67
|
+
- --main
|
68
|
+
- README.textile
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 11
|
86
|
+
segments:
|
87
|
+
- 1
|
88
|
+
- 2
|
89
|
+
version: "1.2"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project: mapquest_directions
|
93
|
+
rubygems_version: 1.3.7
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Ruby-wrapper for MapQuest Directions API. Can return the drive time and driving distance between two places
|
97
|
+
test_files: []
|
98
|
+
|