Class: GmapsDirections::API
- Inherits:
-
Object
- Object
- GmapsDirections::API
- Defined in:
- lib/gmaps_directions.rb
Constant Summary collapse
- DIRECTIONS_API_BASE_URL =
"http://maps.googleapis.com/maps/api/directions/json"
Instance Attribute Summary collapse
-
#end_address ⇒ Object
readonly
Returns the value of attribute end_address.
-
#parsed_directions_response ⇒ Object
readonly
Returns the value of attribute parsed_directions_response.
-
#start_address ⇒ Object
readonly
Returns the value of attribute start_address.
Class Method Summary collapse
Instance Method Summary collapse
- #call_google ⇒ Object
-
#initialize(attributes) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(attributes) ⇒ API
Returns a new instance of API.
51 52 53 54 |
# File 'lib/gmaps_directions.rb', line 51 def initialize(attributes) @start_address = attributes[:start_address] @end_address = attributes[:end_address] end |
Instance Attribute Details
#end_address ⇒ Object (readonly)
Returns the value of attribute end_address.
49 50 51 |
# File 'lib/gmaps_directions.rb', line 49 def end_address @end_address end |
#parsed_directions_response ⇒ Object (readonly)
Returns the value of attribute parsed_directions_response.
49 50 51 |
# File 'lib/gmaps_directions.rb', line 49 def parsed_directions_response @parsed_directions_response end |
#start_address ⇒ Object (readonly)
Returns the value of attribute start_address.
49 50 51 |
# File 'lib/gmaps_directions.rb', line 49 def start_address @start_address end |
Class Method Details
.find_directions(options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gmaps_directions.rb', line 34 def find_directions( = {}) api_driver = new(:start_address => [:from], :end_address => [:to]) api_driver.call_google if api_driver.parsed_directions_response.present? && api_driver.parsed_directions_response["routes"].present? return api_driver.parsed_directions_response["routes"].inject([]) do |routes, route_hash| routes << Route.new(route_hash, api_driver.parsed_directions_response["status"]) end else return [] end end |
Instance Method Details
#call_google ⇒ Object
56 57 58 59 |
# File 'lib/gmaps_directions.rb', line 56 def call_google response = Net::HTTP.get_response(directions_api_url).body @parsed_directions_response = Yajl::Parser.parse(response) end |