Class: Bscf::Core::GebetaMapsService
- Inherits:
-
Object
- Object
- Bscf::Core::GebetaMapsService
- Includes:
- HTTParty
- Defined in:
- app/services/bscf/core/gebeta_maps_service.rb
Instance Method Summary collapse
-
#initialize ⇒ GebetaMapsService
constructor
A new instance of GebetaMapsService.
- #optimize_route(origin_address, destination_addresses) ⇒ Object
Constructor Details
#initialize ⇒ GebetaMapsService
Returns a new instance of GebetaMapsService.
9 10 11 |
# File 'app/services/bscf/core/gebeta_maps_service.rb', line 9 def initialize @api_key = Rails.application.credentials.gebeta_api_key || ENV["GEBETA_API_KEY"] end |
Instance Method Details
#optimize_route(origin_address, destination_addresses) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/bscf/core/gebeta_maps_service.rb', line 13 def optimize_route(origin_address, destination_addresses) return {} if destination_addresses.empty? origin = origin_address.coordinates destinations = destination_addresses.map(&:coordinates).compact return {} if origin.nil? || destinations.empty? origin_str = "{#{origin[0]},#{origin[1]}}" destinations_str = destinations.map { |lat, lon| "{#{lat},#{lon}}" }.join(",") json_param = "[#{destinations_str}]" url = "https://mapapi.gebeta.app/api/route/onm?origin=#{origin_str}&json=#{json_param}&apiKey=#{@api_key}" response = HTTParty.get(url) handle_response(response) end |