<commit_before>require 'rest-client'
require 'active_support/core_ext'
require 'hashie'

module Goodreads
  module Request
    API_URL    = 'http://www.goodreads.com'
    API_FORMAT = 'xml'
    
    protected
    
    # Perform an API request
    #
    # path   - Request path
    # params - Parameters hash
    #
    def request(path, params={})
      if api_key.nil?
        raise Goodreads::ConfigurationError, 'API key required.'
      end
      
      params.merge!(:format => API_FORMAT, :key => api_key)
      url = "#{API_URL}#{path}"
      
      resp = RestClient.get(url, :params => params) do |response, request, result, &block|
        case response.code
          when 200
            response.return!(request, result, &block)
          when 401
            raise Goodreads::Unauthorized
          when 404
            raise Goodreads::NotFound
        end
      end<commit_msg>Try to use global config<commit_after>require 'rest-client'
require 'active_support/core_ext'
require 'hashie'

module Goodreads
  module Request
    API_URL    = 'http://www.goodreads.com'
    API_FORMAT = 'xml'
    
    protected
    
    # Perform an API request
    #
    # path   - Request path
    # params - Parameters hash
    #
    def request(path, params={})
      token = api_key || Goodreads.configuration[:api_key]
      
      if token.nil?
        raise Goodreads::ConfigurationError, 'API key required.'
      end
      
      params.merge!(:format => API_FORMAT, :key => token)
      url = "#{API_URL}#{path}"
      
      resp = RestClient.get(url, :params => params) do |response, request, result, &block|
        case response.code
          when 200
            response.return!(request, result, &block)
          when 401
            raise Goodreads::Unauthorized
          when 404
            raise Goodreads::NotFound
        end
      end
{'fraction_non_alphanumeric': 0.0996230479267636, 'fraction_numerical': 0.009693053311793215, 'mean_word_length': 2.086378737541528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '7024395', 'n_tokens_mistral': 557, 'n_tokens_neox': 529, 'n_words': 142}