-
-
Save xiconet/6eba311c6b7351d5c8ff to your computer and use it in GitHub Desktop.
Iterate Box folders in Ruby
This file contains 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
require 'ruby-box' #gem install ruby-box | |
require 'term/ansicolor' #gem install term-ansicolor | |
include Term::ANSIColor | |
MODIFIED_AT_CUTOFF = Time.new(2013,7,1) | |
session = RubyBox::Session.new({ | |
client_id: "YOUR_CLIENT_ID", | |
client_secret: "YOUR_CLIENT_SECRET", | |
access_token: "YOUR_DEV_ACCESS_TOKEN" | |
}) | |
@client = RubyBox::Client.new(session) | |
def load_folder(folder, path_prefix="/") | |
path = "#{path_prefix}#{folder.name}" | |
puts path | |
files = folder.files(nil,1000,0,['name','modified_at']) | |
files.each do |f| | |
output = "--> #{f.name}" | |
puts f.modified_at < MODIFIED_AT_CUTOFF ? red(output) : output | |
end | |
subFolders = folder.folders | |
subFolders.each do |f| | |
load_folder(f,"#{path}/") | |
end | |
end | |
load_folder @client.root_folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses the "official" ruby-box gem. Might be useful