<commit_before>module Songdrop
  class Client
    attr_accessor :auth_token

    def initialize(options={})
      @token = options[:token]
      @endpoint = options[:endpoint] || 'https://songdrop.com/v1'
      @auth_token = options[:auth_token]
    end

    def get(path, params={}, &block)
      puts "[Songdrop::Client] GET #{path} with #{params.inspect} block? #{block_given?}"
      params.merge!(:client => @token, :token => @auth_token)
      HTTP.get(full_url(path), params) do |response, headers, error|
        handle_response(response, headers, error, &block)
      end
    end

    def put(path, params={}, &block)
      puts "[Songdrop::Client] PUT #{path} with #{params.inspect} block? #{block_given?}"
      params.merge!(:client => @token, :token => @auth_token)
      HTTP.put(full_url(path), params) do |response, headers, error|
        handle_response(response, headers, error, &block)
      end
    end

    def post(path, params={}, &block)
      puts "[Songdrop::Client] POST #{path} with #{params.inspect} block? #{block_given?}"
      params.merge!(:client => @token, :token => @auth_token)
      HTTP.post(full_url(path), params) do |response, headers, error|
        handle_response(response, headers, error, &block)
      end
    end

    def delete(path, params={}, &block)
      puts "[Songdrop::Client] DELETE #{path} with #{params.inspect} block? #{block_given?}"
      params.merge!(:client => @token, :token => @auth_token)
      HTTP.delete(full_url(path), params) do |response, headers, error|
        handle_response(response, headers, error, &block)
      end
    end

    private
      def full_url(path)
        "#{@endpoint}#{path}"
      end

      def handle_response(response, headers, error, &block)
        target = response || error
        res = nil
        JSON.parse(target) do |obj|
          res = Parser.parse(obj, headers)
          res = res.first if res.is_a? Array and res.size == 1
          block.call res if block
          res
        end
        res
      end<commit_msg>returning an array if that was returned<commit_after>module Songdrop
  class Client
    attr_accessor :auth_token

    def initialize(options={})
      @token = options[:token]
      @endpoint = options[:endpoint] || 'https://songdrop.com/v1'
      @auth_token = options[:auth_token]
    end

    def get(path, params={}, &block)
      puts "[Songdrop::Client] GET #{path} with #{params.inspect} block? #{block_given?}"
      params.merge!(:client => @token, :token => @auth_token)
      HTTP.get(full_url(path), params) do |response, headers, error|
        handle_response(response, headers, error, &block)
      end
    end

    def put(path, params={}, &block)
      puts "[Songdrop::Client] PUT #{path} with #{params.inspect} block? #{block_given?}"
      params.merge!(:client => @token, :token => @auth_token)
      HTTP.put(full_url(path), params) do |response, headers, error|
        handle_response(response, headers, error, &block)
      end
    end

    def post(path, params={}, &block)
      puts "[Songdrop::Client] POST #{path} with #{params.inspect} block? #{block_given?}"
      params.merge!(:client => @token, :token => @auth_token)
      HTTP.post(full_url(path), params) do |response, headers, error|
        handle_response(response, headers, error, &block)
      end
    end

    def delete(path, params={}, &block)
      puts "[Songdrop::Client] DELETE #{path} with #{params.inspect} block? #{block_given?}"
      params.merge!(:client => @token, :token => @auth_token)
      HTTP.delete(full_url(path), params) do |response, headers, error|
        handle_response(response, headers, error, &block)
      end
    end

    private
      def full_url(path)
        "#{@endpoint}#{path}"
      end

      def handle_response(response, headers, error, &block)
        target = response || error
        res = nil
        JSON.parse(target) do |obj|
          res = Parser.parse(obj, headers)
          block.call res if block
          res
        end
        res
      end
{'fraction_non_alphanumeric': 0.14321171506577315, 'fraction_numerical': 0.0007446016381236039, 'mean_word_length': 2.943248532289628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '3357101', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1230, 'n_words': 327}