GDocs4Ruby is a full featured wrapper for version 2.0 of the Google Documents API (aka DocList). GDocs4Ruby provides the ability to create, update and delete google documents, metadata and content. The gem also includes support for folders, modifying permissions for documents via ACL feeds, and much more.
GDocs4Ruby uses the GData4Ruby Gem for interacting with the Google API. Check out cookingandcoding.com/gdata4ruby for other Google API Libraries based using GData4Ruby.
GDocs4Ruby was created and is maintained by Mike Reich and is licenses under the GPL v2. Feel free to use and update, but be sure to contribute your code back to the project and attribute as required by the license.
cookingandcoding.com/gdocs4ruby/
GDocs4Ruby includes the following classes: Service, Folder, BaseObject, Spreadsheet, Document, Presentation.
The Service object provides functionality for authenticating with the Google Documents API, grabbing a list of documents and a list of folders associated with the account.
Interacting with objects is done by using the associated subclass of BaseObject, i.e. Document. Every object class supports the same inherited methods for creating, updating and deleting, in addition to changing ACL permissions, and adding and removing from various folders.
Below are some common usage examples. For more examples, check the documentation. Also, check out the example code for integrating with Rails at cookingandcoding.com/gdocs4ruby/example/
-
Authenticate
service = Service.new service.authenticate("user@gmail.com", "password")
-
Get Document List
documents = service.files
-
Get Folder List
folders = serivce.folders
-
Create a new Document
doc = Document.new(@service) doc.title = 'Test Document' doc.content = '<h1>Test Content HTML</h1>' doc.content_type = 'html' doc.save
-
Deleting a Document
doc = Document.find(@service, {:id => @doc_id}) doc.delete
-
Finding an existing Document by id
doc = Document.find(@service, {:id => @doc_id})
-
Full Text Query
doc = Document.find(@service, 'content text')
or
doc = Document.find(@service, {:query => 'content text'})
-
Finding an Existing Document by Title
doc = Document.find(@service, nil, {'title' => 'Test Document'})
-
Updating a Document with Content from a Local File
doc = Document.find(@service, {:id => @doc_id}) doc.title = 'New Title' doc.local_file = '/path/to/some/file' doc.save
-
Retrieving an Export
doc = Document.find(@service, {:id => @doc_id}) doc.download_to_file('pdf', '/path/to/save/location.pdf')