<commit_before>require 'faraday'
require 'multi_json'
require 'echowrap/configurable'
require 'echowrap/api/artist'
require 'echowrap/api/playlist'
require 'echowrap/api/sandbox'
require 'echowrap/api/song'
require 'echowrap/api/oauth'
require 'echowrap/api/taste_profile'
require 'echowrap/api/track'
require 'simple_oauth'


module Echowrap
  class Client
    include Echowrap::API::Artist
    include Echowrap::API::Playlist
    include Echowrap::API::Sandbox
    include Echowrap::API::Song
    include Echowrap::API::Oauth
    include Echowrap::API::TasteProfile
    include Echowrap::API::Track
    include Echowrap::Configurable

    # Initializes a new Client object
    #
    # @param options [Hash]
    # @return [Echowrap::Client]
    def initialize(options={})
      Echowrap::Configurable.keys.each do |key|
        instance_variable_set(:"@#{key}", options[key] || Echowrap.instance_variable_get(:"@#{key}"))
      end
    end

    # Perform an HTTP GET request
    def get(path, params={})
      request(:get, path, params)
    end

    # Perform an HTTP POST request
    def post(path, params={})
      signature_params = params.values.any?{|value| value.respond_to?(:to_io)} ? {} : params
      request(:post, path, params, signature_params)
    end

    private

      def setup_authentication_parameters(method, path, params)
        params = params.merge(:api_key => @api_key)
        params = params.merge(oauth_parameters(method, path, params)) if params.delete(:oauth_request)
        params
      end

      def request(method, path, params={}, signature_params=params)
        params = setup_authentication_parameters(method, path, params)
        connection.send(method.to_sym, path, params).env
      rescue Faraday::Error::ClientError
        raise Echowrap::Error::ClientError
      rescue MultiJson::DecodeError
        raise Echowrap::Error::DecodeError
      end

      # Returns a Faraday::Connection object
      #
      # @return [Faraday::Connection]
      def connection
        @connection ||= begin
          connection_options = {:builder => @middleware}
          connection_options[:ssl] = {:verify => true} if @endpoint[0..4] == 'https'
          Faraday.new(@endpoint, @connection_options.merge(connection_options))
        end
      end

      def oauth_parameters(method, path, params={})
        uri = URI(@endpoint + path)
        SimpleOAuth::Header.new(method, uri, params, credentials).signed_attributes
      end

  end
end<commit_msg>adding oauth arg to ignore extra keys<commit_after>require 'faraday'
require 'multi_json'
require 'echowrap/configurable'
require 'echowrap/api/artist'
require 'echowrap/api/playlist'
require 'echowrap/api/sandbox'
require 'echowrap/api/song'
require 'echowrap/api/oauth'
require 'echowrap/api/taste_profile'
require 'echowrap/api/track'
require 'simple_oauth'


module Echowrap
  class Client
    include Echowrap::API::Artist
    include Echowrap::API::Playlist
    include Echowrap::API::Sandbox
    include Echowrap::API::Song
    include Echowrap::API::Oauth
    include Echowrap::API::TasteProfile
    include Echowrap::API::Track
    include Echowrap::Configurable

    # Initializes a new Client object
    #
    # @param options [Hash]
    # @return [Echowrap::Client]
    def initialize(options={})
      Echowrap::Configurable.keys.each do |key|
        instance_variable_set(:"@#{key}", options[key] || Echowrap.instance_variable_get(:"@#{key}"))
      end
    end

    # Perform an HTTP GET request
    def get(path, params={})
      request(:get, path, params)
    end

    # Perform an HTTP POST request
    def post(path, params={})
      signature_params = params.values.any?{|value| value.respond_to?(:to_io)} ? {} : params
      request(:post, path, params, signature_params)
    end

    private

      def setup_authentication_parameters(method, path, params)
        params = params.merge(:api_key => @api_key)
        params = params.merge(oauth_parameters(method, path, params)) if params.delete(:oauth_request)
        params
      end

      def request(method, path, params={}, signature_params=params)
        params = setup_authentication_parameters(method, path, params)
        connection.send(method.to_sym, path, params).env
      rescue Faraday::Error::ClientError
        raise Echowrap::Error::ClientError
      rescue MultiJson::DecodeError
        raise Echowrap::Error::DecodeError
      end

      # Returns a Faraday::Connection object
      #
      # @return [Faraday::Connection]
      def connection
        @connection ||= begin
          connection_options = {:builder => @middleware}
          connection_options[:ssl] = {:verify => true} if @endpoint[0..4] == 'https'
          Faraday.new(@endpoint, @connection_options.merge(connection_options))
        end
      end

      def oauth_parameters(method, path, params={})
        uri = URI(@endpoint + path)
        SimpleOAuth::Header.new(method, uri, params,
                                credentials.merge(ignore_extra_keys: true)).signed_attributes
      end

  end
end
{'fraction_non_alphanumeric': 0.11420667852203122, 'fraction_numerical': 0.0007903576368306659, 'mean_word_length': 3.390286209887251, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4295637', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1521, 'n_words': 336}