My goal: http://maps.googleapis.com/maps/api/directions/json?origin=montreal&destination=toronto&sensor=false
My class:
class GoogleMap
include HTTParty
base_uri 'http://maps.googleapis.com'
attr_accessor :origin, :destination
def initialize(service, page)
@options = { query: {origin: origin, destination: destination} }
end
def directions
self.class.get("/maps/api/directions/json", @options)
end
end
Currently when I run this on the console:
irb(main):001:0> g = GoogleMap.new("montreal", "toronto")
=> #<GoogleMap:0x007fcaeeb88538 @options={:query=>{:origin=>nil, :destination=>nil}}>
irb(main):002:0> g.directions
=> #<HTTParty::Response:0x7fcaeeb60b00 parsed_response={"error_message"=>"Invalid request. Missing the 'origin' parameter.", "routes"=>[]...
Problem is: {:query=>{:origin=>nil, :destination=>nil}}
origin and destination are nil.
I would like to know how I would achieve:
irb(main):001:0> g = GoogleMap.new("montreal", "toronto")
=> #<GoogleMap:0x007fcaeeb88538 @options={:query=>{:origin=>montreal, :destination=>toronto}}
And then when I run:
g.directions
I get output of http://maps.googleapis.com/maps/api/directions/json?origin=montreal&destination=toronto&sensor=false
Thank you in advance.