google_api_directions 0.0.2 → 0.0.3
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db184c0beee5f0f529627d2d1dfad547b4bb299c
|
4
|
+
data.tar.gz: 42663cccdbc6a6def14d58c7ad49a92a25732169
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34bc30fbc75423d2c9a1593cf74815ddc7682732e09ddcd0f3161b9f2fb53ef579e66302b6b88d30661549bfa6d022e6410a28c030f640f69f6a95d69bc72f3a
|
7
|
+
data.tar.gz: 46d3c6fea98290a45086aa21c2064ad9c08a37649c224a37da1dc10c3c189509cbacee61a440a07e44ed4b22ba71ca152659a0dd4fa934ec68237b7e1c986411
|
data/README.md
CHANGED
@@ -35,12 +35,21 @@ Lets get the directions. An array of string will be returned.
|
|
35
35
|
|
36
36
|
directions_array = result[:directions]
|
37
37
|
|
38
|
-
|
38
|
+
Print out the directions in steps.
|
39
39
|
|
40
|
+
directions_array.each do |step|
|
41
|
+
#Print out Ex. {Continue forward to the end of the road, 1 km, 2 minutes
|
42
|
+
puts step.route + ", " + step.distance + ", " step.duration
|
43
|
+
end
|
44
|
+
|
45
|
+
How about the distance information (in total)!? A string will be returned.
|
46
|
+
|
47
|
+
#Ex. 7 km
|
40
48
|
distance = result[:distance]
|
41
49
|
|
42
|
-
And the duration of time? A string will be returned.
|
50
|
+
And the duration of time (in total)? A string will be returned.
|
43
51
|
|
52
|
+
#Ex. 17 minutes
|
44
53
|
duration = result[:duration]
|
45
54
|
|
46
55
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'open-uri'
|
3
3
|
require 'json'
|
4
|
+
require_relative 'google_directions_route'
|
4
5
|
|
5
6
|
module GoogleApiDirections
|
6
7
|
|
7
8
|
class GoogleDirections
|
8
9
|
def initialize(apikey = "")
|
9
|
-
@apikey =
|
10
|
-
@apikey = "&key=" + apikey unless apikey.empty?
|
11
|
-
@uri = "http://maps.googleapis.com/maps/api/directions/json?origin="
|
10
|
+
@apikey = apikey
|
12
11
|
@directions = []
|
13
12
|
end
|
14
13
|
|
@@ -30,7 +29,10 @@ module GoogleApiDirections
|
|
30
29
|
|
31
30
|
result.each do |direction|
|
32
31
|
text = remove_html_tags(direction["html_instructions"])
|
33
|
-
|
32
|
+
route_distance = direction["distance"]["text"]
|
33
|
+
route_duration = direction["duration"]["text"]
|
34
|
+
|
35
|
+
@directions << GoogleApiDirections::GoogleDirectionsRoute.new(text.gsub(" ", " "), route_distance, route_duration)
|
34
36
|
end
|
35
37
|
|
36
38
|
{:directions => @directions, :distance => distance, :duration => duration}
|
@@ -42,6 +44,8 @@ module GoogleApiDirections
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def set_uri(origin, destination, language)
|
47
|
+
@apikey = "&key=" + @apikey unless @apikey.empty?
|
48
|
+
@uri = "http://maps.googleapis.com/maps/api/directions/json?origin="
|
45
49
|
@uri = @uri + URI::encode(origin) + "&destination=" + URI::encode(destination) + "&language=" + language + "&sensor=false" + @apikey
|
46
50
|
end
|
47
51
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module GoogleApiDirections
|
2
|
+
class GoogleDirectionsRoute
|
3
|
+
attr_accessor :route, :distance, :duration
|
4
|
+
|
5
|
+
def initialize(route, distance, duration)
|
6
|
+
@route = route
|
7
|
+
@distance = distance
|
8
|
+
@duration = duration
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
@route
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_api_directions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jone Samra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- google_api_directions.gemspec
|
68
68
|
- lib/google_api_directions.rb
|
69
69
|
- lib/google_api_directions/google_directions.rb
|
70
|
+
- lib/google_api_directions/google_directions_route.rb
|
70
71
|
- lib/google_api_directions/version.rb
|
71
72
|
- test/google_api_directions_test.rb
|
72
73
|
- test/test_helper.rb
|