class Box::Folder
Constants
- LIMIT
Public Instance Methods
find_or_create_subfolder(folder_name)
click to toggle source
# File lib/box/folder.rb, line 21 def find_or_create_subfolder(folder_name) folder = subfolder(folder_name) return folder unless folder.nil? Box.log "Creating subfolder in #{self.name} for #{folder_name}" response = @client.post('folders', {name: folder_name, parent:{id: self.id}}) if response.status == 201 # created folder = Box::Folder.new(@client, response.body) Box.log "Created folder for #{folder_name} in #{name} as #{folder.id}" folder else Box.log "Error creating folder, #{response.body}" nil end end
folders()
click to toggle source
# File lib/box/folder.rb, line 61 def folders items.select {|item| item.type == 'folder' } end
has_item?(name)
click to toggle source
Check to see if an item of the same name in the folder
# File lib/box/folder.rb, line 11 def has_item?(name) items.find {|item| item.name == name} end
items(params = {}, collection = [])
click to toggle source
Warning: This gets on all files for a directory with no limit by recursively calling itself until it reaches the limit
# File lib/box/folder.rb, line 41 def items(params = {}, collection = []) # Format params defaults params = {fields: 'sha1,name,path_collection,size', limit: LIMIT, offset: 0}.merge(params) # Add expected fields and limit response = @client.get("/folders/#{id}/items", params) # Add the results to the total collection collection.push *@client.parse_items(response.body) total_count = response.body['total_count'] offset = (LIMIT * (params[:offset] + 1)) if total_count > offset Box.log "Recursively calling for items in folder #{name} - #{LIMIT}, #{offset}, #{total_count}" return self.items({offset: offset}, collection) end collection end
load_info!()
click to toggle source
# File lib/box/folder.rb, line 6 def load_info! @client.get("/folders/#{id}") end
subfolder(folder_name)
click to toggle source
# File lib/box/folder.rb, line 15 def subfolder(folder_name) folders = items.select {|item| item.folder? and item.name == folder_name} return nil if folders.empty? folders.first end