<commit_before>enable :sessions

# Tutorial by Example, Sinatra Edition
# A simple app that allows a user to first authorize their Dropbox account, and then upload a file to their Dropbox.

get '/' do
  if params[:oauth_token] then
    dropbox_session = Dropbox::Session.deserialize(session[:dropbox_session])
    dropbox_session.authorize(params)
    session[:dropbox_session] = dropbox_session.serialize # re-serialize the authenticated session
    redirect '/upload'
  else
    dropbox_session = Dropbox::Session.new('key', 'secret')
    session[:dropbox_session] = dropbox_session.serialize
    redirect dropbox_session.authorize_url(:oauth_callback => 'http://localhost:9393')
  end
end

get '/upload' do
 redirect '/' unless session[:dropbox_session]
 dropbox_session = Dropbox::Session.deserialize(session[:dropbox_session])
 dropbox_session.mode = :dropbox
 redirect '/' unless dropbox_session.authorized?
 dropbox_session.upload 'testfile.txt', 'Folder'
 uploaded_file = dropbox_session.file 'Folder/testfile.txt'
 'This is the metadata: ' + uploaded_file.metadata.size
end

get "/logout" do
  session = {}
  redirect "/"
end<commit_msg>switched gem to official and modeled it like https://www.dropbox.com/developers/reference/sdk<commit_after>require 'sinatra'
require 'dropbox_sdk'
enable :sessions

get '/' do
  if not params[:oauth_token] then
    dbsession = DropboxSession.new('ribh7ft60gym2l8', '<KEY>') # key, secret
    session[:dropbox_session] = dbsession.serialize #serialize and save this DropboxSession
    #pass to get_authorize_url a callback url that will return the user here
    # redirect dbsession.get_authorize_url url_for(:action => 'authorize')
    redirect dbsession.get_authorize_url("http://127.0.0.1:9393")
  else
    # the user has returned from Dropbox
    dbsession = DropboxSession.deserialize(session[:dropbox_session])
    dbsession.get_access_token  #we've been authorized, so now request an access_token
    session[:dropbox_session] = dbsession.serialize

    redirect '/upload'
  end
end

get '/upload' do
  # Check if user has no dropbox session...re-direct them to authorize
  redirect '/' unless session[:dropbox_session]
  dbsession = DropboxSession.deserialize(session[:dropbox_session])
  client = DropboxClient.new(dbsession, :app_folder) #raise an exception if session not authorized
  info = client.account_info # look up account information

  if request.method != "POST"
    # show a file upload page
    render :inline =>
      "#{info['email']} <br/><%= form_tag({:action => :upload}, :multipart => true) do %><%= file_field_tag 'file' %><%= submit_tag %><% end %>"
    return
  else
    # upload the posted file to dropbox keeping the same name
    resp = client.put_file(params[:file].original_filename, params[:file].read)
    render :text => "Upload successful! File now at #{resp['path']}"
  end
end

# dropbox_session.mode = :dropbox
 # redirect '/' unless dropbox_session.authorized?
 # dropbox_session.upload 'testfile.txt', 'Folder'
 # uploaded_file = dropbox_session.file 'Folder/testfile.txt'
 # 'This is the metadata: ' + uploaded_file.metadata.size

get "/logout" do
  session = {}
  redirect "/"
end
{'fraction_non_alphanumeric': 0.11188150015757958, 'fraction_numerical': 0.005988023952095809, 'mean_word_length': 4.7709090909090905, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 1, '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': '7256509', 'n_tokens_mistral': 975, 'n_tokens_neox': 958, 'n_words': 261}