google_maps_api-directions 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/google_maps_api-directions.gemspec +1 -1
- data/lib/google_maps_api/directions/request.rb +41 -6
- data/lib/google_maps_api/directions/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2976224fb7deea7c716d1fc5375a0060c412bb74
|
4
|
+
data.tar.gz: 283d8b097f315c74ac6d6ea9a71832dd6bef1234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 775b60444e7b7456a6cca02d5cbf7102ef0caf7f9d0b036a34e326df40cc0819afe54bb1afb8b2d0b5fdadd81bb2367a00e79a54bf232ce00b0bf530cdb11672
|
7
|
+
data.tar.gz: 3123f9f401259bb8985daaaaab7596d30d6bef7ada95c1ed6fe008072f436beb732ed8872c2c97660df12ffea4f18fa8de21f40e5e6b6e866565e9723d3a044a
|
data/README.md
CHANGED
@@ -25,6 +25,8 @@ GoogleMapsAPI::Directions.route(origin, destination, options = {})
|
|
25
25
|
Origin and destination can be an a string or anything that supports ```to_ary```.
|
26
26
|
Options is a *Symbols* Hash with optional parameters. (See https://developers.google.com/maps/documentation/directions/#RequestParameters for more information).
|
27
27
|
|
28
|
+
For Google Business/Enterprise requests, include the ```:key```, ```:client``` and optionally, ```:channel``` in the options hash.
|
29
|
+
|
28
30
|
### Examples:
|
29
31
|
|
30
32
|
```ruby
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "net/http"
|
2
2
|
|
3
3
|
class GoogleMapsAPI::Directions::Request
|
4
|
-
BASE_PATH = "
|
4
|
+
BASE_PATH = "/maps/api/directions/json"
|
5
5
|
|
6
6
|
attr_accessor :origin, :destination, :options, :http_adapter
|
7
7
|
|
@@ -10,7 +10,7 @@ class GoogleMapsAPI::Directions::Request
|
|
10
10
|
destination = destination.to_ary.join(",") if destination.respond_to?(:to_ary)
|
11
11
|
@origin = origin
|
12
12
|
@destination = destination
|
13
|
-
@options =
|
13
|
+
@options = options
|
14
14
|
@http_adapter = nil
|
15
15
|
end
|
16
16
|
|
@@ -31,9 +31,20 @@ class GoogleMapsAPI::Directions::Request
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def uri
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
base_host = GoogleMapsAPI::Core::BASE_HOST
|
35
|
+
uri = "#{scheme}://#{base_host}#{BASE_PATH}"
|
36
|
+
query_params = prepared_options.merge(
|
37
|
+
{origin: origin, destination: destination}
|
38
|
+
).reject { |key, value| [:client, :channel].include?(key) }
|
39
|
+
|
40
|
+
if business_account?
|
41
|
+
query_params = query_params.reject { |key, value| [:key].include?(key) }
|
42
|
+
uri = "#{uri}?#{to_query(query_params)}"
|
43
|
+
uri = sign_uri(uri)
|
44
|
+
else
|
45
|
+
uri = URI("#{uri}?#{URI.encode_www_form(query_params)}")
|
46
|
+
end
|
47
|
+
|
37
48
|
uri
|
38
49
|
end
|
39
50
|
|
@@ -45,6 +56,10 @@ class GoogleMapsAPI::Directions::Request
|
|
45
56
|
@http_adapter || Net::HTTP
|
46
57
|
end
|
47
58
|
|
59
|
+
def business_account?
|
60
|
+
options.key?(:key) && options.key?(:client)
|
61
|
+
end
|
62
|
+
|
48
63
|
private
|
49
64
|
|
50
65
|
def default_options
|
@@ -58,7 +73,13 @@ class GoogleMapsAPI::Directions::Request
|
|
58
73
|
end
|
59
74
|
|
60
75
|
def prepared_options
|
61
|
-
options = self.options
|
76
|
+
options = default_options.merge(self.options)
|
77
|
+
|
78
|
+
# Symbolizes the options keys
|
79
|
+
options.keys.each do |key|
|
80
|
+
options[(key.to_sym rescue key) || key] = options.delete(key)
|
81
|
+
end
|
82
|
+
|
62
83
|
options[:departure_time] = time_or_date_to_unix(options[:departure_time])
|
63
84
|
options[:arrival_time] = time_or_date_to_unix(options[:arrival_time])
|
64
85
|
|
@@ -79,4 +100,18 @@ class GoogleMapsAPI::Directions::Request
|
|
79
100
|
return time_or_date.to_time.to_i if time_or_date.is_a?(Date)
|
80
101
|
time_or_date
|
81
102
|
end
|
103
|
+
|
104
|
+
def sign_uri(uri)
|
105
|
+
options = prepared_options
|
106
|
+
GoogleMapsAPI::Core::URISigner.sign(
|
107
|
+
uri.to_s,
|
108
|
+
options[:client],
|
109
|
+
options[:key],
|
110
|
+
options[:channel]
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def to_query(hash)
|
115
|
+
hash.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
|
116
|
+
end
|
82
117
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_maps_api-directions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Zavan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,14 +64,14 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
67
|
+
version: '0.2'
|
68
68
|
type: :runtime
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
74
|
+
version: '0.2'
|
75
75
|
description:
|
76
76
|
email:
|
77
77
|
- zavan@outlook.com
|