<commit_before>require 'restclient'

module JustDial
  class Search
    def initialize(url, auth_tokens={})
      @url = url
      @auth_tokens = auth_tokens
    end

    def execute(params={})
      valid_params = params.select { |key| [:query, :city, :area].include?(key) } # TODO: Implement Hash.slice
      latitude = params[:latitude]
      longitude = params[:longitude]
      geolocation_params = {}
      geolocation_params[:geolocation] = "#{latitude},#{longitude}" if !latitude.nil? && !longitude.nil?
      page_size = params[:num_res] || 100
      request_params = @auth_tokens.merge(valid_params).merge(geolocation_params).merge({:num_res => page_size})
      RestClient.get(@url, {:params => request_params}) { |response, request, result, &block|
        case response.code
          when 200
            Provider.parse(response.to_s)<commit_msg>Log request/response to stdout for debugging on local and Heroku<commit_after>require 'restclient'

module JustDial
  class Search
    def initialize(url, auth_tokens={})
      @url = url
      @auth_tokens = auth_tokens
    end

    def execute(params={})
      valid_params = params.select { |key| [:query, :city, :area].include?(key) } # TODO: Implement Hash.slice
      latitude = params[:latitude]
      longitude = params[:longitude]
      geolocation_params = {}
      geolocation_params[:geolocation] = "#{latitude},#{longitude}" if !latitude.nil? && !longitude.nil?
      page_size = params[:num_res] || 100
      request_params = @auth_tokens.merge(valid_params).merge(geolocation_params).merge({:num_res => page_size})
      puts "Request: #{@url}/#{request_params.to_param}"

      RestClient.get(@url, {:params => request_params}) { |response, request, result, &block|
        puts "Response: #{response.code}, #{response.to_s}"

        case response.code
          when 200
            Provider.parse(response.to_s)
{'fraction_non_alphanumeric': 0.13597883597883598, 'fraction_numerical': 0.006349206349206349, 'mean_word_length': 3.5676328502415457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1320899', 'n_tokens_mistral': 594, 'n_tokens_neox': 580, 'n_words': 121}