summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2011-08-28 12:17:34 (UTC)
committer Michael Krelin <hacker@klever.net>2011-08-28 12:17:34 (UTC)
commitaa13caca14bac3ed268ac6fb62f0270e40b24e48 (patch) (side-by-side diff)
treeedcfd094407b87cf9c49e9275c6d4b847fc82f29
parent4152a504609522fab4a269dc88d13a1078a09452 (diff)
downloadfireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.zip
fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.tar.gz
fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.tar.bz2
made api calls mostly json-based
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js96
-rw-r--r--content/flickr.js65
2 files changed, 69 insertions, 92 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 225e21c..283e930 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -126,9 +126,7 @@ var fireflix = {
- importXPR: function(xp) {
+ import_json: function(jp) {
this.tree.beginUpdateBatch();
this.photos = new Array();
- var n; while(n=xp.iterateNext()) {
- this.photos.push(new Photo(n));
- }
- this.rowCount = this.photos.length;
+ for(var i in jp) this.photos.push(new Photo(jp[i]));
+ this.rowCount =this.photos.length;
this.tree.endUpdateBatch();
@@ -137,4 +135,4 @@ var fireflix = {
load_photos: function(psid) {
- var _this = this;
- this.fireflix.flickr.api_call(
+ var that = this;
+ this.fireflix.flickr.api_call_json(
{
@@ -144,10 +142,6 @@ var fireflix = {
extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update'
- }, function(xr) {
- var x = xr.responseXML;
- var xp = x.evaluate(
- '/rsp/photoset/photo', x, null,
- XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
- _this.importXPR(xp);
+ }, function(x,j) {
+ that.import_json(j.photoset.photo);
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
@@ -202,8 +196,6 @@ var fireflix = {
- importXPR: function(xp) {
+ import_json: function(j) {
this.tree.beginUpdateBatch();
this.sets = new Array();
- var n; while(n=xp.iterateNext()) {
- this.sets.push(new Photoset(n));
- }
+ for(var i in j) this.sets.push(new Photoset(j[i]));
this.rowCount = this.sets.length;
@@ -212,4 +204,4 @@ var fireflix = {
refresh_sets: function() {
- var _this = this;
- this.fireflix.flickr.api_call(
+ var that = this;
+ this.fireflix.flickr.api_call_json(
{
@@ -217,10 +209,6 @@ var fireflix = {
auth_token: 'default'
- }, function(xr) {
- var x = xr.responseXML;
- var xp = x.evaluate(
- '/rsp/photosets/photoset', x, null,
- XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
- _this.importXPR(xp);
+ }, function(x,j) {
+ that.import_json(j.photosets.photoset);
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
@@ -789,10 +777,10 @@ var fireflix = {
- importXPR: function(xp) {
+ import_json: function(jp) {
this.selection.clearSelection();
- this.selection.currentIndex = -1;
- this.searchresult_props.hidden = true;
+ this.selection.currentIndex=-1;
+ this.searchresult_props.hidden=true;
this.tree.beginUpdateBatch();
this.photos = new Array();
- var n; while(n=xp.iterateNext()) {
- this.photos.push(new Photo(n));
+ for(var i in jp) {
+ this.photos.push(new Photo(jp[i]));
}
@@ -825,18 +813,15 @@ var fireflix = {
perform_search: function(p) {
- var _this = this;
- this.fireflix.flickr.api_call( p,
- function(xr) {
- var x = xr.responseXML;
- var xp = xp_nodes('/rsp/photos/photo',x);
- _this.importXPR(xp);
- _this.tree.ensureRowIsVisible(0);
- xp = xp_node('/rsp/photos',x);
- _this.paging.page = parseInt(xp.getAttribute('page'));
- _this.paging.pages = parseInt(xp.getAttribute('pages'));
- _this.paging.perpage = parseInt(xp.getAttribute('perpage'));
- _this.paging.total = parseInt(xp.getAttribute('total'));
- _this.update_paging();
- _this.on_select();
+ var that = this;
+ this.fireflix.flickr.api_call_json( p,
+ function(x,j) {
+ that.import_json(j.photos.photo);
+ that.tree.ensureRowIsVisible(0);
+ var pp=j.photos;
+ that.paging.page = pp.page; that.paging.pages = pp.pages;
+ that.paging.perpage = pp.perpage;
+ that.paging.total = pp.total;
+ that.update_paging();
+ that.on_select();
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
@@ -900,4 +885,4 @@ var fireflix = {
var ci = this.selection.currentIndex;
- var _this = this;
- this.fireflix.flickr.api_call(
+ var that = this;
+ this.fireflix.flickr.api_call_json(
{
@@ -907,11 +892,10 @@ var fireflix = {
secret: p.secret
- }, function(xr) {
- var pp = _this.photos[ci];
- if(ci==_this.selection.currentIndex && pp.id==pid) {
- var n = xp_node('/rsp/photo',xr.responseXML);
- pp.fromNode_(n);
- _this.render_description_frame(pp.description);
+ }, function(x,j) {
+ var pp = that.photos[ci];
+ if(ci==that.selection.currentIndex && pp.id==pid) {
+ pp.fromJSON_(j.photo);
+ that.render_description_frame(pp.description);
}
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
diff --git a/content/flickr.js b/content/flickr.js
index 545144c..716874b 100644
--- a/content/flickr.js
+++ b/content/flickr.js
@@ -8,3 +8,3 @@ function Photoset(s) {
}else
- this.fromNode(s);
+ this.fromJSON(s);
}
@@ -18,11 +18,9 @@ Photoset.prototype = {
description: null,
- fromNode: function(n) {
- this.id = n.getAttribute('id');
- this.primary = n.getAttribute('primary');
- this.secret = n.getAttribute('secret');
- this.server = n.getAttribute('server');
- this.photos = n.getAttribute('photos');
- this.title = n.getElementsByTagName('title').item(0).firstChild.nodeValue;
- this.description = n.getElementsByTagName('description').item(0).firstChild;
- if(this.description) this.description = this.description.nodeValue;
+ fromJSON: function(j) {
+ this.id=j.id;
+ this.primary = j.primary;
+ this.secret = j.secret; this.server = j.server;
+ this.photos = j.photos;
+ this.title = j.title._content;
+ this.description = j.description._content;
}
@@ -37,3 +35,3 @@ function Photo(s) {
}else
- this.fromNode(s);
+ this.fromJSON(s);
}
@@ -50,30 +48,25 @@ Photo.prototype = {
lastupdate: null,
- fromNode: function(n) {
- this.id = n.getAttribute('id'); this.secret = n.getAttribute('secret');
- this.server = n.getAttribute('server');
- this.title = n.getAttribute('title');
- this.isprimary = n.getAttribute('isprimary');
- this.license = n.getAttribute('license');
- this.dateupload = n.getAttribute('dateupload');
- this.datetaken = n.getAttribute('datetaken'); this.datetakengranularity = n.getAttribute('datetakengranularity');
- this.ownername = n.getAttribute('ownername');
- this.iconserver = n.getAttribute('iconserver');
- this.originalformat = n.getAttribute('originalformat');
- this.lastupdate = n.getAttribute('lastupdate');
+ fromJSON: function(j) {
+ this.id = j.id; this.secret = j.secret;
+ this.server = j.server;
+ this.title=j.title;
+ this.isprimary = j.isprimary;
+ this.license = j.license;
+ this.dateupload = j.dateupload;
+ this.datetaken=j.datetaken; j.datetakengranularity=j.datetakengranularity;
+ this.ownername=j.ownername;
+ this.iconserver=j.iconserver;
+ this.originalformat=j.originalformat;
+ this.lastupdate=j.lastupdate;
},
- fromNode_: function(n) {
- var t;
- // TODO: @rotation @isfavorite
+ fromJSON_: function(j) {
this.owner = {};
- t = n.getElementsByTagName('owner').item(0);
- if(t) {
- this.owner.nsid=t.getAttribute('nsid');
- this.owner.username=t.getAttribute('username');
- this.owner.realname=t.getAttribute('realname');
- this.owner.location=t.getAttribute.location;
- }
- t = n.getElementsByTagName('description').item(0);
- if(t && t.firstChild) {
- this.description = t.firstChild.nodeValue;
+ var t;
+ if((t=j.owner)) {
+ this.owner.nsid=t.nsid;
+ this.owner.username=t.username; this.owner.realname=t.realname;
+ this.owner.location=t.location;
}
+ if((t=j.description)) this.description=t._content;
+ // TODO: @rotation @isfavorite
// TODO: visibility/@ispublic visibility/@isfriend visibility/@isfamily