Commits

Artyom Semyonov committed 316d8b1

Rewrited for more services.

  • Participants
  • Parent commits 5921037

Comments (0)

Files changed (2)

File src/index.html

 
     <script type="text/javascript" src="http://static.tumblr.com/j8ivo9f/L27l0td25/moocore.js"></script>
     <script type="text/javascript" src="http://static.tumblr.com/j8ivo9f/ljBl0td33/moomore.js"></script>
-    <script type="text/javascript" src="http://static.tumblr.com/j8ivo9f/Fo3l0td8z/mooffdebate.js"></script>
+    <script type="text/javascript" src="mooffdebate.js"></script>
     <script type="text/javascript">
         window.addEvent('DOMContentLoaded', function(){
             // Comments for http://weirdfledgling.tumblr.com/post/514280739
             var comments = new Comments({
-                username: 'arsemyonov',
-                post_id: 514280739
+                services: [
+                    new FriendFeed({
+                        username: 'arsemyonov',
+                        post_id: 514280739
+                    }),
+                ]
             });
             comments.addEvent('complete', function(comments){
                 console.log(comments);

File src/mooffdebate.js

+
+var Service = new Class({
+    Implements: Options,
+    options: {
+        url: ''
+    },
+
+    initialize: function(options){
+        this.setOptions(options);
+    },
+
+    onComplete: function(base, data){
+        base.fireEvent('complete', this.parseResponse(data));
+    },
+
+    getRequestData: function(){
+        return {}
+    },
+
+    parseResponse: function(response){
+        return [];
+    }
+});
+
+var FriendFeed = new Class({
+    Extends: Service,
+    options: {
+        url: 'http://friendfeed-api.com/v2/search',
+        username: '',
+        post_id: 0,
+    },
+
+    getRequestData: function(){
+        return {
+            q: 'from:' + this.options.username + '+'
+                       + this.options.post_id
+        }
+    },
+
+    parseResponse: function(response){
+        return [response.entries[0].comments];
+    }
+});
 
 var Comments = new Class({
     Implements: [Options, Events],
     options: {},
+
     initialize: function(options){
         this.setOptions(options);
     },
 
-    fetch: function(callback){
-        new Request.JSONP({
-            url: 'http://friendfeed-api.com/v2/search',
-            data: {
-                q: 'from:' + this.options.username + '+'
-                           + this.options.post_id
-            },
-            onComplete: function(data){
-                this.fireEvent('complete', [
-                    data.entries[0].comments
-                ]);
-            }.bind(this)
-        }).send()
+    fetch: function(){
+        $each(this.options.services, function(service){
+            new Request.JSONP({
+                url: service.options.url,
+                data: service.getRequestData(),
+                onComplete: function(data){
+                    service.onComplete(this, data);
+                }.bind(this)
+            }).send()
+        }.bind(this));
     }
 });
+