twitter using resources

This commit is contained in:
Adam Abrons
2010-03-16 14:38:56 -07:00
parent 9e1f085ba6
commit 2df072e3f8
6 changed files with 21 additions and 20 deletions

View File

@@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="../../css/angular.css">
<script type="text/javascript" src="../../lib/underscore/underscore.js"></script>
<script type="text/javascript" src="../../lib/jquery/jquery-1.4.js"></script>
<script type="text/javascript" src="../../angular.js"></script>
<script type="text/javascript" src="../../src/angular-bootstrap.js"></script>
<script type="text/javascript" src="tweeterclient.js"></script>
</head>
<body ng-class="status" ng-init="mute={}" ng-watch="$anchor.user: tweets = fetchTweets($anchor.user)">

View File

@@ -1,28 +1,26 @@
function noop(){}
$(document).ready(function(){
function xhr(method, url, data, callback){
jQuery.getJSON(url, function(){
callback.apply(this, arguments);
scope.updateView();
})
}
var resourceFactory = new ResourceFactory({method: xhr});
var Tweeter = resourceFactory.route("http://twitter.com/statuses/:service:username.json", {}, {
home: {method:'GET', params: {service:'home_timeline'}, isArray:true },
user: {method:'GET', params: {service:'user_timeline/'}, isArray:true }
});
var scope = window.scope = angular.compile(document, {
location:angular.startUrlWatcher()
});
scope.getJSON = function(url, callback) {
var list = [];
var self = this;
self.set('status', 'fetching');
$.getJSON(url, function(response, code){
_(response).forEach(function(v,k){
list[k] = v;
});
(callback||noop)(response);
self.set('status', '');
self.updateView();
});
return list;
};
function fetchTweets(username){
return scope.getJSON(
username ?
"http://twitter.com/statuses/user_timeline/"+username+".json" :
"http://twitter.com/statuses/home_timeline.json");
return username ? Tweeter.user({username: username}) : Tweeter.home();
}
scope.set('fetchTweets', fetchTweets);