Class: GoogleMapsAPI::Directions::Request
- Inherits:
-
Object
- Object
- GoogleMapsAPI::Directions::Request
- Defined in:
- lib/google_maps_api/directions/request.rb
Constant Summary collapse
- BASE_PATH =
"/maps/api/directions/json"
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#http_adapter ⇒ Object
Returns the value of attribute http_adapter.
-
#options ⇒ Object
Returns the value of attribute options.
-
#origin ⇒ Object
Returns the value of attribute origin.
Class Method Summary collapse
Instance Method Summary collapse
- #business_account? ⇒ Boolean
-
#initialize(origin, destination, options = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
- #scheme ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(origin, destination, options = {}) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 15 |
# File 'lib/google_maps_api/directions/request.rb', line 8 def initialize(origin, destination, = {}) origin = origin.to_ary.join(",") if origin.respond_to?(:to_ary) destination = destination.to_ary.join(",") if destination.respond_to?(:to_ary) @origin = origin @destination = destination = @http_adapter = nil end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
6 7 8 |
# File 'lib/google_maps_api/directions/request.rb', line 6 def destination @destination end |
#http_adapter ⇒ Object
Returns the value of attribute http_adapter.
6 7 8 |
# File 'lib/google_maps_api/directions/request.rb', line 6 def http_adapter @http_adapter end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/google_maps_api/directions/request.rb', line 6 def end |
#origin ⇒ Object
Returns the value of attribute origin.
6 7 8 |
# File 'lib/google_maps_api/directions/request.rb', line 6 def origin @origin end |
Class Method Details
.build(origin, destination, options = {}) ⇒ Object
17 18 19 |
# File 'lib/google_maps_api/directions/request.rb', line 17 def self.build(origin, destination, = {}) self.new(origin, destination, ) end |
Instance Method Details
#business_account? ⇒ Boolean
59 60 61 |
# File 'lib/google_maps_api/directions/request.rb', line 59 def business_account? .key?(:key) && .key?(:client) end |
#perform ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/google_maps_api/directions/request.rb', line 21 def perform response = http_adapter.get_response(uri) if response.is_a?(Net::HTTPSuccess) return GoogleMapsAPI::Directions::Response.from_json(response.body) else msg = "The response was not successful (200). Call #response for datails." exception = GoogleMapsAPI::Directions::ResponseError.new(msg) exception.response = response raise exception end end |
#scheme ⇒ Object
51 52 53 |
# File 'lib/google_maps_api/directions/request.rb', line 51 def scheme [:https] ? "https" : "http" end |
#uri ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/google_maps_api/directions/request.rb', line 33 def uri base_host = GoogleMapsAPI::Core::BASE_HOST uri = "#{scheme}://#{base_host}#{BASE_PATH}" query_params = .merge( {origin: origin, destination: destination} ).reject { |key, value| [:client, :channel].include?(key) } if business_account? query_params = query_params.reject { |key, value| [:key].include?(key) } uri = "#{uri}?#{to_query(query_params)}" uri = sign_uri(uri) else uri = URI("#{uri}?#{URI.encode_www_form(query_params)}") end uri end |