Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial drop

  • Loading branch information...
commit 5e1344715850c88ef348ec807b7b603b62207aab 0 parents
@ammmir authored
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2011 Amir Malik
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
11 README.md
@@ -0,0 +1,11 @@
+node-gdocs
+==========
+
+As the name implies, this is a Google Documents List API client for
+node.js. Only the latest release (version 3) of the GData protocol
+supported.
+
+Requirements
+------------
+
+* [node-oauth](https://github.com/ciaranj/node-oauth)
1  index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/client');
56 lib/client.js
@@ -0,0 +1,56 @@
+/**
+ * client.js
+ * Google Documents List API client
+ *
+ * @author Amir Malik
+ */
+
+var querystring = require('querystring'),
+ OAuth = require('oauth').OAuth;
+
+var DocsList = require('./list').DocsList;
+
+var API_URL = 'https://docs.google.com/feeds';
+
+var DocsClient = function(consumer_key, consumer_secret) {
+ this.consumer_key = consumer_key;
+ this.consumer_secret = consumer_secret;
+ this.access_token = undefined;
+ this.access_token_secret = undefined;
+ this.oauth = new OAuth('https://www.google.com/accounts/OAuthGetRequestToken', 'https://www.google.com/accounts/OAuthGetAccessToken', consumer_key, consumer_secret, '1.0', null, 'HMAC-SHA1');
+ this.oauth._headers['GData-Version'] = '3.0'; // HACK
+};
+
+DocsClient.prototype.getAccessToken = function(email, password, cb) {
+ if(!email || !password)
+ return cb(new Error('getAccessToken(email, password, cb) expected'));
+
+ cb(new Error('TODO'));
+};
+
+DocsClient.prototype.getList = function getList(optargs, cb) {
+ if(typeof optargs == 'function') cb = optargs, optargs = {};
+
+ this.oauth.get(API_URL + '/default/private/full?showfolders=true&alt=json',
+ optargs.token || this.access_token,
+ optargs.secret || this.access_token_secret,
+ function(err, data, res) {
+ if(err) {
+ cb(err);
+ } else {
+ try {
+ cb(err, new DocsList(JSON.parse(data)));
+ } catch(e) {
+ cb(e);
+ }
+ }
+ });
+};
+
+DocsClient.prototype.getFile = function getFile(url, optargs, cb) {
+ if(typeof optargs == 'function') cb = optargs, optargs = {};
+
+ cb(new Error('TODO'));
+};
+
+exports.DocsClient = DocsClient;
12 lib/entry.js
@@ -0,0 +1,12 @@
+/**
+* entry.js
+* A helper object that wraps a feed entry
+*
+* @author Amir Malik
+*/
+
+function Entry(entry) {
+ this.entry = entry;
+}
+
+exports.Entry = Entry;
63 lib/list.js
@@ -0,0 +1,63 @@
+/**
+* list.js
+* A helper object that wraps a feed list
+*
+* @author Amir Malik
+*/
+
+function DocsList(feed) {
+ this.feed = feed['feed'];
+ this.iterator = -1;
+
+ //require('fs').writeFileSync('/tmp/docs.json', JSON.stringify(this.feed));
+
+ console.log(this.feed['title']['$t']);
+ console.log('ETag: ' + this.feed['gd$etag']);
+ console.log('updated: ' + this.feed['updated']['$t']);
+
+ this.length = this.feed['entry'].length;
+
+ this.feed['entry'].forEach(function(entry) {
+ var type, selfId, parentId;
+
+ entry['category'].forEach(function(cat) {
+ if('http://schemas.google.com/g/2005#kind' == cat['scheme']) {
+ switch(cat['term']) {
+ case 'http://schemas.google.com/docs/2007#folder':
+ type = 'folder';
+ break;
+ case 'http://schemas.google.com/docs/2007#spreadsheet':
+ case 'http://schemas.google.com/docs/2007#document':
+ case 'http://schemas.google.com/docs/2007#presentation':
+ default:
+ type = 'file';
+ }
+ }
+ });
+
+ entry['link'].forEach(function(link) {
+ switch(link['rel']) {
+ case 'self':
+ selfId = link['href'];
+ break;
+
+ case 'http://schemas.google.com/docs/2007#parent':
+ parentId = link['href'];
+ break;
+ }
+ });
+
+ var etag = entry['gd$etag'];
+ var id = entry['id']['$t'];
+ var resid = entry['gd$resourceId']['$t'];
+ var title = entry['title']['$t'];
+ var published = new Date(Date.parse(entry['published']['$t']));
+ var updated = new Date(Date.parse(entry['updated']['$t']));
+ //var lastViewed = new Date(Date.parse(entry['gd$lastViewed']['$t']));
+
+ console.log(' entry: ' + title + ' / ' + type);
+ console.log(' updated: ' + updated);
+ });
+}
+
+exports.DocsList = DocsList;
Please sign in to comment.
Something went wrong with that request. Please try again.