public
Description: jQuery Douban plugin
Homepage: http://code.google.com/p/jquery-douban
Clone URL: git://github.com/wuyuntao/jquery-douban.git
Added collection class
wuyuntao (author)
Sat Nov 22 05:16:33 -0800 2008
commit  57c78ac10cc19979fc013847355d155b1bde395d
tree    edfaede572a095f5b6fe1f7f9b99b3a86d60173c
parent  b9c874a5c33fba5cdf16f841dd63c8a11d9fa8f9
...
398
399
400
401
402
403
404
...
828
829
830
831
 
832
833
834
835
836
837
838
839
840
...
1319
1320
1321
1322
 
1323
1324
1325
...
1340
1341
1342
1343
1344
1345
 
1346
1347
1348
 
1349
1350
1351
 
1352
1353
1354
...
1535
1536
1537
1538
1539
 
1540
 
1541
1542
1543
...
398
399
400
 
401
402
403
...
827
828
829
 
830
831
832
833
834
835
 
836
837
838
...
1317
1318
1319
 
1320
1321
1322
1323
...
1338
1339
1340
 
1341
 
1342
1343
1344
 
1345
1346
1347
 
1348
1349
1350
1351
...
1532
1533
1534
 
1535
1536
1537
1538
1539
1540
1541
0
@@ -398,7 +398,6 @@ var BaseService = $.class({
0
      */
0
     _add: function(data, url, model) {
0
         if (typeof data == 'object') data = model.createXml(data);
0
-        if (model == Review) console.debug(data, url, model);
0
         var json = this._service.post(url, data);
0
         return this._response(json, model);
0
     },
0
@@ -828,13 +827,12 @@ var DoubanObject = $.class({
0
     },
0
 
0
     getTags: function() {
0
-        if (!this._feed || !this._feed['db:tag']) return;
0
+        if (!this._feed || !this._feed['db:tag']) return [];
0
         var tags = [], entries = this._feed['db:tag'];
0
         for (var i = 0, len = entries.length; i < len; i++)
0
             tags.push(new Tag(entries[i]['@name'], entries[i]['@count']));
0
         return tags;
0
     }
0
-
0
 });
0
 
0
 var DoubanObjectEntries = $.class(DoubanObject, {
0
@@ -1319,7 +1317,7 @@ var Collection = $.class(DoubanObject, {
0
     },
0
 
0
     getStatus: function() {
0
-        return this.attr('status');
0
+        return this.getAttr('db:status');
0
     }
0
 });
0
 // Class methods
0
@@ -1340,15 +1338,14 @@ Collection.createXml = function(data) {
0
     else if (data.subject.match(/^\d+$/)) var id = GET_REVIEW_URL.replace(/\{ID\}/, data.subject);
0
     else var id = data.subject;
0
     var xml = '<?xml version="1.0" encoding="UTF-8"?><entry xmlns:ns0="http://www.w3.org/2005/Atom"><db:subject xmlns:db="http://www.douban.com/xmlns/"><id>{ID}</id></db:subject><db:status>{STATUS}</db:status>{TAGS}<content>{CONTENT}</content><gd:rating xmlns:gd="http://schemas.google.com/g/2005" value="{RATING}" ></gd:rating><db:attribute name="privacy">{IS_PRIVATE}</db:attribute></entry>';
0
-    var tag = '<db:tags>{TAG}</db:tags>';
0
     for (var i = 0, tags = '', len = data.tags.length; i < len; i++) {
0
-        tags += tag.replace(/\{TAG\}/, data.tags[i]);
0
+        tags += '<db:tags>' + data.tags[i] + '</db:tags>';
0
     }
0
     return xml.replace(/\{ID\}/, id)
0
-              .replace(/\{status\}/, data.status)
0
+              .replace(/\{STATUS\}/, data.status)
0
               .replace(/\{CONTENT\}/, data.content)
0
               .replace(/\{RATING\}/, data.rating)
0
-              .replace(/\{TAGS\}/, data.tags)
0
+              .replace(/\{TAGS\}/, tags)
0
               .replace(/\{IS_PRIVATE\}/, data.isPrivate ? 'private' : 'public');
0
 };
0
 
0
@@ -1535,9 +1532,10 @@ var factoryDict = {
0
     'book': Book,
0
     'movie': Movie,
0
     'music': Music,
0
-    'note': Note,
0
     'user': User,
0
+    'note': Note,
0
     'review': Review,
0
+    'collection': Collection,
0
 };
0
 
0
 /* Factory method of jQuery Douban
...
344
345
346
347
348
349
350
...
494
495
496
 
 
 
 
 
 
 
 
 
 
 
 
 
497
...
344
345
346
 
347
348
349
...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
0
@@ -344,7 +344,6 @@ test("test review api", function() {
0
     // delete
0
     service.review.delete(review2);
0
     var review4 = service.review.get(review2);
0
-    console.debug(review4);
0
     ok(!review4, "review deleted");
0
 });
0
 
0
@@ -494,4 +493,17 @@ test("test review object", function() {
0
     equals(xml, '<?xml version="1.0" encoding="UTF-8"?><entry xmlns:ns0="http://www.w3.org/2005/Atom"><db:subject xmlns:db="http://www.douban.com/xmlns/"><id>http://api.douban.com/book/subject/1452923</id></db:subject><content>内容</content><gd:rating xmlns:gd="http://schemas.google.com/g/2005" value="3" ></gd:rating><title>标题</title></entry>', "get xml ok");
0
 });
0
 
0
+test("test collection object", function() {
0
+    var json = {"updated":{"$t":"2006-03-30T00:10:03+08:00"},"author":{"link":[{"@rel":"self","@href":"http://api.douban.com/people/1025061"},{"@rel":"alternate","@href":"http://www.douban.com/people/Fenng/"},{"@rel":"icon","@href":"http://otho.douban.com/icon/u1025061-3.jpg"}],"uri":{"$t":"http://api.douban.com/people/1025061"},"name":{"$t":"Fenng(DBAnotes)"}},"title":{"$t":"Fenng(DBAnotes) 想读 国际经济学(第五版)"},"db:subject":{"category":{"@scheme":"http://www.douban.com/2007#kind","@term":"http://www.douban.com/2007#book"},"author":[{"name":{"$t":"(美)克鲁格曼"}}],"title":{"$t":"国际经济学(第五版)"},"link":[{"@rel":"self","@href":"http://api.douban.com/book/subject/1263907"},{"@rel":"alternate","@href":"http://www.douban.com/subject/1263907/"},{"@rel":"image","@href":"http://otho.douban.com/spic/s2701851.jpg"}],"db:attribute":[{"$t":"7300040187","@name":"isbn10"},{"$t":"9787300040189","@name":"isbn13"},{"$t":"79.0","@name":"price"},{"$t":"(美)克鲁格曼","@name":"author"},{"$t":"中国人民大学出版社","@name":"publisher"},{"$t":"海闻等","@name":"translator"},{"$t":"2002-11-1","@name":"pubdate"}],"id":{"$t":"http://api.douban.com/book/subject/1263907"}},"link":[{"@rel":"self","@href":"http://api.douban.com/collection/2165271"},{"@rel":"http://www.douban.com/2007#subject","@href":"http://api.douban.com/book/subject/1263907"}],"id":{"$t":"http://api.douban.com/collection/2165271"},"db:status":{"$t":"wish"}};
0
+    
0
+    var collection = $.douban('collection', json);
0
+    equals(collection.id, "http://api.douban.com/collection/2165271");
0
+    equals(collection.owner.id, "http://api.douban.com/people/1025061");
0
+    equals(collection.subject.id, "http://api.douban.com/book/subject/1263907");
0
+    equals(collection.status, "wish");
0
+    equals(collection.tags.length, 0);
0
+
0
+    var xml = $.douban.createXml('collection', { subject: '条目', status: '状态', content: '评价', rating: 5, tags: ['标签一', '标签二', '标签三'], isPrivate: true });
0
+    equals(xml, '<?xml version="1.0" encoding="UTF-8"?><entry xmlns:ns0="http://www.w3.org/2005/Atom"><db:subject xmlns:db="http://www.douban.com/xmlns/"><id>条目</id></db:subject><db:status>状态</db:status><db:tags>标签一</db:tags><db:tags>标签二</db:tags><db:tags>标签三</db:tags><content>评价</content><gd:rating xmlns:gd="http://schemas.google.com/g/2005" value="5" ></gd:rating><db:attribute name="privacy">private</db:attribute></entry>');
0
+});
0
 // vim: foldmethod=indent

Comments