Skip to content

Commit

Permalink
Converted "new Promise()" to more convenient "this.Promise()" factory…
Browse files Browse the repository at this point in the history
… accessible from a module context.
  • Loading branch information
bnoguchi committed May 2, 2011
1 parent 4af689b commit c9f8a85
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 24 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,22 @@ everyauth.password
// If we cannot, returns null/undefined
})
.getRegisterPath('/register')
.postRegisterPath('/register')
.getRegisterPath('/register') // Page with the registration form
.postRegisterPath('/register') // What you POST to
// TODO Complete documentation for validateRegistration
.extractExtraRegistrationParams( function (req) {
return {
phone: req.body.phone
, name: {
first: req.body.first_name
, last: req.body.last_name
}
};
})
.validateRegistration( function () {
})
.handleRegistrationError( function (req, res, errorMessages) {
})
.registerView('a string of html; OR the name of the jade/etc-view-engine view')
.registerUser( function (login, password) {
// Returns a user (or a Promise that promises a user) after adding it to
Expand Down
2 changes: 1 addition & 1 deletion example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ everyauth
if (!password)
return this.breakTo('registrationError', req, res, 'Missing password');

// simulate an async user db
var promise = this.Promise();
// simulate an async user db
setTimeout( function () {
if (login in usersByLogin) {
return promise.breakTo('registrationError', req, res, 'Someone already has the login ' + login);
Expand Down
3 changes: 1 addition & 2 deletions lib/facebook.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth2')
, Promise = require('./promise')
, url = require('url');

var fb = module.exports =
Expand Down Expand Up @@ -38,7 +37,7 @@ oauthModule.submodule('facebook')
})

.fetchOAuthUser( function (accessToken) {
var p = new Promise();
var p = this.Promise();
this.oauth.get(this.apiHost() + '/me', accessToken, function (err, data) {
if (err)
return p.fail(err);
Expand Down
3 changes: 1 addition & 2 deletions lib/foursquare.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth2')
, Promise = require('./promise')
, rest = require('restler');

var foursquare = module.exports =
Expand All @@ -20,7 +19,7 @@ oauthModule.submodule('foursquare')

.fetchOAuthUser( function (accessToken) {
console.log(arguments);
var promise = new Promise();
var promise = this.Promise();
rest.get(this.apiHost() + '/users/self', {
query: { oauth_token: accessToken }
}).on('success', function (data, res) {
Expand Down
5 changes: 2 additions & 3 deletions lib/github.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth2')
, Promise = require('./promise');
var oauthModule = require('./oauth2');

var github = module.exports =
oauthModule.submodule('github')
Expand All @@ -21,7 +20,7 @@ oauthModule.submodule('github')
})

.fetchOAuthUser( function (accessToken) {
var p = new Promise();
var p = this.Promise();
this.oauth.get(this.apiHost() + '/user/show', accessToken, function (err, data) {
if (err) return p.fail(err);
var oauthUser = JSON.parse(data).user;
Expand Down
3 changes: 1 addition & 2 deletions lib/instagram.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth2')
, Promise = require('./promise')
, querystring= require('querystring');

var instagram = module.exports =
Expand Down Expand Up @@ -27,7 +26,7 @@ oauthModule.submodule('instagram')
.postAccessTokenParamsVia('data')

.fetchOAuthUser( function (accessToken) {
var p = new Promise();
var p = this.Promise();
this.oauth.get(this.apiHost() + '/users/self', accessToken, function (err, data) {
if (err) return p.fail(err.error_message);
var oauthUser = JSON.parse(data).data;
Expand Down
3 changes: 1 addition & 2 deletions lib/linkedin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth')
, Promise = require('./promise')
, OAuth = require('oauth').OAuth;

var linkedin = module.exports =
Expand Down Expand Up @@ -35,7 +34,7 @@ oauthModule.submodule('linkedin')
})

.fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
var promise = new Promise();
var promise = this.Promise();
this.oauth.get(this.apiHost() + '/people/~:(id,first-name,last-name,headline,location:(name,country:(code)),industry,num-connections,num-connections-capped,summary,specialties,proposal-comments,associations,honors,interests,positions,publications,patents,languages,skills,certifications,educations,three-current-positions,three-past-positions,num-recommenders,recommendations-received,phone-numbers,im-accounts,twitter-accounts,date-of-birth,main-address,member-url-resources,picture-url,site-standard-profile-request:(url),api-standard-profile-request:(url,headers),public-profile-url)', accessToken, accessTokenSecret, function (err, data) {
if (err) return promise.fail(err);
var oauthUser = JSON.parse(data);
Expand Down
7 changes: 3 additions & 4 deletions lib/oauth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var everyModule = require('./everymodule')
, OAuth = require('oauth').OAuth
, url = require('url')
, Promise = require('./promise');
, url = require('url');

var oauth = module.exports =
everyModule.submodule('oauth')
Expand Down Expand Up @@ -73,7 +72,7 @@ everyModule.submodule('oauth')
.accepts('res')
.promises(null)
.getRequestToken( function (req, res) {
var p = new Promise();
var p = this.Promise();
this.oauth.getOAuthRequestToken( function (err, token, tokenSecret, authUrl, params) {
if (err) return p.fail(err);
p.fulfill(token, tokenSecret);
Expand Down Expand Up @@ -106,7 +105,7 @@ everyModule.submodule('oauth')
return sess.auth && sess.auth[this.name] && sess.auth[this.name].tokenSecret;
})
.getAccessToken( function (reqToken, reqTokenSecret, verifier) {
var promise = new Promise();
var promise = this.Promise();
this.oauth.getOAuthAccessToken(reqToken, reqTokenSecret, verifier, function (err, accessToken, accessTokenSecret, params) {
if (err) return promise.fail(err);
promise.fulfill(accessToken, accessTokenSecret, params);
Expand Down
3 changes: 1 addition & 2 deletions lib/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var everyModule = require('./everymodule')
, OAuth = require('oauth').OAuth2
, url = require('url')
, querystring = require('querystring')
, Promise = require('./promise')
, rest = require('restler');

// Steps define a sequence of logic that pipes data through
Expand Down Expand Up @@ -128,7 +127,7 @@ everyModule.submodule('oauth2')
return parsedUrl.query && parsedUrl.query.code;
})
.getAccessToken( function (code) {
var p = new Promise()
var p = this.Promise()
, params = {
client_id: this.appId()
, redirect_uri: this.myHostname() + this.callbackPath()
Expand Down
2 changes: 1 addition & 1 deletion lib/stepSequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var materializedMethods = {
if (!resultPromise) return; // if we have a breakTo
resultPromise.callback( function () {
nextPromise.fulfill();
}); // TODO breakback
}); // TODO breakback?
});
return nextPromise;
}
Expand Down
5 changes: 2 additions & 3 deletions lib/twitter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth')
, Promise = require('./promise');
var oauthModule = require('./oauth');

var twitter = module.exports =
oauthModule.submodule('twitter')
Expand All @@ -8,7 +7,7 @@ oauthModule.submodule('twitter')
.entryPath('/auth/twitter')
.callbackPath('/auth/twitter/callback')
.fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
var promise = new Promise();
var promise = this.Promise();
this.oauth.get(this.apiHost() + '/users/show.json?user_id=' + params.user_id, accessToken, accessTokenSecret, function (err, data) {
if (err) return promise.fail(err);
var oauthUser = JSON.parse(data);
Expand Down

0 comments on commit c9f8a85

Please sign in to comment.