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 /content/flickr.js | |
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/flickr.js | 65 |
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,110 +1,103 @@ | |||
1 | /* | 1 | /* |
2 | * Photoset | 2 | * Photoset |
3 | */ | 3 | */ |
4 | 4 | ||
5 | function Photoset(s) { | 5 | function 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 | } |
11 | Photoset.prototype = { | 11 | Photoset.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 | */ |
34 | function Photo(s) { | 32 | function 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 | } |
40 | Photo.prototype = { | 38 | Photo.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 | ||
92 | function Flickr() { } | 85 | function Flickr() { } |
93 | Flickr.prototype = { | 86 | Flickr.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 | } |