Created
May 9, 2015 11:17
-
-
Save ds0nt/ace71c3b30577543fc34 to your computer and use it in GitHub Desktop.
Some ES6 winning in a gist file.
This file contains 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 model = require('component/model'); | |
var superagent = require('visionmedia/superagent'); | |
var supercouch = require('qualiancy/supercouch'); | |
var transforms = require('./transforms.js'); | |
var state = require('./state.js'); | |
var apiSpec = { | |
user: { | |
register: register, | |
login: login, | |
}, | |
subscription: { | |
create: null, | |
delete: null, | |
} | |
}; | |
function* login(data) { | |
var res = yield superagent | |
.post('/user/login') | |
.send(data) | |
.set('Accept', 'application.json') | |
.end(); | |
transforms.login(res); | |
return res; | |
} | |
function* register(data) { | |
var res = yield superagent | |
.post('/user/create') | |
.send(data) | |
.set('Accept', 'application.json') | |
.end(); | |
if (!res) | |
return false; | |
return yield login(data); | |
} | |
module.exports = apiSpec; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment