<commit_before># encoding: utf-8
require 'logger'

module GmapsGeocoding
  # Google Maps Geocoding Service abstraction class
  #
  # @example
  #  opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
  #  api = GmapsGeocoding::Api.new(opts)
  #
  class Api
    attr_reader :config

    def initialize(opts = {})
      @logger = opts.delete(:logger)||Logger.new(STDERR) do |l|
        l.progname = 'gmaps_geocoding'
        l.level = $DEBUG ? Logger::DEBUG : Logger::INFO
      end
      @config = GmapsGeocoding::Config.new(opts)
    end

    # Return a Ruby Hash object of the Google Maps Geocoding Service response
    #
    # {https://developers.google.com/maps/documentation/geocoding/ Google Maps Geocoding Service documentation}.
    #
    # @example
    #  # json output example
    #  opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
    #  api = GmapsGeocoding::Api.new(opts)
    #  result = api.get_location
    #  # xml output example
    #  opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'xml'}
    #  api = GmapsGeocoding::Api.new(opts)
    #  result = api.get_location
    #
    def get_location
      begin
        if @config.valid?
          rest_client = retrieve_geocoding_data
          result = case @config.is_json_format?
                   when true
                     GmapsGeocoding.from_json(rest_client.to_s)
                   else
                     GmapsGeocoding.from_xml(rest_client.to_s)
                   end
          return result
        end
      rescue => e
        @logger.debug "[error: gmaps_geocoding]: #{e}"
      end
      nil
    end

    # Get the best latlng for an address based on Google Maps Geocoder "location_type"
    #
    # location_type stores additional data about the specified location. The following values are currently supported:<commit_msg>Fix error log level.<commit_after># encoding: utf-8
require 'logger'

module GmapsGeocoding
  # Google Maps Geocoding Service abstraction class
  #
  # @example
  #  opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
  #  api = GmapsGeocoding::Api.new(opts)
  #
  class Api
    attr_reader :config

    def initialize(opts = {})
      @logger = opts.delete(:logger)||Logger.new(STDERR) do |l|
        l.progname = 'gmaps_geocoding'
        l.level = $DEBUG ? Logger::DEBUG : Logger::INFO
      end
      @config = GmapsGeocoding::Config.new(opts)
    end

    # Return a Ruby Hash object of the Google Maps Geocoding Service response
    #
    # {https://developers.google.com/maps/documentation/geocoding/ Google Maps Geocoding Service documentation}.
    #
    # @example
    #  # json output example
    #  opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
    #  api = GmapsGeocoding::Api.new(opts)
    #  result = api.get_location
    #  # xml output example
    #  opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'xml'}
    #  api = GmapsGeocoding::Api.new(opts)
    #  result = api.get_location
    #
    def get_location
      begin
        if @config.valid?
          rest_client = retrieve_geocoding_data
          result = case @config.is_json_format?
                   when true
                     GmapsGeocoding.from_json(rest_client.to_s)
                   else
                     GmapsGeocoding.from_xml(rest_client.to_s)
                   end
          return result
        end
      rescue => e
        @logger.error e.to_s
      end
      nil
    end

    # Get the best latlng for an address based on Google Maps Geocoder "location_type"
    #
    # location_type stores additional data about the specified location. The following values are currently supported:
{'fraction_non_alphanumeric': 0.09563803847195881, 'fraction_numerical': 0.000541858574911948, 'mean_word_length': 2.3502722323049, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '486677', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1121, 'n_words': 302}