<commit_before>module Traxo

  class Client
    attr_accessor :access_token
    attr_reader :response_format, :raise_http_errors

    API_URL = "https://api.traxo.com/v2/"

    def initialize(access_token, client_id, client_secret, options = {})
      @access_token = access_token
      @client_secret = client_secret
      @client_id = client_id
      assign_options(options)
    end

    def return_body!
      @response_format = :body
    end

    def return_body_string!
      @response_format = :body_string
    end

    def return_headers!
      @response_format = :headers
    end

    def return_headers_string!
      @response_format = :headers_string
    end

    def return_code!
      @response_format = :code
    end

    def return_http_object!
      @response_format = :http
    end

    def ignore_http_errors!
      @raise_http_errors = false
    end

    def raise_http_errors!
      @raise_http_errors = true
    end

      private

    def assign_options(options)
      assign_response_format(options[:response_format])
      assign_error_handling(options[:errors])
    end

    def assign_response_format(format)
      if format
        accepted = [:body, :body_string, :headers, :headers_string, :code, :http]
        if accepted.include? format
          @response_format = format
        else
          str = accepted.join(', :').insert(0, ':')
          raise ArgumentError.new(":response_format must be one of the following: #{str}")
        end
      else
        return_body!
      end
    end

    def assign_error_handling(action)
      if action
        if [:raise, :ignore].include? action
          raise_http_errors! if action == :raise
          ignore_http_errors! if action == :ignore
        else
          raise ArgumentError.new(':errors parameter must be either :raise or :ignore')<commit_msg>Returning object from formatting/error-handling methods<commit_after>module Traxo

  class Client
    attr_accessor :access_token
    attr_reader :response_format, :raise_http_errors

    API_URL = "https://api.traxo.com/v2/"

    def initialize(access_token, client_id, client_secret, options = {})
      @access_token = access_token
      @client_secret = client_secret
      @client_id = client_id
      assign_options(options)
    end

    def return_body!
      @response_format = :body
      self
    end

    def return_body_string!
      @response_format = :body_string
      self
    end

    def return_headers!
      @response_format = :headers
      self
    end

    def return_headers_string!
      @response_format = :headers_string
      self
    end

    def return_code!
      @response_format = :code
      self
    end

    def return_http_object!
      @response_format = :http
      self
    end

    def ignore_http_errors!
      @raise_http_errors = false
      self
    end

    def raise_http_errors!
      @raise_http_errors = true
      self
    end

      private

    def assign_options(options)
      assign_response_format(options[:response_format])
      assign_error_handling(options[:errors])
    end

    def assign_response_format(format)
      if format
        accepted = [:body, :body_string, :headers, :headers_string, :code, :http]
        if accepted.include? format
          @response_format = format
        else
          str = accepted.join(', :').insert(0, ':')
          raise ArgumentError.new(":response_format must be one of the following: #{str}")
        end
      else
        return_body!
      end
    end

    def assign_error_handling(action)
      if action
        if [:raise, :ignore].include? action
          raise_http_errors! if action == :raise
          ignore_http_errors! if action == :ignore
        else
          raise ArgumentError.new(':errors parameter must be either :raise or :ignore')
{'fraction_non_alphanumeric': 0.07740916271721959, 'fraction_numerical': 0.00105318588730911, 'mean_word_length': 2.4949402023919043, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '4359242', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1093, 'n_words': 271}