<commit_before>require 'httparty'
require 'active_support'

class Buxfer
  include HTTParty
  base_uri 'https://www.buxfer.com/api'
  format :xml

  def initialize(username, password)
    @username = username
    @password = password
  end

  def add_transaction(amount, description, account = nil, status = nil, tags = [])
    amount = (amount < 0 ? amount.to_s : '+' + amount.to_s)
    tags = tags.join(',')
    attrs = {}
    text = [description, amount]

    {:acct => account, :status => status, :tags => tags}.each do |k, v|
      text << '%s:%s' % [k, v] unless v.blank?
    end

    self.class.post('/add_transaction.xml', auth_query({:text => text, :format => 'sms'}, :body))
  end

  def upload_statement(accountId, statement, dateFormat = 'DD/MM/YYYY')
    unless statement.is_a?(String)
      if statement.respond_to?(:read)
        statement = statement.read
      else chec
        statement = statement.to_s
      end
    end

    options = {:accountId => accountId, :statement => statement, :dateFormat => dateFormat}

    self.class.post('/upload_statement.xml', auth_query(options, :body))
  end

  def transactions(options = {})
    self.class.get('/transactions.xml', auth_query(options))['response']['transactions']['transaction']
  end
  
  def reports(options = {})
    self.class.get('/reports.xml', auth_query(options))
  end

  def accounts
    self.class.get('/accounts.xml', auth_query)['response']['accounts']['account']
  end

  def loans
    self.class.get('/loans.xml', auth_query)
  end

  def tags
    self.class.get('/tags.xml', auth_query)['response']['tags']['tag']
  end

  private

  def auth
    @auth ||= begin
      self.class.get('/login.xml', :query => {:userid => @username, :password => @password})
    end
  end

  def token
    auth['response']['token']
  end

  def auth_query(options = {}, container = :query)
    {container => options.merge(:token => token)}
  end
end<commit_msg>Fill in loan and report responses<commit_after>require 'httparty'
require 'active_support'

class Buxfer
  include HTTParty
  base_uri 'https://www.buxfer.com/api'
  format :xml

  def initialize(username, password)
    @username = username
    @password = password
  end

  def add_transaction(amount, description, account = nil, status = nil, tags = [])
    amount = (amount < 0 ? amount.to_s : '+' + amount.to_s)
    tags = tags.join(',')
    attrs = {}
    text = [description, amount]

    {:acct => account, :status => status, :tags => tags}.each do |k, v|
      text << '%s:%s' % [k, v] unless v.blank?
    end

    self.class.post('/add_transaction.xml', auth_query({:text => text, :format => 'sms'}, :body))
  end

  def upload_statement(accountId, statement, dateFormat = 'DD/MM/YYYY')
    unless statement.is_a?(String)
      if statement.respond_to?(:read)
        statement = statement.read
      else chec
        statement = statement.to_s
      end
    end

    options = {:accountId => accountId, :statement => statement, :dateFormat => dateFormat}

    self.class.post('/upload_statement.xml', auth_query(options, :body))
  end

  def transactions(options = {})
    self.class.get('/transactions.xml', auth_query(options))['response']['transactions']['transaction']
  end
  
  def reports(options = {})
    self.class.get('/reports.xml', auth_query(options))['response']['reports']['report']
  end

  def accounts
    self.class.get('/accounts.xml', auth_query)['response']['accounts']['account']
  end

  def loans
    self.class.get('/loans.xml', auth_query)['response']['loans']['loan']
  end

  def tags
    self.class.get('/tags.xml', auth_query)['response']['tags']['tag']
  end

  private

  def auth
    @auth ||= begin
      self.class.get('/login.xml', :query => {:userid => @username, :password => @password})
    end
  end

  def token
    auth['response']['token']
  end

  def auth_query(options = {}, container = :query)
    {container => options.merge(:token => token)}
  end
end
{'fraction_non_alphanumeric': 0.16379310344827586, 'fraction_numerical': 0.0005070993914807302, 'mean_word_length': 3.4829545454545454, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 18}, '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': '1299123', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1242, 'n_words': 286}