Created
September 26, 2012 19:13
-
-
Save cronopio/3789947 to your computer and use it in GitHub Desktop.
BogotaConf.co
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flatiron = require('flatiron'), | |
app = flatiron.app, | |
Usuario = require('./user'), | |
winston = require('winston'), | |
restful = require('restful'); | |
app.resources = { Usuario:Usuario }; | |
app.use(flatiron.plugins.http, { | |
before: [logUserAgent] | |
}); | |
app.use(restful); | |
app.router.get('/', function () { | |
winston.info('Recibiendo peticion usando:', this.req.request.headers['user-agent']); | |
this.res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
this.res.end('Bienvenidos a BogotaConf + PulsoConf!'); | |
}); | |
app.start(3000, function () { | |
winston.info(' > http server iniciado en el puerto 3000') | |
}); | |
function logUserAgent (req, res) { | |
winston.info('User Agent:', req.request.headers['user-agent']); | |
res.emit('next'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flatiron = require('flatiron'), | |
commandful = require('commandful'), | |
Usuario = require('./user'); | |
// Creamos la App | |
var app = new flatiron.App; | |
// Activamos el plugin de CLI | |
app.use(flatiron.plugins.cli); | |
// Definimos los recursos que queramos usar | |
app.resources = { Usuario:Usuario }; | |
// Extendemos la funcionalidad usando commandful | |
app.use(commandful); | |
app.start(function (err) { | |
if (err) throw err; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resourceful = require('resourceful'); | |
resourceful.use('memory'); | |
// | |
// TODO: This seems to not be working on couchdb. Test coverage should be added for this. | |
// | |
var Category = resourceful.define('category'); | |
Category.parent('category'); | |
Category.create({ | |
id: 'music', | |
}, function(err, music){ | |
music.createCategory({ | |
id: 'hip-hop', | |
}, function(err, hiphop){ | |
music.createCategory({ | |
id: 'rap', | |
}, function(err, rap){ | |
hiphop.createCategory({ id: "a-tribe-called-quest", title: "Hello!" }, function(err, result){ | |
hiphop.createCategory({ id: "busta-rhymes", title: "Hello!" }, function(err, busta){ | |
rap.createCategory({ id: "wu-tang", title: "Hello!" }, function(err, wutang){ | |
wutang.createCategory({ id: "Enter the 36 Chambers", title: "Hello!" }, function(err, result){ | |
music.categories(function(err, result){ | |
console.log('music', err, result); | |
}); | |
rap.categories(function(err, result){ | |
console.log('rap', err, result); | |
}); | |
hiphop.categories(function(err, result){ | |
console.log('hiphop', err, result); | |
}); | |
wutang.categories(function(err, result){ | |
console.log('wutang', err, result); | |
}); | |
Category.categories('music', function(err, result){ | |
console.log('music', result) | |
}); | |
Category.categories('category/music/rap', function(err, result){ | |
console.log('category/music/rap', result) | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resourceful = require('resourceful'), | |
winston = require('winston'); | |
var Usuario = module.exports = resourceful.define('Usuario', function () { | |
// Motor de Almacenamiento | |
this.use('memory'); | |
// Propiedades | |
// this.string('_id') | |
// .unique(true) | |
// .sanitize('lower') | |
// .sanitize('prefix', 'regular/'); | |
this.string('username').sanitize('lower'); | |
this.string('password'); | |
this.string('email', { format: 'email', required: true }); | |
this.object('profile'); | |
this.timestamps(); | |
this.restful = true; | |
}); | |
/** | |
// Podemos hacer cosas raras. | |
// Como esta... | |
Usuario.prototype.destacar = function () { | |
this.profile.destacado = true; | |
} | |
// | |
// ¿Como probamos? | |
// | |
var data = { | |
username:'daniel', | |
password:'cronopio', | |
email: 'daniel@nodejitsu.com' | |
} | |
// Creamos un usuario | |
Usuario.create(data, function (err, result) { | |
if (err) throw err; | |
winston.info('Usuario creado: ', result); | |
}); | |
// Cual es la gracia? | |
Usuario.create({ username: 'cronopio' }, function (err, result) { | |
if (err) { | |
// El email es requerido, asi que tenemos un error aqui. | |
winston.error('E', err); | |
winston.error('Cual es el error? => ', err.validate.errors); | |
} | |
winston.log(result); | |
}) | |
Usuario.create({ username: 'cronopio', email: 'soylisto' }, function (err, result) { | |
winston.error('Y ahora?', err.validate.errors); | |
}); | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment