google_maps_api-directions 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5ab55ac8c65193c48ef84b188aad24fb9cc4339
4
- data.tar.gz: 64ea3b0da7201bd113dbf9ded5c00150ae22c632
3
+ metadata.gz: 2976224fb7deea7c716d1fc5375a0060c412bb74
4
+ data.tar.gz: 283d8b097f315c74ac6d6ea9a71832dd6bef1234
5
5
  SHA512:
6
- metadata.gz: b946bac2ceb2942a92fcb229dcac1e0ba070434ed4d04f37adab6427d5e204626b8d3050ed0aee38d6175f01b32a844684f05f21eee0f5eaa8bb4564da188585
7
- data.tar.gz: d1955b2f858213d5665d90dccc8a903a49415934ce19544fbcd3c536b87ff0ec4050fb01dae526c0849db39ad8d3f8e546a57e4ebc6675ef5ad9c48862298dad
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
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rake"
22
22
  spec.add_development_dependency "rspec", ">= 3.0.0.beta2", "< 4"
23
23
 
24
- spec.add_dependency "google_maps_api-core", "~> 0"
24
+ spec.add_dependency "google_maps_api-core", "~> 0.2"
25
25
  end
@@ -1,7 +1,7 @@
1
1
  require "net/http"
2
2
 
3
3
  class GoogleMapsAPI::Directions::Request
4
- BASE_PATH = "maps.googleapis.com/maps/api/directions/json"
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 = default_options.merge(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
- uri = URI("#{scheme}://#{BASE_PATH}")
35
- query = prepared_options.merge({origin: origin, destination: destination})
36
- uri.query = URI.encode_www_form(query)
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.dup
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
@@ -1,5 +1,5 @@
1
1
  module GoogleMapsAPI
2
2
  module Directions
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1.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-14 00:00:00.000000000 Z
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