summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2011-08-28 11:05:26 (UTC)
committer Michael Krelin <hacker@klever.net>2011-08-28 11:05:26 (UTC)
commit4152a504609522fab4a269dc88d13a1078a09452 (patch) (side-by-side diff)
treea923baa662a97b865eddedb1394085d943289b0a
parent5d85cdc10a4affbebc8a06d655f820239ececf37 (diff)
downloadfireflix-4152a504609522fab4a269dc88d13a1078a09452.zip
fireflix-4152a504609522fab4a269dc88d13a1078a09452.tar.gz
fireflix-4152a504609522fab4a269dc88d13a1078a09452.tar.bz2
Add json-responding api calls
It is somewhat more native to javascript. Or could be, at least. Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--content/flickr.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/content/flickr.js b/content/flickr.js
index e09d5f0..545144c 100644
--- a/content/flickr.js
+++ b/content/flickr.js
@@ -118,6 +118,26 @@ Flickr.prototype = {
rv += 'api_sig='+this.api_sig(pstr);
return rv;
},
+ api_call_json: function(params,on_success,on_failure) {
+ if(params.auth_token=='default') params.auth_token=this.token;
+ params.format = 'json'; params.nojsoncallback=1;
+ var x = new XMLHttpRequest();
+ x.open("GET",this.api_call_url(params));
+ x.onreadystatechange=function() {
+ if(x.readyState!=4) return false;
+ if(x.status==200) {
+ var rsp=JSON.parse(x.responseText);
+ if(rsp.stat=='ok')
+ on_success && on_success(x,rsp);
+ else
+ on_failure && on_failure(rsp,rsp.stat,rsp.code,rsp.message);
+ }else
+ on_failure && on_failure(x);
+ return true;
+ };
+ x.send(null);
+ return true;
+ },
api_call: function(params, on_success, on_failure) {
if(params.auth_token == 'default')
params.auth_token = this.token;