<commit_before>require "walmart_open/config"
require "walmart_open/connection_manager"
require "walmart_open/requests/search"
require "walmart_open/requests/lookup"
require "walmart_open/requests/taxonomy"
require "walmart_open/requests/token"
require "walmart_open/requests/order"

module WalmartOpen
  class Client
    attr_reader :connection
    attr_reader :config

    def initialize(config_attrs = {})
      @config = Config.new(config_attrs)
      @connection = ConnectionManager.new(self)

      @auth_token = <PASSWORD>

      yield config if block_given?
    end

    def search(query, params = {})
      connection.request(Requests::Search.new(query, params))
    end

    def lookup(item_id, params = {})
      connection.request(Requests::Lookup.new(item_id, params))
    end

    def taxonomy
      connection.request(Requests::Taxonomy.new)
    end

    def order(item_id)
      if !@auth_token|| @auth_token.expired?
        @auth_token = connection.request(Requests::Token.new)
      end

      #connection.request(Requests::Order.new(item_id, @auth_token))
    end
  end
end
<commit_msg>Move authentication into its own method<commit_after>require "walmart_open/config"
require "walmart_open/connection_manager"
require "walmart_open/requests/search"
require "walmart_open/requests/lookup"
require "walmart_open/requests/taxonomy"
require "walmart_open/requests/token"
require "walmart_open/requests/order"

module WalmartOpen
  class Client
    attr_reader :connection
    attr_reader :config
    attr_reader :auth_token

    def initialize(config_attrs = {})
      @config = Config.new(config_attrs)
      @connection = ConnectionManager.new(self)

      yield config if block_given?
    end

    def search(query, params = {})
      connection.request(Requests::Search.new(query, params))
    end

    def lookup(item_id, params = {})
      connection.request(Requests::Lookup.new(item_id, params))
    end

    def taxonomy
      connection.request(Requests::Taxonomy.new)
    end

    def order(item_id)
      authenticate!

      #connection.request(Requests::Order.new(item_id, @auth_token))
    end

    private

    def authenticate!
      if !@auth_token || @auth_token.expired?
        @auth_token = connection.request(Requests::Token.new)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09969525468001741, 'fraction_numerical': 0.0, 'mean_word_length': 3.7479338842975207, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '6582027', 'n_tokens_mistral': 706, 'n_tokens_neox': 698, 'n_words': 138}