Class: RubyBox::Folder
Instance Method Summary collapse
-
#create_collaboration(email, role = :viewer) ⇒ Object
see developers.box.com/docs/#collaborations-collaboration-object for a list of valid roles.
- #create_subfolder(name) ⇒ Object
- #files(name = nil, item_limit = 100, offset = 0, fields = nil) ⇒ Object
- #folders(name = nil, item_limit = 100, offset = 0, fields = nil) ⇒ Object
- #upload_file(filename, data) ⇒ Object
Methods inherited from Item
#create, #create_shared_link, #delete, #disable_shared_link, has_many, has_many_paginated, #initialize, #method_missing, #reload_meta, #update
Constructor Details
This class inherits a constructor from RubyBox::Item
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RubyBox::Item
Instance Method Details
#create_collaboration(email, role = :viewer) ⇒ Object
see developers.box.com/docs/#collaborations-collaboration-object for a list of valid roles.
42 43 44 45 46 47 48 |
# File 'lib/ruby-box/folder.rb', line 42 def create_collaboration(email, role=:viewer) RubyBox::Collaboration.new(@session, { 'item' => {'id' => id, 'type' => type}, 'accessible_by' => {'login' => email}, 'role' => role.to_s }).create end |
#create_subfolder(name) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/ruby-box/folder.rb', line 31 def create_subfolder(name) url = "#{RubyBox::API_URL}/#{resource_name}" uri = URI.parse(url) request = Net::HTTP::Post.new( uri.request_uri ) request.body = JSON.dump({ "name" => name, "parent" => {"id" => id} }) resp = @session.request(uri, request) RubyBox::Folder.new(@session, resp) end |
#files(name = nil, item_limit = 100, offset = 0, fields = nil) ⇒ Object
8 9 10 |
# File 'lib/ruby-box/folder.rb', line 8 def files(name=nil, item_limit=100, offset=0, fields=nil) items_by_type(RubyBox::File, name, item_limit, offset, fields) end |
#folders(name = nil, item_limit = 100, offset = 0, fields = nil) ⇒ Object
12 13 14 |
# File 'lib/ruby-box/folder.rb', line 12 def folders(name=nil, item_limit=100, offset=0, fields=nil) items_by_type(RubyBox::Folder, name, item_limit, offset, fields) end |
#upload_file(filename, data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby-box/folder.rb', line 16 def upload_file(filename, data) file = RubyBox::File.new(@session, { 'name' => filename, 'parent' => RubyBox::User.new(@session, {'id' => id}) }) begin resp = file.upload_content(data) #write a new file. If there is a conflict, update the conflicted file. rescue RubyBox::ItemNameInUse => e data.rewind file = files(filename).first resp = file.update_content( data ) end end |