class GoogleDrive::Collection

Use GoogleDrive::Session#root_collection, #subcollections, or GoogleDrive::Session#collection_by_url to get GoogleDrive::Collection object.

Public Instance Methods

add(file) click to toggle source

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
contents(params = {}) click to toggle source
Alias for: files
contents_url() click to toggle source
# 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
create_subcollection(title) click to toggle source

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
documents(params = {}) click to toggle source

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
files(params = {}) click to toggle source

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
Also aliased as: contents
remove(file) click to toggle source

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
resource_id() click to toggle source
# File lib/google_drive/collection.rb, line 43
def resource_id
  return self.root? ? nil : super
end
root?() click to toggle source

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
spreadsheets(params = {}) click to toggle source

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
subcollection_by_title(title) click to toggle source

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
subcollections(params = {}) click to toggle source

Returns all its subcollections.

# File lib/google_drive/collection.rb, line 115
def subcollections(params = {})
  return files_with_type("folder", params)
end
title(params = {}) click to toggle source

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