Skip to content

Commit

Permalink
separate entry and list
Browse files Browse the repository at this point in the history
  • Loading branch information
ammmir committed Feb 4, 2011
1 parent 5e13447 commit 275dedd
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 46 deletions.
78 changes: 78 additions & 0 deletions lib/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
58 changes: 12 additions & 46 deletions lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.