Permalink
Browse files

getting there

  • Loading branch information...
1 parent 34c9ba7 commit 731b43c4eadf8fef72e117c229e22b3acbf4cc97 @timsavery timsavery committed Apr 15, 2012
View
@@ -1,3 +1,5 @@
.project
node_modules/**/*
-gklst-creds.json
+gklst-creds.jsonpublic/img/*
+public/img/*.jpg
+gklst-creds.json
View
128 app.js
@@ -1,39 +1,10 @@
-/*
-var express = require('express')
- , routes = require('./routes');
-
-var app = module.exports = express.createServer();
-
-// Configuration
-
-app.configure(function(){
- app.set('views', __dirname + '/views');
- app.set('view engine', 'jade');
- app.use(express.bodyParser());
- app.use(express.methodOverride());
- app.use(app.router);
- app.use(express.static(__dirname + '/public'));
-});
-
-app.configure('development', function(){
- app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
-});
-
-app.configure('production', function(){
- app.use(express.errorHandler());
-});
-
-// View Routes
-app.get('/', routes.index);
-
-app.listen(3000);
-console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
-*/
-
var creds = require('./gklst-creds.json');
-var util= require('util')
+var fs = require('fs')
+ , util= require('util')
, async = require('async')
+ , im = require('imagemagick')
+ , request = require('request')
, OAuth = require('oauth').OAuth;
var oa = new OAuth(
@@ -46,46 +17,85 @@ var oa = new OAuth(
"HMAC-SHA1"
);
-var users = {
+users = {
'timsavery': undefined,
'csanz': undefined,
- 'rekatz': undefined,
- 'paul_irish': undefined,
- 'tendrelove': undefined,
- 'matz': undefined
+ 'rekatz': undefined
};
-var cards = [];
+cards = [];
async.series([
function(seriesCallback) {
async.map(Object.keys(users), function(user, callback) {
- oa.getProtectedResource('http://sandbox-api.geekli.st/v1/users/' + user, 'GET', creds.ACCESS_TOKEN, creds.ACCESS_TOKEN_SECRET, function (error, data, response) {
- if (error) callback(error, null);
- users[user] = JSON.parse(data);
- callback();
- });
- }, seriesCallback);
+ oa.getProtectedResource('http://sandbox-api.geekli.st/v1/users/' + user, 'GET', creds.ACCESS_TOKEN, creds.ACCESS_TOKEN_SECRET, function (error, data, response) {
+ if (error) callback(error, null);
+
+ users[user] = JSON.parse(data);
+
+ request.get(users[user].data.avatar.large, function(err, response, body) {
+ fs.readFile('public/img/geeks/' + user + '-large.jpg', 'binary', function(err, data) {
+ im.resize({
+ srcPath: 'public/img/geeks/' + user + '-large.jpg',
+ dstPath: 'public/img/geeks/' + user + '.jpg',
+ width: 300
+ }, function() {
+ callback();
+ });
+ });
+ }).pipe(fs.createWriteStream('public/img/geeks/' + user + '-large.jpg'));
+ });
+ }, seriesCallback);
},
function(seriesCallback) {
async.map(Object.keys(users), function(user, callback) {
- oa.getProtectedResource('http://sandbox-api.geekli.st/v1/users/' + user + '/cards', 'GET', creds.ACCESS_TOKEN, creds.ACCESS_TOKEN_SECRET, function (error, data, response) {
- var cardsResult = JSON.parse(data);
-
- for (var cardIdx=0; cardIdx<cardsResult.data.cards.length; cardIdx++) {
- cards.push({
- headline: cardsResult.data.cards[cardIdx].headline,
- user: user
- });
- }
-
- callback();
- });
- }, seriesCallback);
+ oa.getProtectedResource('http://sandbox-api.geekli.st/v1/users/' + user + '/cards', 'GET', creds.ACCESS_TOKEN, creds.ACCESS_TOKEN_SECRET, function (error, data, response) {
+ var cardsResult = JSON.parse(data);
+
+ for (var cardIdx=0; cardIdx<cardsResult.data.cards.length; cardIdx++) {
+ cards.push({
+ headline: cardsResult.data.cards[cardIdx].headline,
+ user: {
+ name: user,
+ avatar: '/img/geeks/' + user + '.jpg'
+ }
+ });
+ }
+
+ callback();
+ });
+ }, seriesCallback);
}
], function() {
- console.log(cards);
+
+ var express = require('express')
+ , routes = require('./routes');
+
+ var app = module.exports = express.createServer();
+
+ app.configure(function(){
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'jade');
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express.static(__dirname + '/public'));
+ });
+
+ app.configure('development', function(){
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+ });
+
+ app.configure('production', function(){
+ app.use(express.errorHandler());
+ });
+
+ app.get('/', routes.index);
+
+ app.listen(3000);
+ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+
});
View
@@ -7,5 +7,7 @@
, "jade": "0.22.x"
, "oauth": "0.9.x"
, "async": "0.1.x"
+ , "imagemagick": "0.1.2"
+ , "request": "2.9.x"
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 731b43c

Please sign in to comment.