Skip to content
Browse files

separate entry and list

  • Loading branch information...
1 parent 5e13447 commit 275deddf5ab14842a264445a594d9060ebd357b3 @ammmir committed Feb 3, 2011
Showing with 90 additions and 46 deletions.
  1. +78 −0 lib/entry.js
  2. +12 −46 lib/list.js
View
78 lib/entry.js
@@ -7,6 +7,84 @@
function Entry(entry) {
this.entry = entry;
+
+ if(entry)
+ this._init();
}
+Entry.prototype._init = function _init() {
+ var type = 0;
+ var selfId;
+ var parnetId;
+
+ // type of file
+ this.entry['category'].forEach(function(category) {
+ if('http://schemas.google.com/g/2005#kind' == category['scheme']) {
+ switch(category['term']) {
+ case 'http://schemas.google.com/docs/2007#document':
+ type = Entry.DOCUMENT;
+ break;
+ case 'http://schemas.google.com/docs/2007#spreadsheet':
+ type = Entry.SPREADSHEET;
+ break;
+ case 'http://schemas.google.com/docs/2007#presentation':
+ type = Entry.PRESENTATION;
+ break;
+ case 'http://schemas.google.com/docs/2007#folder':
+ type = Entry.FOLDER;
+ break;
+ default:
+ type = Entry.FILE;
+ }
+ }
+ });
+
+ // parent folder
+ this.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;
+ }
+ });
+};
+
+Entry.prototype.getEtag = function getEtag() {
+ return this.entry['gd$etag'];
+};
+
+Entry.prototype.getTitle = function getTitle() {
+ return this.entry['title']['$t'];
+};
+
+Entry.prototype.getPublishedDate = function getPublishedDate() {
+ return new Date(Date.parse(this.entry['published']['$t']));
+};
+
+Entry.prototype.getLastUpdatedDate = function getLastUpdatedDate() {
+ return new Date(Date.parse(this.entry['updated']['$t']));
+};
+
+Entry.prototype.getId = function getId() {
+ return this.entry['id']['$t'];
+};
+
+Entry.prototype.getResourceId = function getResourceId() {
+ return this.entry['gd$resourceId']['$t'];
+};
+
+Entry.prototype.getType = function getType() {
+ return this.type;
+};
+
+Entry.FILE = 1;
+Entry.FOLDER = 2;
+Entry.DOCUMENT = 4;
+Entry.SPREADSHEET = 8;
+Entry.PRESENTATION = 16;
+
exports.Entry = Entry;
View
58 lib/list.js
@@ -5,59 +5,25 @@
* @author Amir Malik
*/
+var Entry = require('./entry').Entry;
+
function DocsList(feed) {
this.feed = feed['feed'];
- this.iterator = -1;
-
+ this.entries = [];
+
//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);
- });
+ for(var i = 0; i < this.feed['entry'].length; i++) {
+ this.entries.push(new Entry(this.feed['entry'][i]));
+ }
}
+DocsList.prototype.getEntries = function getEntries() {
+ return this.entries;
+};
+
exports.DocsList = DocsList;

0 comments on commit 275dedd

Please sign in to comment.
Something went wrong with that request. Please try again.