Twitter Client
by Couto
HTML
<script src="https://gist.github.com/raw/661855/9ef0e862a574c5148e5945cb8306969f6d642fda/jquery.ba-tinypubsub.js"></script>
JavaScript
function Twitter(screenname) {
var that = this;
this.screenName = screenname;
this.request = function(request) {
$.ajax({
url: 'http://api.twitter.com/1' + request + '.json',
type: 'get',
dataType: 'jsonp',
data: "screen_name=" + that.screenName,
success: function(msg) {
$.publish('/twitter/timeline', [msg]);
}
});
};
/* Public API */
return {
screenName: that.screenName,
request: that.request
};
}
function Wall() {
var that = this,
d = document;
this.createTweet = function(Obj) {
var li = d.createElement('li'),
img = d.createElement('img'),
h3 = d.createElement('h3'),
p = d.createElement('p'),
small = d.createElement('small'),
time = d.createElement('time'),
span = d.createElement('span');
li.className = 'tweet';
img.src = Obj.user.profile_image_url;
h3.innerHTML = Obj.user.name;
p.innerHTML = Obj.text;
time.dateTime = time.innerHTML = Obj.created_at;
span.innerHTML = 'from ' + Obj.source;
small.appendChild(time);
small.appendChild(span);
li.appendChild(img);
li.appendChild(h3);
li.appendChild(p);
li.appendChild(small);
return li;
};
this.createWall = function(Obj) {
var container = d.createElement('ul'),
i; /*Counter*/
for (i in Obj) {
if (Obj.hasOwnProperty(i)) {
container.appendChild(that.createTweet(Obj[i]));
}
}
d.body.appendChild(container);
};
return {
createWall: that.createWall
};
}
(function() {
var twitter = new Twitter('coutoantisocial'),
wall = new Wall();
twitter.request('/statuses/user_timeline');
$.subscribe('/twitter/timeline', wall.createWall);
}());