-rw-r--r-- | content/flickr.js | 20 |
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 @@ -89,64 +89,84 @@ Photo.prototype = { } }; function Flickr() { } Flickr.prototype = { rest_url: 'http://www.flickr.com/services/rest/', auth_url: 'http://flickr.com/services/auth/', photo_url: 'http://static.flickr.com/', photos_url: 'http://www.flickr.com/photos/', upload_url: 'http://www.flickr.com/services/upload/', uploader_edit_url: 'http://www.flickr.com/tools/uploader_edit.gne', api_sig: function(paramstr) { return MD5(toutf8(this.api_shs+paramstr)); }, api_call_url: function(params,url) { params.api_key = this.api_key; var pp = new Array(); for(var p in params) { pp.push(p); } var pstr = ''; var rv = (url?url:this.rest_url)+'?'; for(var p in pp.sort()) { var pn = pp[p]; pstr += pn+params[pn]; rv += pn+'='+params[pn]+'&'; } 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; 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 stat = x.responseXML.firstChild.getAttribute('stat'); if(stat=='ok') { if(on_success) on_success(x); }else{ var e = x.responseXML.getElementsByTagName('err').item(0); var ecode = e.getAttribute('code'); var emsg = e.getAttribute('msg'); dump(params.method+' failed: '+ecode+' '+emsg+'\n'); if(on_failure) on_failure(x,stat,ecode,emsg); } }else{ if(on_failure) on_failure(x); } return true; } x.send(null); return true; }, frob: null, authorize_0: function(perms, on_s, on_f) { var _this = this; this.api_call( { method: 'flickr.auth.getFrob' }, |