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

1
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1 @@
workspace.xml

View File

@@ -46,6 +46,7 @@ task :compile do
src/JSON.js \
src/Model.js \
src/Parser.js \
src/Resource.js \
src/Scope.js \
src/Server.js \
src/Users.js \

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);

View File

@@ -49,7 +49,7 @@ ResourceFactory.prototype = {
actions = $.extend({}, ResourceFactory.DEFAULT_ACTIONS, actions);
function extractParams(data){
var ids = {};
foreach(paramDefaults, function(value, key){
foreach(paramDefaults || {}, function(value, key){
ids[key] = value.charAt && value.charAt(0) == '@' ? Scope.getter(data, value.substr(1)) : value;
});
return ids;

View File

@@ -46,6 +46,7 @@
addScript("/JSON.js");
addScript("/Model.js");
addScript("/Parser.js");
addScript("/Resource.js");
addScript("/Scope.js");
addScript("/Server.js");
addScript("/Users.js");