Class: GoogleDriveV0::Table

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/google_drive_v0/table.rb

Overview

DEPRECATED: Table and Record feeds are deprecated and they will not be available after March 2012.

Use GoogleDriveV0::Worksheet#add_table to create table. Use GoogleDriveV0::Worksheet#tables to get GoogleDriveV0::Table objects.

Constant Summary

Constants included from Util

Util::DOCS_BASE_URL, Util::EXT_TO_CONTENT_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

concat_url, encode_query, h, to_v3_url

Constructor Details

#initialize(session, entry) ⇒ Table

:nodoc:



20
21
22
23
24
25
26
# File 'lib/google_drive_v0/table.rb', line 20

def initialize(session, entry) #:nodoc:
  @columns = {}
  @worksheet_title = entry.css("gs|worksheet")[0]["name"]
  @records_url = entry.css("content")[0]["src"]
  @edit_url = entry.css("link[rel='edit']")[0]["href"]
  @session = session
end

Instance Attribute Details

#worksheet_titleObject (readonly)

Title of the worksheet the table belongs to.



29
30
31
# File 'lib/google_drive_v0/table.rb', line 29

def worksheet_title
  @worksheet_title
end

Instance Method Details

#add_record(values) ⇒ Object

Adds a record.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/google_drive_v0/table.rb', line 32

def add_record(values)
  fields = ""
  values.each() do |name, value|
    fields += "<gs:field name='#{h(name)}'>#{h(value)}</gs:field>"
  end
  xml =<<-EOS
    <entry
        xmlns="http://www.w3.org/2005/Atom"
        xmlns:gs="http://schemas.google.com/spreadsheets/2006">
      #{fields}
    </entry>
  EOS
  @session.request(:post, @records_url, :data => xml)
end

#deleteObject

Deletes this table. Deletion takes effect right away without calling save().



54
55
56
# File 'lib/google_drive_v0/table.rb', line 54

def delete
  @session.request(:delete, @edit_url, :header => {"If-Match" => "*"})
end

#recordsObject

Returns records in the table.



48
49
50
51
# File 'lib/google_drive_v0/table.rb', line 48

def records
  doc = @session.request(:get, @records_url)
  return doc.css("entry").map(){ |e| Record.new(@session, e) }
end