author | Michael Krelin <hacker@klever.net> | 2011-08-28 12:17:34 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2011-08-28 12:17:34 (UTC) |
commit | aa13caca14bac3ed268ac6fb62f0270e40b24e48 (patch) (unidiff) | |
tree | edcfd094407b87cf9c49e9275c6d4b847fc82f29 | |
parent | 4152a504609522fab4a269dc88d13a1078a09452 (diff) | |
download | fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.zip fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.tar.gz fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.tar.bz2 |
made api calls mostly json-based
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | content/fireflix.js | 90 | ||||
-rw-r--r-- | content/flickr.js | 65 |
2 files changed, 66 insertions, 89 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 225e21c..283e930 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -125,10 +125,8 @@ var fireflix = { | |||
125 | canDropBeforeAfter: function(r,b) { return false }, | 125 | canDropBeforeAfter: function(r,b) { return false }, |
126 | 126 | ||
127 | importXPR: function(xp) { | 127 | import_json: function(jp) { |
128 | this.tree.beginUpdateBatch(); | 128 | this.tree.beginUpdateBatch(); |
129 | this.photos = new Array(); | 129 | this.photos = new Array(); |
130 | var n; while(n=xp.iterateNext()) { | 130 | for(var i in jp) this.photos.push(new Photo(jp[i])); |
131 | this.photos.push(new Photo(n)); | ||
132 | } | ||
133 | this.rowCount = this.photos.length; | 131 | this.rowCount = this.photos.length; |
134 | this.tree.endUpdateBatch(); | 132 | this.tree.endUpdateBatch(); |
@@ -136,6 +134,6 @@ var fireflix = { | |||
136 | }, | 134 | }, |
137 | load_photos: function(psid) { | 135 | load_photos: function(psid) { |
138 | var _this = this; | 136 | var that = this; |
139 | this.fireflix.flickr.api_call( | 137 | this.fireflix.flickr.api_call_json( |
140 | { | 138 | { |
141 | method: 'flickr.photosets.getPhotos', | 139 | method: 'flickr.photosets.getPhotos', |
@@ -143,12 +141,8 @@ var fireflix = { | |||
143 | photoset_id: psid, | 141 | photoset_id: psid, |
144 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' | 142 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' |
145 | }, function(xr) { | 143 | }, function(x,j) { |
146 | var x = xr.responseXML; | 144 | that.import_json(j.photoset.photo); |
147 | var xp = x.evaluate( | ||
148 | '/rsp/photoset/photo', x, null, | ||
149 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | ||
150 | _this.importXPR(xp); | ||
151 | }, function(x,s,c,m) { | 145 | }, function(x,s,c,m) { |
152 | _this.fireflix.flickr_failure(x,s,c,m); | 146 | that.fireflix.flickr_failure(x,s,c,m); |
153 | } | 147 | } |
154 | ); | 148 | ); |
@@ -201,27 +195,21 @@ var fireflix = { | |||
201 | canDropBeforeAfter: function(r,b) { return false }, | 195 | canDropBeforeAfter: function(r,b) { return false }, |
202 | 196 | ||
203 | importXPR: function(xp) { | 197 | import_json: function(j) { |
204 | this.tree.beginUpdateBatch(); | 198 | this.tree.beginUpdateBatch(); |
205 | this.sets = new Array(); | 199 | this.sets = new Array(); |
206 | var n; while(n=xp.iterateNext()) { | 200 | for(var i in j) this.sets.push(new Photoset(j[i])); |
207 | this.sets.push(new Photoset(n)); | ||
208 | } | ||
209 | this.rowCount = this.sets.length; | 201 | this.rowCount = this.sets.length; |
210 | this.tree.endUpdateBatch(); | 202 | this.tree.endUpdateBatch(); |
211 | }, | 203 | }, |
212 | refresh_sets: function() { | 204 | refresh_sets: function() { |
213 | var _this = this; | 205 | var that = this; |
214 | this.fireflix.flickr.api_call( | 206 | this.fireflix.flickr.api_call_json( |
215 | { | 207 | { |
216 | method: 'flickr.photosets.getList', | 208 | method: 'flickr.photosets.getList', |
217 | auth_token: 'default' | 209 | auth_token: 'default' |
218 | }, function(xr) { | 210 | }, function(x,j) { |
219 | var x = xr.responseXML; | 211 | that.import_json(j.photosets.photoset); |
220 | var xp = x.evaluate( | ||
221 | '/rsp/photosets/photoset', x, null, | ||
222 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | ||
223 | _this.importXPR(xp); | ||
224 | }, function(x,s,c,m) { | 212 | }, function(x,s,c,m) { |
225 | _this.fireflix.flickr_failure(x,s,c,m); | 213 | that.fireflix.flickr_failure(x,s,c,m); |
226 | } | 214 | } |
227 | ); | 215 | ); |
@@ -788,5 +776,5 @@ var fireflix = { | |||
788 | canDropBeforeAfter: function(r,b) { return false }, | 776 | canDropBeforeAfter: function(r,b) { return false }, |
789 | 777 | ||
790 | importXPR: function(xp) { | 778 | import_json: function(jp) { |
791 | this.selection.clearSelection(); | 779 | this.selection.clearSelection(); |
792 | this.selection.currentIndex = -1; | 780 | this.selection.currentIndex = -1; |
@@ -794,6 +782,6 @@ var fireflix = { | |||
794 | this.tree.beginUpdateBatch(); | 782 | this.tree.beginUpdateBatch(); |
795 | this.photos = new Array(); | 783 | this.photos = new Array(); |
796 | var n; while(n=xp.iterateNext()) { | 784 | for(var i in jp) { |
797 | this.photos.push(new Photo(n)); | 785 | this.photos.push(new Photo(jp[i])); |
798 | } | 786 | } |
799 | this.rowCount = this.photos.length; | 787 | this.rowCount = this.photos.length; |
@@ -824,20 +812,17 @@ var fireflix = { | |||
824 | }, | 812 | }, |
825 | perform_search: function(p) { | 813 | perform_search: function(p) { |
826 | var _this = this; | 814 | var that = this; |
827 | this.fireflix.flickr.api_call( p, | 815 | this.fireflix.flickr.api_call_json( p, |
828 | function(xr) { | 816 | function(x,j) { |
829 | var x = xr.responseXML; | 817 | that.import_json(j.photos.photo); |
830 | var xp = xp_nodes('/rsp/photos/photo',x); | 818 | that.tree.ensureRowIsVisible(0); |
831 | _this.importXPR(xp); | 819 | var pp=j.photos; |
832 | _this.tree.ensureRowIsVisible(0); | 820 | that.paging.page = pp.page; that.paging.pages = pp.pages; |
833 | xp = xp_node('/rsp/photos',x); | 821 | that.paging.perpage = pp.perpage; |
834 | _this.paging.page = parseInt(xp.getAttribute('page')); | 822 | that.paging.total = pp.total; |
835 | _this.paging.pages = parseInt(xp.getAttribute('pages')); | 823 | that.update_paging(); |
836 | _this.paging.perpage = parseInt(xp.getAttribute('perpage')); | 824 | that.on_select(); |
837 | _this.paging.total = parseInt(xp.getAttribute('total')); | ||
838 | _this.update_paging(); | ||
839 | _this.on_select(); | ||
840 | }, function(x,s,c,m) { | 825 | }, function(x,s,c,m) { |
841 | _this.fireflix.flickr_failure(x,s,c,m); | 826 | that.fireflix.flickr_failure(x,s,c,m); |
842 | } | 827 | } |
843 | ); | 828 | ); |
@@ -899,6 +884,6 @@ var fireflix = { | |||
899 | var pid = p.id; | 884 | var pid = p.id; |
900 | var ci = this.selection.currentIndex; | 885 | var ci = this.selection.currentIndex; |
901 | var _this = this; | 886 | var that = this; |
902 | this.fireflix.flickr.api_call( | 887 | this.fireflix.flickr.api_call_json( |
903 | { | 888 | { |
904 | method: 'flickr.photos.getInfo', | 889 | method: 'flickr.photos.getInfo', |
@@ -906,13 +891,12 @@ var fireflix = { | |||
906 | photo_id: p.id, | 891 | photo_id: p.id, |
907 | secret: p.secret | 892 | secret: p.secret |
908 | }, function(xr) { | 893 | }, function(x,j) { |
909 | var pp = _this.photos[ci]; | 894 | var pp = that.photos[ci]; |
910 | if(ci==_this.selection.currentIndex && pp.id==pid) { | 895 | if(ci==that.selection.currentIndex && pp.id==pid) { |
911 | var n = xp_node('/rsp/photo',xr.responseXML); | 896 | pp.fromJSON_(j.photo); |
912 | pp.fromNode_(n); | 897 | that.render_description_frame(pp.description); |
913 | _this.render_description_frame(pp.description); | ||
914 | } | 898 | } |
915 | }, function(x,s,c,m) { | 899 | }, function(x,s,c,m) { |
916 | _this.fireflix.flickr_failure(x,s,c,m); | 900 | that.fireflix.flickr_failure(x,s,c,m); |
917 | } | 901 | } |
918 | ); | 902 | ); |
diff --git a/content/flickr.js b/content/flickr.js index 545144c..716874b 100644 --- a/content/flickr.js +++ b/content/flickr.js | |||
@@ -7,5 +7,5 @@ function Photoset(s) { | |||
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 | } |
11 | Photoset.prototype = { | 11 | Photoset.prototype = { |
@@ -17,13 +17,11 @@ Photoset.prototype = { | |||
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 | }; |
@@ -36,5 +34,5 @@ function Photo(s) { | |||
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 | } |
40 | Photo.prototype = { | 38 | Photo.prototype = { |
@@ -49,32 +47,27 @@ Photo.prototype = { | |||
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 |