class GoogleSpreadsheet::Collection

Use GoogleSpreadsheet::Session#collection_by_url to get GoogleSpreadsheet::Collection object.

Attributes

collection_feed_url[R]

Public Instance Methods

add(spreadsheet) click to toggle source

Adds the given GoogleSpreadsheet::Spreadsheet to the collection.

# File lib/google_spreadsheet/collection.rb, line 24
        def add(spreadsheet)
          contents_url = concat_url(@collection_feed_url, "/contents")
          header = {"GData-Version" => "3.0", "Content-Type" => "application/atom+xml"}
          xml = "            <entry xmlns="http://www.w3.org/2005/Atom">
              <id>#{h(spreadsheet.document_feed_url)}</id>
            </entry>
"
          @session.request(
              :post, contents_url, :data => xml, :header => header, :auth => :writely)
          return nil
        end
spreadsheets() click to toggle source

Returns all the spreadsheets in the collection.

# File lib/google_spreadsheet/collection.rb, line 38
def spreadsheets
  
  contents_url = concat_url(@collection_feed_url, "/contents")
  header = {"GData-Version" => "3.0", "Content-Type" => "application/atom+xml"}
  doc = @session.request(:get, contents_url, :header => header, :auth => :writely)
  
  result = []
  for entry in doc.css("feed > entry")
    title = entry.css("title").text
    worksheets_feed_link = entry.css(
      "link[rel='http://schemas.google.com/spreadsheets/2006#worksheetsfeed']")[0]
    if worksheets_feed_link
      result.push(GoogleSpreadsheet::Spreadsheet.new(
          @session, worksheets_feed_link["href"], title))
    end
  end
  return result
  
end