<commit_before>class RobinhoodController < ApplicationController
  
  def login
    response = robinhood_post "https://api.robinhood.com/api-token-auth/", {"username" => params[:username], "password" => params[:password]}
    session[:robinhood_auth_token] = response["token"]
    redirect_to root_path
  end

  def basic_info
    @basic_info = robinhood_get "https://api.robinhood.com/user/"
  end

  def portfolios
    @portfolios = robinhood_get("https://api.robinhood.com/portfolios/")["results"]
  end

  def positions
    @investments = {}
    response = robinhood_get "https://api.robinhood.com/positions/"
    @positions = response["results"]
    next_page = response["next"]
    while next_page.present?
      response = robinhood_get "https://api.robinhood.com/positions/"
      @positions += response["results"]
      next_page = response["next"]
    end
    @instruments = []
    @positions.each do |position|
      instrument = robinhood_get position["instrument"]
      @instruments << instrument
      @investments[instrument["symbol"]] = position.merge instrument
    end
    @quotes = robinhood_get("https://api.robinhood.com/quotes/?symbols=#{@instruments.map{|i| i["symbol"]}.join(',')}")["results"]
    @quotes.each do |quote|
      @investments[quote["symbol"]].merge! quote
    end
  end

  def orders
    @orders = robinhood_get("https://api.robinhood.com/orders/")["results"]
  end

  def logout
    session.delete :robinhood_auth_token
    redirect_to root_path
  end

  private
<commit_msg>refactor how to delete session data and logout. store basic info<commit_after>class RobinhoodController < ApplicationController
  
  def login
    response = robinhood_post "https://api.robinhood.com/api-token-auth/", {"username" => params[:username], "password" => params[:password]}
    session[:robinhood_auth_token] = response["token"]
    redirect_to root_path
  end

  def basic_info
    session[:robinhood_user] ||= robinhood_get "https://api.robinhood.com/user/"
    @basic_info = session[:robinhood_user]
  end

  def portfolios
    @portfolios = robinhood_get("https://api.robinhood.com/portfolios/")["results"]
  end

  def positions
    @investments = {}
    response = robinhood_get "https://api.robinhood.com/positions/"
    @positions = response["results"]
    next_page = response["next"]
    while next_page.present?
      response = robinhood_get "https://api.robinhood.com/positions/"
      @positions += response["results"]
      next_page = response["next"]
    end
    @instruments = []
    @positions.each do |position|
      instrument = robinhood_get position["instrument"]
      @instruments << instrument
      @investments[instrument["symbol"]] = position.merge instrument
    end
    @quotes = robinhood_get("https://api.robinhood.com/quotes/?symbols=#{@instruments.map{|i| i["symbol"]}.join(',')}")["results"]
    @quotes.each do |quote|
      @investments[quote["symbol"]].merge! quote
    end
  end

  def orders
    @orders = robinhood_get("https://api.robinhood.com/orders/")["results"]
  end

  def logout
    session.keys.select{|k| k =~ /robinhood/i}.each do |k|
      session.delete k
    end
    redirect_to root_path
  end

  private

{'fraction_non_alphanumeric': 0.14106583072100312, 'fraction_numerical': 0.0, 'mean_word_length': 3.7555886736214603, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 14, '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': '2257879', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1010, 'n_words': 186}