Sha256: 634cd75c141ee2e8e69aa78f67e33bcc742d6236e2a007dfa98d7d398acf3ec9

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# log in using the login example, so we don't have to duplicate code
$: << File.dirname(__FILE__) # for 1.9
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
  # to_i or [] will throw an exception if the index is invalid or out of range respectively
  folder = root.folders[index.to_i]
rescue
  # they picked an invalid folder!
  puts "You picked an invalid folder, please try again."
  exit
end

# the folder they picked was valid
puts "Excellent choice, here are the contents of that folder"

# show the selected folder
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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
box-api-0.1.9 examples/files.rb
box-api-0.1.8 examples/files.rb
box-api-0.1.7 examples/files.rb
box-api-0.1.6 examples/files.rb