summaryrefslogtreecommitdiffabout
path: root/content/flickr.js
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) (unidiff)
treeedcfd094407b87cf9c49e9275c6d4b847fc82f29 /content/flickr.js
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 (limited to 'content/flickr.js') (more/less context) (ignore whitespace changes)
-rw-r--r--content/flickr.js65
1 files changed, 29 insertions, 36 deletions
diff --git a/content/flickr.js b/content/flickr.js
index 545144c..716874b 100644
--- a/content/flickr.js
+++ b/content/flickr.js
@@ -1,334 +1,327 @@
1/* 1/*
2 * Photoset 2 * Photoset
3 */ 3 */
4 4
5function Photoset(s) { 5function Photoset(s) {
6 if(s instanceof Photoset) { 6 if(s instanceof Photoset) {
7 for(var p in s) this[p]=s[p]; 7 for(var p in s) this[p]=s[p];
8 }else 8 }else
9 this.fromNode(s); 9 this.fromJSON(s);
10} 10}
11Photoset.prototype = { 11Photoset.prototype = {
12 id: null, 12 id: null,
13 primary: null, 13 primary: null,
14 secret: null, 14 secret: null,
15 server: null, 15 server: null,
16 photos: null, 16 photos: null,
17 title: null, 17 title: null,
18 description: null, 18 description: null,
19 fromNode: function(n) { 19 fromJSON: function(j) {
20 this.id = n.getAttribute('id'); 20 this.id=j.id;
21 this.primary = n.getAttribute('primary'); 21 this.primary = j.primary;
22 this.secret = n.getAttribute('secret'); 22 this.secret = j.secret; this.server = j.server;
23 this.server = n.getAttribute('server'); 23 this.photos = j.photos;
24 this.photos = n.getAttribute('photos'); 24 this.title = j.title._content;
25 this.title = n.getElementsByTagName('title').item(0).firstChild.nodeValue; 25 this.description = j.description._content;
26 this.description = n.getElementsByTagName('description').item(0).firstChild;
27 if(this.description) this.description = this.description.nodeValue;
28 } 26 }
29}; 27};
30 28
31/* 29/*
32 * Photo 30 * Photo
33 */ 31 */
34function Photo(s) { 32function Photo(s) {
35 if(s instanceof Photo) { 33 if(s instanceof Photo) {
36 for(var p in s) this[p]=s[p]; 34 for(var p in s) this[p]=s[p];
37 }else 35 }else
38 this.fromNode(s); 36 this.fromJSON(s);
39} 37}
40Photo.prototype = { 38Photo.prototype = {
41 id: null, secret: null, 39 id: null, secret: null,
42 server: null, 40 server: null,
43 title: null, 41 title: null,
44 isprimary: null, 42 isprimary: null,
45 license: null, 43 license: null,
46 dateupload: null, datetaken: null, datetakengranularity: null, 44 dateupload: null, datetaken: null, datetakengranularity: null,
47 ownername: null, 45 ownername: null,
48 iconserver: null, 46 iconserver: null,
49 originalformat: null, 47 originalformat: null,
50 lastupdate: null, 48 lastupdate: null,
51 fromNode: function(n) { 49 fromJSON: function(j) {
52 this.id = n.getAttribute('id'); this.secret = n.getAttribute('secret'); 50 this.id = j.id; this.secret = j.secret;
53 this.server = n.getAttribute('server'); 51 this.server = j.server;
54 this.title = n.getAttribute('title'); 52 this.title=j.title;
55 this.isprimary = n.getAttribute('isprimary'); 53 this.isprimary = j.isprimary;
56 this.license = n.getAttribute('license'); 54 this.license = j.license;
57 this.dateupload = n.getAttribute('dateupload'); 55 this.dateupload = j.dateupload;
58 this.datetaken = n.getAttribute('datetaken'); this.datetakengranularity = n.getAttribute('datetakengranularity'); 56 this.datetaken=j.datetaken; j.datetakengranularity=j.datetakengranularity;
59 this.ownername = n.getAttribute('ownername'); 57 this.ownername=j.ownername;
60 this.iconserver = n.getAttribute('iconserver'); 58 this.iconserver=j.iconserver;
61 this.originalformat = n.getAttribute('originalformat'); 59 this.originalformat=j.originalformat;
62 this.lastupdate = n.getAttribute('lastupdate'); 60 this.lastupdate=j.lastupdate;
63 }, 61 },
64 fromNode_: function(n) { 62 fromJSON_: function(j) {
65 var t;
66 // TODO: @rotation @isfavorite
67 this.owner = {}; 63 this.owner = {};
68 t = n.getElementsByTagName('owner').item(0); 64 var t;
69 if(t) { 65 if((t=j.owner)) {
70 this.owner.nsid=t.getAttribute('nsid'); 66 this.owner.nsid=t.nsid;
71 this.owner.username=t.getAttribute('username'); 67 this.owner.username=t.username; this.owner.realname=t.realname;
72 this.owner.realname=t.getAttribute('realname'); 68 this.owner.location=t.location;
73 this.owner.location=t.getAttribute.location;
74 }
75 t = n.getElementsByTagName('description').item(0);
76 if(t && t.firstChild) {
77 this.description = t.firstChild.nodeValue;
78 } 69 }
70 if((t=j.description)) this.description=t._content;
71 // TODO: @rotation @isfavorite
79 // TODO: visibility/@ispublic visibility/@isfriend visibility/@isfamily 72 // TODO: visibility/@ispublic visibility/@isfriend visibility/@isfamily
80 // TODO: dates/@posted dates/@taken dates/@takengranularity dates/@lastupdate 73 // TODO: dates/@posted dates/@taken dates/@takengranularity dates/@lastupdate
81 // TODO: permissions/@permcomment permsiions/@permaddmeta 74 // TODO: permissions/@permcomment permsiions/@permaddmeta
82 // TODO: editability/@canaddcomment editability/@canaddmeta 75 // TODO: editability/@canaddcomment editability/@canaddmeta
83 // TODO: comments 76 // TODO: comments
84 // TODO: notes/note/@id notes/note/@author notes/note/@authorname 77 // TODO: notes/note/@id notes/note/@author notes/note/@authorname
85 // TODO: notes/note/@x notes/note/@y notes/note/@w notes/note/@h 78 // TODO: notes/note/@x notes/note/@y notes/note/@w notes/note/@h
86 // TODO: notes/note 79 // TODO: notes/note
87 // TODO: tags/tag/@id tags/tag/@author tags/tag/@raw tags/tag 80 // TODO: tags/tag/@id tags/tag/@author tags/tag/@raw tags/tag
88 // TODO: urls/url/@type urls/url 81 // TODO: urls/url/@type urls/url
89 } 82 }
90}; 83};
91 84
92function Flickr() { } 85function Flickr() { }
93Flickr.prototype = { 86Flickr.prototype = {
94 87
95 rest_url: 'http://www.flickr.com/services/rest/', 88 rest_url: 'http://www.flickr.com/services/rest/',
96 auth_url: 'http://flickr.com/services/auth/', 89 auth_url: 'http://flickr.com/services/auth/',
97 photo_url: 'http://static.flickr.com/', 90 photo_url: 'http://static.flickr.com/',
98 photos_url: 'http://www.flickr.com/photos/', 91 photos_url: 'http://www.flickr.com/photos/',
99 upload_url: 'http://www.flickr.com/services/upload/', 92 upload_url: 'http://www.flickr.com/services/upload/',
100 uploader_edit_url: 'http://www.flickr.com/tools/uploader_edit.gne', 93 uploader_edit_url: 'http://www.flickr.com/tools/uploader_edit.gne',
101 94
102 api_sig: function(paramstr) { 95 api_sig: function(paramstr) {
103 return MD5(toutf8(this.api_shs+paramstr)); 96 return MD5(toutf8(this.api_shs+paramstr));
104 }, 97 },
105 api_call_url: function(params,url) { 98 api_call_url: function(params,url) {
106 params.api_key = this.api_key; 99 params.api_key = this.api_key;
107 var pp = new Array(); 100 var pp = new Array();
108 for(var p in params) { 101 for(var p in params) {
109 pp.push(p); 102 pp.push(p);
110 } 103 }
111 var pstr = ''; 104 var pstr = '';
112 var rv = (url?url:this.rest_url)+'?'; 105 var rv = (url?url:this.rest_url)+'?';
113 for(var p in pp.sort()) { 106 for(var p in pp.sort()) {
114 var pn = pp[p]; 107 var pn = pp[p];
115 pstr += pn+params[pn]; 108 pstr += pn+params[pn];
116 rv += pn+'='+params[pn]+'&'; 109 rv += pn+'='+params[pn]+'&';
117 } 110 }
118 rv += 'api_sig='+this.api_sig(pstr); 111 rv += 'api_sig='+this.api_sig(pstr);
119 return rv; 112 return rv;
120 }, 113 },
121 api_call_json: function(params,on_success,on_failure) { 114 api_call_json: function(params,on_success,on_failure) {
122 if(params.auth_token=='default') params.auth_token=this.token; 115 if(params.auth_token=='default') params.auth_token=this.token;
123 params.format = 'json'; params.nojsoncallback=1; 116 params.format = 'json'; params.nojsoncallback=1;
124 var x = new XMLHttpRequest(); 117 var x = new XMLHttpRequest();
125 x.open("GET",this.api_call_url(params)); 118 x.open("GET",this.api_call_url(params));
126 x.onreadystatechange=function() { 119 x.onreadystatechange=function() {
127 if(x.readyState!=4) return false; 120 if(x.readyState!=4) return false;
128 if(x.status==200) { 121 if(x.status==200) {
129 var rsp=JSON.parse(x.responseText); 122 var rsp=JSON.parse(x.responseText);
130 if(rsp.stat=='ok') 123 if(rsp.stat=='ok')
131 on_success && on_success(x,rsp); 124 on_success && on_success(x,rsp);
132 else 125 else
133 on_failure && on_failure(rsp,rsp.stat,rsp.code,rsp.message); 126 on_failure && on_failure(rsp,rsp.stat,rsp.code,rsp.message);
134 }else 127 }else
135 on_failure && on_failure(x); 128 on_failure && on_failure(x);
136 return true; 129 return true;
137 }; 130 };
138 x.send(null); 131 x.send(null);
139 return true; 132 return true;
140 }, 133 },
141 api_call: function(params, on_success, on_failure) { 134 api_call: function(params, on_success, on_failure) {
142 if(params.auth_token == 'default') 135 if(params.auth_token == 'default')
143 params.auth_token = this.token; 136 params.auth_token = this.token;
144 var x = new XMLHttpRequest(); 137 var x = new XMLHttpRequest();
145 x.open("GET",this.api_call_url(params)); 138 x.open("GET",this.api_call_url(params));
146 x.onreadystatechange=function() { 139 x.onreadystatechange=function() {
147 if(x.readyState!=4) return false; 140 if(x.readyState!=4) return false;
148 if(x.status==200) { 141 if(x.status==200) {
149 var stat = x.responseXML.firstChild.getAttribute('stat'); 142 var stat = x.responseXML.firstChild.getAttribute('stat');
150 if(stat=='ok') { 143 if(stat=='ok') {
151 if(on_success) on_success(x); 144 if(on_success) on_success(x);
152 }else{ 145 }else{
153 var e = x.responseXML.getElementsByTagName('err').item(0); 146 var e = x.responseXML.getElementsByTagName('err').item(0);
154 var ecode = e.getAttribute('code'); 147 var ecode = e.getAttribute('code');
155 var emsg = e.getAttribute('msg'); 148 var emsg = e.getAttribute('msg');
156 dump(params.method+' failed: '+ecode+' '+emsg+'\n'); 149 dump(params.method+' failed: '+ecode+' '+emsg+'\n');
157 if(on_failure) on_failure(x,stat,ecode,emsg); 150 if(on_failure) on_failure(x,stat,ecode,emsg);
158 } 151 }
159 }else{ 152 }else{
160 if(on_failure) on_failure(x); 153 if(on_failure) on_failure(x);
161 } 154 }
162 return true; 155 return true;
163 } 156 }
164 x.send(null); 157 x.send(null);
165 return true; 158 return true;
166 }, 159 },
167 160
168 frob: null, 161 frob: null,
169 authorize_0: function(perms, on_s, on_f) { 162 authorize_0: function(perms, on_s, on_f) {
170 var _this = this; 163 var _this = this;
171 this.api_call( 164 this.api_call(
172 { method: 'flickr.auth.getFrob' }, 165 { method: 'flickr.auth.getFrob' },
173 function(x) { 166 function(x) {
174 _this.frob = xp_str('/rsp/frob',x.responseXML); 167 _this.frob = xp_str('/rsp/frob',x.responseXML);
175 var u = _this.api_call_url( 168 var u = _this.api_call_url(
176 { frob: _this.frob, perms: perms?perms:'delete' }, _this.auth_url ); 169 { frob: _this.frob, perms: perms?perms:'delete' }, _this.auth_url );
177 if(on_s) on_s(x,_this.frob,u); 170 if(on_s) on_s(x,_this.frob,u);
178 }, function(x,s,c,m) { 171 }, function(x,s,c,m) {
179 if(on_f) on_f(x,s,c,m); 172 if(on_f) on_f(x,s,c,m);
180 } 173 }
181 ); 174 );
182 }, 175 },
183 token: null, 176 token: null,
184 perms: null, 177 perms: null,
185 user: null, 178 user: null,
186 authorize_1: function(on_s, on_f) { 179 authorize_1: function(on_s, on_f) {
187 var _this = this; 180 var _this = this;
188 this.api_call( 181 this.api_call(
189 { method: 'flickr.auth.getToken', frob: this.frob }, 182 { method: 'flickr.auth.getToken', frob: this.frob },
190 function(x) { 183 function(x) {
191 _this.token = xp_str('/rsp/auth/token',x.responseXML); 184 _this.token = xp_str('/rsp/auth/token',x.responseXML);
192 _this.perms = xp_str('/rsp/auth/perms',x.responseXML); 185 _this.perms = xp_str('/rsp/auth/perms',x.responseXML);
193 var u = xp_node('/rsp/auth/user',x.responseXML); 186 var u = xp_node('/rsp/auth/user',x.responseXML);
194 _this.user = { 187 _this.user = {
195 nsid: u.getAttribute('nsid'), 188 nsid: u.getAttribute('nsid'),
196 username: u.getAttribute('username'), 189 username: u.getAttribute('username'),
197 fullname: u.getAttribute('fullname') 190 fullname: u.getAttribute('fullname')
198 }; 191 };
199 if(on_s) on_s(x); 192 if(on_s) on_s(x);
200 }, function(x,s,c,m) { 193 }, function(x,s,c,m) {
201 if(on_f) on_f(x,s,c,m); 194 if(on_f) on_f(x,s,c,m);
202 } 195 }
203 ); 196 );
204 }, 197 },
205 198
206 prefs: Components.classes['@mozilla.org/preferences-service;1'].getService( 199 prefs: Components.classes['@mozilla.org/preferences-service;1'].getService(
207 Components.interfaces.nsIPrefBranch 200 Components.interfaces.nsIPrefBranch
208 ), 201 ),
209 prefs_root: 'net.klever.kin.flickr', 202 prefs_root: 'net.klever.kin.flickr',
210 save_token: function() { 203 save_token: function() {
211 // TODO: don't clear when there's nothing to clear or catch exceptions 204 // TODO: don't clear when there's nothing to clear or catch exceptions
212 if(this.token) 205 if(this.token)
213 this.prefs.setCharPref(this.prefs_root+'.auth_token',this.token); 206 this.prefs.setCharPref(this.prefs_root+'.auth_token',this.token);
214 else 207 else
215 this.prefs.clearUserPref(this.prefs_root+'.auth_token'); 208 this.prefs.clearUserPref(this.prefs_root+'.auth_token');
216 if(this.perms) 209 if(this.perms)
217 this.prefs.setCharPref(this.prefs_root+'.auth_perms',this.perms); 210 this.prefs.setCharPref(this.prefs_root+'.auth_perms',this.perms);
218 else 211 else
219 this.prefs.clearUserPref(this.prefs_root+'.auth_perms'); 212 this.prefs.clearUserPref(this.prefs_root+'.auth_perms');
220 if(this.user && this.user.nsid!=null && this.user.nsid!=undefined) 213 if(this.user && this.user.nsid!=null && this.user.nsid!=undefined)
221 this.prefs.setCharPref(this.prefs_root+'.auth_user.nsid',this.user.nsid); 214 this.prefs.setCharPref(this.prefs_root+'.auth_user.nsid',this.user.nsid);
222 else 215 else
223 this.prefs.clearUserPref(this.prefs_root+'.auth_user.nsid'); 216 this.prefs.clearUserPref(this.prefs_root+'.auth_user.nsid');
224 if(this.user && this.user.username!=null && this.user.username!=undefined) 217 if(this.user && this.user.username!=null && this.user.username!=undefined)
225 this.prefs.setCharPref(this.prefs_root+'.auth_user.username',this.user.username); 218 this.prefs.setCharPref(this.prefs_root+'.auth_user.username',this.user.username);
226 else 219 else
227 this.prefs.clearUserPref(this.prefs_root+'.auth_user.username'); 220 this.prefs.clearUserPref(this.prefs_root+'.auth_user.username');
228 if(this.user && this.user.fullname!=null && this.user.fullname!=undefined) 221 if(this.user && this.user.fullname!=null && this.user.fullname!=undefined)
229 this.prefs.setCharPref(this.prefs_root+'.auth_user.fullname',this.user.fullname); 222 this.prefs.setCharPref(this.prefs_root+'.auth_user.fullname',this.user.fullname);
230 else 223 else
231 this.prefs.clearUserPref(this.prefs_root+'.auth_user.fullname'); 224 this.prefs.clearUserPref(this.prefs_root+'.auth_user.fullname');
232 }, 225 },
233 _reset_token: function() { 226 _reset_token: function() {
234 this.token = null; this.perms = null; this.user = null; 227 this.token = null; this.perms = null; this.user = null;
235 return false; 228 return false;
236 }, 229 },
237 load_token: function() { 230 load_token: function() {
238 try { 231 try {
239 if(this.prefs.getPrefType(this.prefs_root+'.auth_token')!=this.prefs.PREF_STRING) 232 if(this.prefs.getPrefType(this.prefs_root+'.auth_token')!=this.prefs.PREF_STRING)
240 return this._reset_token(); 233 return this._reset_token();
241 this.token = this.prefs.getCharPref(this.prefs_root+'.auth_token'); 234 this.token = this.prefs.getCharPref(this.prefs_root+'.auth_token');
242 if(this.prefs.getPrefType(this.prefs_root+'.auth_perms')!=this.prefs.PREF_STRING) 235 if(this.prefs.getPrefType(this.prefs_root+'.auth_perms')!=this.prefs.PREF_STRING)
243 return this._reset_token(); 236 return this._reset_token();
244 this.perms = this.prefs.getCharPref(this.prefs_root+'.auth_perms'); 237 this.perms = this.prefs.getCharPref(this.prefs_root+'.auth_perms');
245 if(this.prefs.getPrefType(this.prefs_root+'.auth_user.nsid')!=this.prefs.PREF_STRING) 238 if(this.prefs.getPrefType(this.prefs_root+'.auth_user.nsid')!=this.prefs.PREF_STRING)
246 return this._reset_token(); 239 return this._reset_token();
247 this.user = new Object(); 240 this.user = new Object();
248 this.user.nsid = this.prefs.getCharPref(this.prefs_root+'.auth_user.nsid'); 241 this.user.nsid = this.prefs.getCharPref(this.prefs_root+'.auth_user.nsid');
249 if(this.prefs.getPrefType(this.prefs_root+'.auth_user.username')!=this.prefs.PREF_STRING) 242 if(this.prefs.getPrefType(this.prefs_root+'.auth_user.username')!=this.prefs.PREF_STRING)
250 return this._reset_token(); 243 return this._reset_token();
251 this.user.username = this.prefs.getCharPref(this.prefs_root+'.auth_user.username'); 244 this.user.username = this.prefs.getCharPref(this.prefs_root+'.auth_user.username');
252 if(this.prefs.getPrefType(this.prefs_root+'.auth_user.fullname')!=this.prefs.PREF_STRING) 245 if(this.prefs.getPrefType(this.prefs_root+'.auth_user.fullname')!=this.prefs.PREF_STRING)
253 return this._reset_token(); 246 return this._reset_token();
254 this.user.fullname = this.prefs.getCharPref(this.prefs_root+'.auth_user.fullname'); 247 this.user.fullname = this.prefs.getCharPref(this.prefs_root+'.auth_user.fullname');
255 }catch(e) { return this._reset_token(); } 248 }catch(e) { return this._reset_token(); }
256 return true; 249 return true;
257 }, 250 },
258 reset_token: function() { 251 reset_token: function() {
259 this._reset_token(); 252 this._reset_token();
260 this.save_token(); 253 this.save_token();
261 }, 254 },
262 255
263 get_photo_url: function(ser,id,sec,sfx,ext) { 256 get_photo_url: function(ser,id,sec,sfx,ext) {
264 var rv = this.photo_url + ser + '/' + id + '_' + sec; 257 var rv = this.photo_url + ser + '/' + id + '_' + sec;
265 if(sfx && sfx!='_') rv += '_'+sfx; 258 if(sfx && sfx!='_') rv += '_'+sfx;
266 rv += ext?'.'+ext:'.jpg'; 259 rv += ext?'.'+ext:'.jpg';
267 return rv; 260 return rv;
268 }, 261 },
269 get_image_url: function(o,sfx) { 262 get_image_url: function(o,sfx) {
270 return this.get_photo_url( 263 return this.get_photo_url(
271 o.server, 264 o.server,
272 (o instanceof Photoset)? o.primary : o.id, 265 (o instanceof Photoset)? o.primary : o.id,
273 o.secret, 266 o.secret,
274 sfx, 267 sfx,
275 (sfx=='o')?o.originalformat:null 268 (sfx=='o')?o.originalformat:null
276 ); 269 );
277 }, 270 },
278 get_photo_page_url: function(p) { 271 get_photo_page_url: function(p) {
279 if(p instanceof Photo) { 272 if(p instanceof Photo) {
280 // TODO: track photoset and user owner id from there? 273 // TODO: track photoset and user owner id from there?
281 // The approach below is sheerly wrong. 274 // The approach below is sheerly wrong.
282 var o = this.user.nsid; 275 var o = this.user.nsid;
283 if(p.owner && p.owner.nsid) o = p.owner.nsid; 276 if(p.owner && p.owner.nsid) o = p.owner.nsid;
284 var rv = this.photos_url + o +'/' + p.id; 277 var rv = this.photos_url + o +'/' + p.id;
285 return rv; 278 return rv;
286 }else // TODO: take owner into account? 279 }else // TODO: take owner into account?
287 return this.photos_url + this.user.nsid + '/' + p; 280 return this.photos_url + this.user.nsid + '/' + p;
288 }, 281 },
289 make_photo_url: function(p,sfx) { 282 make_photo_url: function(p,sfx) {
290 if(sfx=='p') 283 if(sfx=='p')
291 return this.get_photo_page_url(p); 284 return this.get_photo_page_url(p);
292 else 285 else
293 return this.get_image_url(p,sfx); 286 return this.get_image_url(p,sfx);
294 }, 287 },
295 make_photoset_url: function(ps) { 288 make_photoset_url: function(ps) {
296 // TODO: allow for using someone else's photoset? 289 // TODO: allow for using someone else's photoset?
297 return this.photos_url+this.user.nsid+'/sets/'+ps.id; 290 return this.photos_url+this.user.nsid+'/sets/'+ps.id;
298 }, 291 },
299 make_uploader_edit_url: function(pid) { 292 make_uploader_edit_url: function(pid) {
300 // TODO: handle arrays 293 // TODO: handle arrays
301 return this.uploader_edit_url+'?ids='+pid; 294 return this.uploader_edit_url+'?ids='+pid;
302 }, 295 },
303 296
304 upload_file: function(f,fa,on_success,on_failure) { 297 upload_file: function(f,fa,on_success,on_failure) {
305 try { 298 try {
306 var fi = Components.classes["@mozilla.org/file/local;1"] 299 var fi = Components.classes["@mozilla.org/file/local;1"]
307 .createInstance(Components.interfaces.nsILocalFile); 300 .createInstance(Components.interfaces.nsILocalFile);
308 fi.initWithPath( f ); 301 fi.initWithPath( f );
309 var st = Components.classes["@mozilla.org/network/file-input-stream;1"] 302 var st = Components.classes["@mozilla.org/network/file-input-stream;1"]
310 .createInstance(Components.interfaces.nsIFileInputStream); 303 .createInstance(Components.interfaces.nsIFileInputStream);
311 st.init(fi,0x01,00004,null); 304 st.init(fi,0x01,00004,null);
312 var bis = Components.classes["@mozilla.org/binaryinputstream;1"] 305 var bis = Components.classes["@mozilla.org/binaryinputstream;1"]
313 .createInstance(Components.interfaces.nsIBinaryInputStream); 306 .createInstance(Components.interfaces.nsIBinaryInputStream);
314 bis.setInputStream(st); 307 bis.setInputStream(st);
315 308
316 // allocate and initialize temp storage string 309 // allocate and initialize temp storage string
317 var pbs = Components.classes["@mozilla.org/storagestream;1"] 310 var pbs = Components.classes["@mozilla.org/storagestream;1"]
318 .createInstance(Components.interfaces.nsIStorageStream); 311 .createInstance(Components.interfaces.nsIStorageStream);
319 pbs.init(1024,10000000,null); 312 pbs.init(1024,10000000,null);
320 // create output stream 313 // create output stream
321 var pbos = pbs.getOutputStream(0); 314 var pbos = pbs.getOutputStream(0);
322 // and a binaryoutputstream interface 315 // and a binaryoutputstream interface
323 var pbbos = Components.classes["@mozilla.org/binaryoutputstream;1"] 316 var pbbos = Components.classes["@mozilla.org/binaryoutputstream;1"]
324 .createInstance(Components.interfaces.nsIBinaryOutputStream); 317 .createInstance(Components.interfaces.nsIBinaryOutputStream);
325 pbbos.setOutputStream(pbos); 318 pbbos.setOutputStream(pbos);
326 319
327 /* create POST body */ 320 /* create POST body */
328 var boundarytoken = 'kadaroloongazaduviaxamma'; 321 var boundarytoken = 'kadaroloongazaduviaxamma';
329 var boundary = '--'+boundarytoken; 322 var boundary = '--'+boundarytoken;
330 var b = ''; 323 var b = '';
331 324
332 var parms = { api_key: this.api_key, auth_token: this.token }; 325 var parms = { api_key: this.api_key, auth_token: this.token };
333 for(var p in fa) parms[p] = fa[p]; 326 for(var p in fa) parms[p] = fa[p];
334 var pns = new Array(); 327 var pns = new Array();