Sha256: 89dc33b597aee193b841834c7f221c83c48fe5f434efbe1286db17d3185ae8d5

Contents?: true

Size: 1007 Bytes

Versions: 5

Compression:

Stored size: 1007 Bytes

Contents

require 'http'

module Google
  # Service for all Google API calls
  class GoogleApi
    #Setting the URL and parameters
    Google_URL = 'https://maps.googleapis.com/maps/api/'
    Search_Type = 'distancematrix'
    Return_Type = 'json'
    Google_API_URL = URI.join(Google_URL, "#{Search_Type}/", "#{Return_Type}")
    #Search_URL = URI.join(Google_API_URL, "#{Parms}")
    attr_reader :google_data

    def self.config=(credentials)
      @config ? @config.update(credentials) : @config = credentials
    end

    def self.config
      return @config if @config
      @config = { googlemap_id: ENV['GOOGLE_API'] }
    end

    def self.distanceInfo(origins, dest, mode)
      return @distance if @distance
      distanceDetail = HTTP.get(Google_API_URL,
        params:
        {
          key: config['googlemap_id'],
          origins: origins,
          destinations: dest,
          mode: mode
        })
      distance_data = JSON.load(distanceDetail.to_s)['rows'][0]['elements']
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
VIAJERO-0.1.74 lib/VIAJERO/google_api.rb
VIAJERO-0.1.73 lib/VIAJERO/google_api.rb
Time_Traveler-0.1.72 lib/Time_Traveler/google_api.rb
Time_Traveler-0.1.71 lib/Time_Traveler/google_api.rb
Time_Traveler-0.1.70 lib/Time_Traveler/google_api.rb