Permalink
Browse files

Converted "new Promise()" to more convenient "this.Promise()" factory…

… accessible from a module context.
  • Loading branch information...
1 parent 4af689b commit c9f8a85b96e38556ed4b0414fddd92fc55ca685d @bnoguchi committed May 2, 2011
Showing with 30 additions and 24 deletions.
  1. +16 −2 README.md
  2. +1 −1 example/server.js
  3. +1 −2 lib/facebook.js
  4. +1 −2 lib/foursquare.js
  5. +2 −3 lib/github.js
  6. +1 −2 lib/instagram.js
  7. +1 −2 lib/linkedin.js
  8. +3 −4 lib/oauth.js
  9. +1 −2 lib/oauth2.js
  10. +1 −1 lib/stepSequence.js
  11. +2 −3 lib/twitter.js
View
@@ -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
View
@@ -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);
View
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth2')
- , Promise = require('./promise')
, url = require('url');
var fb = module.exports =
@@ -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);
View
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth2')
- , Promise = require('./promise')
, rest = require('restler');
var foursquare = module.exports =
@@ -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) {
View
@@ -1,5 +1,4 @@
-var oauthModule = require('./oauth2')
- , Promise = require('./promise');
+var oauthModule = require('./oauth2');
var github = module.exports =
oauthModule.submodule('github')
@@ -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;
View
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth2')
- , Promise = require('./promise')
, querystring= require('querystring');
var instagram = module.exports =
@@ -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;
View
@@ -1,5 +1,4 @@
var oauthModule = require('./oauth')
- , Promise = require('./promise')
, OAuth = require('oauth').OAuth;
var linkedin = module.exports =
@@ -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);
View
@@ -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')
@@ -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);
@@ -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);
View
@@ -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
@@ -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()
View
@@ -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;
}
View
@@ -1,5 +1,4 @@
-var oauthModule = require('./oauth')
- , Promise = require('./promise');
+var oauthModule = require('./oauth');
var twitter = module.exports =
oauthModule.submodule('twitter')
@@ -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);

0 comments on commit c9f8a85

Please sign in to comment.