<commit_before>module Geezeo
  module Adapters
    class Transactions
      attr_reader :credentials

      def initialize(credentials)
        @credentials = credentials
      end

      def path(account, page)
        "/accounts/#{account.id}/transactions?page=#{page}"
      end 

      def all
        accounts = Geezeo::Adapters::Accounts.new(credentials).all
        transactions = accounts.map{|account| find_all(account)}.flatten

        sort_by_posted_at(transactions)
      end

      def find_all(account, transaction_id="")
        pages = total_pages(account)
        results = []

        pages.times do |page|
          find(account, page+1).each do |transaction|
            if transaction["id"] == transaction_id
              return results.compact
            else
              results << transaction
            end
          end
        end

        results.compact
      end

      def find(account, page=1)
        account = Geezeo::Adapters::Accounts.new(credentials).all.find(account) if account.is_a?(Integer)
        response = request(account, page)

        if response["transactions"]
          results = response["transactions"].map do |transaction|
            Geezeo::Transaction.new(transaction["transaction"])
          end
        else
          results = []
        end

        results.compact
      end

      def posted_at(transaction)
        Time.parse(transaction.posted_at) rescue Time.new(0)
      end

      def recent
        accounts = Geezeo::Adapters::Accounts.new(credentials).all
        transactions = accounts.map{|account| find(account)}.flatten

        sort_by_posted_at(transactions)
      end

      def request(account, page=1)
        uri = "#{HOST}/users/#{credentials.user_id}/#{path(account, page)}"
        HTTParty.get(uri, basic_auth:
                            {username: credentials.api_key, password: ""})<commit_msg>Accept account id or object II: Wrath of Khan<commit_after>module Geezeo
  module Adapters
    class Transactions
      attr_reader :credentials

      def initialize(credentials)
        @credentials = credentials
      end

      def path(account, page)
        "/accounts/#{account.id}/transactions?page=#{page}"
      end 

      def all
        accounts = Geezeo::Adapters::Accounts.new(credentials).all
        transactions = accounts.map{|account| find_all(account)}.flatten

        sort_by_posted_at(transactions)
      end

      def find_all(account, transaction_id="")
        pages = total_pages(account)
        results = []

        pages.times do |page|
          find(account, page+1).each do |transaction|
            if transaction["id"] == transaction_id
              return results.compact
            else
              results << transaction
            end
          end
        end

        results.compact
      end

      def find(account_id, page=1)
        account = account_id.is_a?(Integer) ? Geezeo::Adapters::Accounts.new(credentials).all.find(account_id) : account_id

        response = request(account, page)

        if response["transactions"]
          results = response["transactions"].map do |transaction|
            Geezeo::Transaction.new(transaction["transaction"])
          end
        else
          results = []
        end

        results.compact
      end

      def posted_at(transaction)
        Time.parse(transaction.posted_at) rescue Time.new(0)
      end

      def recent
        accounts = Geezeo::Adapters::Accounts.new(credentials).all
        transactions = accounts.map{|account| find(account)}.flatten

        sort_by_posted_at(transactions)
      end

      def request(account, page=1)
        uri = "#{HOST}/users/#{credentials.user_id}/#{path(account, page)}"
        HTTParty.get(uri, basic_auth:
                            {username: credentials.api_key, password: ""})
{'fraction_non_alphanumeric': 0.10041731872717788, 'fraction_numerical': 0.0020865936358894104, 'mean_word_length': 2.1799336650082917, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2537794', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1045, 'n_words': 212}