Created
April 7, 2012 19:59
-
-
Save lazypower/2331710 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$: << File.dirname(__FILE__) # for 1.9 | |
# log in using the login example, so we don't have to duplicate code | |
require 'login' | |
# get the root of the folder structure | |
root = @account.root | |
# list all of the folders in the root directory with their index | |
root.folders.each_with_index do |folder, i| | |
puts "##{ i } -- #{ folder.name }" | |
end | |
# let the user pick one to show the contents of | |
puts "Pick a folder number above to show: " | |
index = gets | |
begin | |
# grab the folder they selected | |
folder = root.folders[index.to_i] | |
rescue | |
# they picked a folder that broke our script! | |
puts "You picked an invalid folder, please try again." | |
exit | |
end | |
puts "FOLDER: #{ folder.name } (#{ folder.id })" | |
# loop through and show each of the sub files and folders | |
(folder.files + folder.folders).each do |item| | |
puts "\t#{ item.type.upcase }: #{ item.name } (#{ item.id })" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:<< File.dirname(__FILE__) + "/lib" | |
require 'yaml' | |
require 'box-api' | |
require 'launchy' | |
#save all the app data to a file, so we dont hard code values | |
app_data_file = File.dirname(__FILE__) + '/app_data.yml' | |
app_data = YAML.load_file(app_data_file) | |
#create an account object using the api key stored in the app_data | |
account = Box::Account.new(app_data['api_key']) | |
#read auth tokens if they are saved | |
auth_token = app_data['auth_token'] | |
account.authorize(:auth_token => auth_token) do |auth_url| | |
#this block comes into play if the auth_token is invalid or missing | |
Launchy.open(auth_url) | |
puts "Please press the enter key once you have authorized this application to use your account" | |
gets | |
end | |
unless account.authorized? | |
#Didnt authorize likwe we told them to, try again | |
puts "Unable to login, please try again." | |
exit | |
end | |
#we logged in, whattup?! | |
puts "Logged in as #{ account.login }" | |
#this is so other files can access the account variable | |
@account = account | |
@app_data = app_data | |
app_data['auth_token'] = account.auth_token | |
File.open(app_data_file, 'w') do |file| | |
YAML.dump(app_data, file) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:<< File.dirname(__FILE__) | |
require 'login' | |
root = @account.root | |
deploy_folder = @app_data['deploy_folder'] | |
puts "Searching for Deployment Folder: #{ deploy_folder }" | |
root.folders.each {|folder| | |
if folder.name == "deploy" | |
found = true | |
p folder.id | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment