Class: GDocs4Ruby::Spreadsheet
- Inherits:
-
Document
- Object
- GData4Ruby::GDataObject
- BaseObject
- Document
- GDocs4Ruby::Spreadsheet
- Defined in:
- lib/gdocs4ruby/spreadsheet.rb
Overview
The Spreadsheet class represents a Google Spreadsheet. Also check out Document and BaseObject, the superclass of Spreadsheet.
Usage
All usages assume you’ve already authenticated with the service, and have a service object called
-
Create a new Spreadsheet s = Spreadsheet.new(@service) s.title = ‘Test Spreadsheet’ s.local_file = ‘/path/to/some/spreadsheet.xls’ s.save
-
Deleting a Spreadsheet s = Spreadsheet.find(@service, => @doc_id) s.delete
-
Finding an existing Spreadsheet by id s = Spreadsheet.find(@service, => @doc_id)
-
Full Text Query s = Spreadsheet.find(@service, ‘content text’)
or
s = Spreadsheet.find(@service, {:query => 'content text'})
-
Finding an Existing Spreadsheet by Title s = Spreadsheet.find(@service, nil, => ‘Test Spreadsheet’)
-
Retrieving an Export s = Spreadsheet.find(@service, => @doc_id) s.download_to_file(‘pdf’, ‘/path/to/save/location.pdf’)
Constant Summary collapse
- DOCUMENT_XML =
'<?xml version="1.0" encoding="UTF-8"?> <atom:entry xmlns:atom="http://www.w3.org/2005/Atom"> <atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/docs/2007#spreadsheet" label="spreadsheet"/> <atom:title></atom:title> </atom:entry>'
- DOWNLOAD_TYPES =
['xls', 'csv', 'pdf', 'ods', 'tsv', 'html']
- EXPORT_URI =
'http://spreadsheets.google.com/feeds/download/spreadsheets/Export'
Constants inherited from BaseObject
BaseObject::BOUNDARY, BaseObject::ENTRY_XML, BaseObject::FEEDS, BaseObject::QUERY_FEEDS, BaseObject::TYPES, BaseObject::UPLOAD_TYPES
Instance Attribute Summary
Attributes inherited from BaseObject
#bytes_used, #folders, #html_uri, #local_file, #type, #viewed
Class Method Summary collapse
-
.find(service, query, args = {}) ⇒ Object
Helper function limit queries to Spreadsheets.
Instance Method Summary collapse
-
#get_content(type) ⇒ Object
Retrieves an export of the Spreadsheet.
-
#initialize(service, attributes = {}) ⇒ Spreadsheet
constructor
Creates a new Spreadsheet instance.
Methods inherited from Document
Methods inherited from BaseObject
#access_rules, #add_access_rule, #add_to_folder, #content=, #content_type=, #create, #load, #put_content, #remove_access_rule, #remove_from_folder, #save, #to_iframe, #update_access_rule
Constructor Details
#initialize(service, attributes = {}) ⇒ Spreadsheet
Creates a new Spreadsheet instance. Requires a valid Service object.
66 67 68 69 |
# File 'lib/gdocs4ruby/spreadsheet.rb', line 66 def initialize(service, attributes = {}) super(service, attributes) @xml = DOCUMENT_XML end |
Class Method Details
.find(service, query, args = {}) ⇒ Object
Helper function limit queries to Spreadsheets. See BaseObject::find for syntax. Type is not required and assumed to be ‘spreadsheet’.
61 62 63 |
# File 'lib/gdocs4ruby/spreadsheet.rb', line 61 def self.find(service, query, args = {}) BaseObject::find(service, query, 'spreadsheet', args) end |
Instance Method Details
#get_content(type) ⇒ Object
Retrieves an export of the Spreadsheet. The parameter type
must be one of the DOWNLOAD_TYPES.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gdocs4ruby/spreadsheet.rb', line 72 def get_content(type) if !@exists raise DocumentDoesntExist end if not DOWNLOAD_TYPES.include? type raise ArgumentError end service.reauthenticate('wise') ret = service.send_request(GData4Ruby::Request.new(:get, EXPORT_URI, nil, nil, {"key" => @id.gsub(/\w.*:/, ""),"exportFormat" => type})) service.reauthenticate() ret.body end |