michi/geocoder.rb
# Execute the Google Geocache API call, and return the raw result.
# TODO: refine the response such that it is just the geocode, not a JSON doc.
Execute the Google Geocache API call, and return the raw result.
TODO: refine the response such that it is just the geocode, not a JSON doc.
Execute the Google Geocache API call and return the raw result . TODO : refine the response such that it is just the geocode not a JSON doc .
def query_google(address)
    endpoint = @api_url.gsub('$ADDRESS', Geocoder.encode_address(address)).gsub('$API_KEY', @api_key)
    uri = URI(endpoint)
    Net::HTTP.start(uri.host, uri.port,
      :use_ssl => uri.scheme == 'https') do |http|
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      request = Net::HTTP::Get.new uri
      @log.info {"Looking up '#{address}' via '#{endpoint}'"}
      start_time = Time.now
      response = http.request(request)
      @log.info {"Response #{response.code} took #{((Time.now.to_f - start_time.to_f) * 1000).round} ms"}
      @log.debug {"Response was #{response.body.length} characters. Contents: #{response.body}"}
      return case response
      when Net::HTTPSuccess
        JSON.load(response.read_body)['results']
      else
        response
      end
    end
  end
def query_google ( address ) endpoint = @api_url . gsub ( '$ADDRESS' , Geocoder . encode_address ( address ) ) . gsub ( '$API_KEY' , @api_key ) uri = URI ( endpoint ) Net :: HTTP . start ( uri . host , uri . port , :use_ssl => uri . scheme == 'https' ) do | http | http . verify_mode = OpenSSL :: SSL :: VERIFY_NONE request = Net :: HTTP :: Get . new uri @log . info { "Looking up '#{address}' via '#{endpoint}'" } start_time = Time . now response = http . request ( request ) @log . info { "Response #{response.code} took #{((Time.now.to_f - start_time.to_f) * 1000).round} ms" } @log . debug { "Response was #{response.body.length} characters. Contents: #{response.body}" } return case response when Net :: HTTPSuccess JSON . load ( response . read_body ) [ 'results' ] else response end end end
Execute the Google Geocache API call, and return the raw result.
Execute the Google Geocache API call and return the raw result .
# Substitute in the requested address to encode, plus our Google API key for the geocoding webservice # Parse the requested JSON # Essentially, rethrow the error
address