Sha256: 4c68a0637ede43343fcb0f76d59b06e7c137ec84eb876e2f87ab3bc2c01b0748
Contents?: true
Size: 1.45 KB
Versions: 8
Compression:
Stored size: 1.45 KB
Contents
module RubyBox class Folder < Item has_many :discussions has_many_paginated :items def files(name=nil, item_limit=100, offset=0) items(item_limit, offset).select do |item| item.kind_of? RubyBox::File and (name.nil? or item.name == name) end end def folders(name=nil, item_limit=100, offset=0) items(item_limit, offset).select do |item| item.kind_of? RubyBox::Folder and (name.nil? or item.name == name) end end 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 file = RubyBox::File.new(@session, { 'id' => e['context_info']['conflicts'][0]['id'] }) data.rewind resp = file.update_content( data ) end end 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 private def resource_name 'folders' end def update_fields ['name', 'description'] end end end
Version data entries
8 entries across 8 versions & 1 rubygems