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.googleapis.com/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
-
#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 = .merge() @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
#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
40 41 42 |
# File 'lib/google_maps_api/directions/request.rb', line 40 def scheme [:https] ? "https" : "http" end |
#uri ⇒ Object
33 34 35 36 37 38 |
# File 'lib/google_maps_api/directions/request.rb', line 33 def uri uri = URI("#{scheme}://#{BASE_PATH}") query = .merge({origin: origin, destination: destination}) uri.query = URI.encode_www_form(query) uri end |