Use GoogleDrive::Session#root_collection, #subcollections, or GoogleDrive::Session#collection_by_url to get GoogleDrive::Collection object.
Adds the given GoogleDrive::File to the collection.
# File lib/google_drive/collection.rb, line 48 def add(file) header = {"GData-Version" => "3.0", "Content-Type" => "application/atom+xml"} xml = " <entry xmlns="http://www.w3.org/2005/Atom"> <id>#{h(file.document_feed_url)}</id> </entry> " @session.request( :post, self.contents_url, :data => xml, :header => header, :auth => :writely) return nil end
# File lib/google_drive/collection.rb, line 21 def contents_url if self.root? # The root collection doesn't have document feed. return concat_url(ROOT_URL, "/contents") else return self.document_feed_entry.css( "content[type='application/atom+xml;type=feed']")[0]["src"] end end
Creates a sub-collection with given title. Returns GoogleDrive::Collection object.
# File lib/google_drive/collection.rb, line 61 def create_subcollection(title) header = {"GData-Version" => "3.0", "Content-Type" => "application/atom+xml"} xml = " <entry xmlns="http://www.w3.org/2005/Atom"> <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/docs/2007#folder"/> <title>#{h(title)}</title> </entry> " doc = @session.request( :post, contents_url, :data => xml, :header => header, :auth => :writely) return @session.entry_element_to_file(doc) end
Returns all the Google Docs documents in the collection.
# File lib/google_drive/collection.rb, line 110 def documents(params = {}) return files_with_type("document", params) end
Returns all the files (including spreadsheets, documents, subcollections) in the collection.
You can specify query parameters described at developers.google.com/google-apps/documents-list/#getting_a_list_of_documents_and_files
e.g.
# Gets all the files in collection, including subcollections. collection.files # Gets only files with title "hoge". collection.files("title" => "hoge", "title-exact" => "true")
# File lib/google_drive/collection.rb, line 98 def files(params = {}) return files_with_type(nil, params) end
Removes the given GoogleDrive::File from the collection.
# File lib/google_drive/collection.rb, line 76 def remove(file) url = to_v3_url("#{contents_url}/#{file.resource_id}") @session.request(:delete, url, :auth => :writely, :header => {"If-Match" => "*"}) end
# File lib/google_drive/collection.rb, line 43 def resource_id return self.root? ? nil : super end
Returns true if this is a root collection
# File lib/google_drive/collection.rb, line 82 def root? self.document_feed_url == ROOT_URL end
Returns all the spreadsheets in the collection.
# File lib/google_drive/collection.rb, line 105 def spreadsheets(params = {}) return files_with_type("spreadsheet", params) end
Returns its subcollection whose title exactly matches title as
GoogleDrive::Collection. Returns nil if not
found. If multiple collections with the title are found,
returns one of them.
# File lib/google_drive/collection.rb, line 122 def subcollection_by_title(title) return subcollections("title" => title, "title-exact" => "true")[0] end
Returns all its subcollections.
# File lib/google_drive/collection.rb, line 115 def subcollections(params = {}) return files_with_type("folder", params) end
Title of the collection.
Set params[:reload] to true to force reloading the title.
# File lib/google_drive/collection.rb, line 34 def title(params = {}) if self.root? # The root collection doesn't have document feed. return nil else return super end end