Permalink
Browse files

Conform to latest conventions.

  • Loading branch information...
1 parent e97aadb commit 8b9240686f511402df90ffa5c75c11bc7a13c37c @jaredhanson committed Feb 11, 2012
Showing with 50 additions and 16 deletions.
  1. +4 −0 .travis.yml
  2. +1 −1 Makefile
  3. +8 −1 README.md
  4. +1 −1 lib/passport-foursquare/index.js
  5. +10 −7 lib/passport-foursquare/strategy.js
  6. +17 −3 package.json
  7. +9 −3 test/strategy-test.js
View
@@ -0,0 +1,4 @@
+language: "node_js"
+node_js:
+ - 0.4
+ - 0.6
View
@@ -1,5 +1,5 @@
NODE = node
-TEST = vows
+TEST = ./node_modules/.bin/vows
TESTS ?= test/*-test.js
test:
View
@@ -50,10 +50,17 @@ application:
res.redirect('/');
});
-#### Examples
+## Examples
For a complete, working example, refer to the [login example](https://github.com/jaredhanson/passport-foursquare/tree/master/examples/login).
+## Tests
+
+ $ npm install --dev
+ $ make test
+
+[![Build Status](https://secure.travis-ci.org/jaredhanson/passport-foursquare.png)](http://travis-ci.org/jaredhanson/passport-foursquare)
+
## Credits
- [Jared Hanson](http://github.com/jaredhanson)
@@ -7,7 +7,7 @@ var Strategy = require('./strategy');
/**
* Framework version.
*/
-exports.version = '0.1.0';
+require('pkginfo')(module, 'version');
/**
* Expose constructors.
@@ -79,18 +79,21 @@ util.inherits(Strategy, OAuth2Strategy);
* @api protected
*/
Strategy.prototype.userProfile = function(accessToken, done) {
- this._oauth2.getProtectedResource('https://api.foursquare.com/v2/users/self', accessToken, function (err, body, res) {
+ this._oauth2.get('https://api.foursquare.com/v2/users/self', accessToken, function (err, body, res) {
if (err) { return done(err); }
try {
- o = JSON.parse(body);
+ var json = JSON.parse(body);
var profile = { provider: 'foursquare' };
- profile.id = o.response.user.id;
- profile.name = { familyName: o.response.user.lastName,
- givenName: o.response.user.firstName };
- profile.gender = o.response.user.gender;
- profile.emails = [{ value: o.response.user.contact.email }];
+ profile.id = json.response.user.id;
+ profile.name = { familyName: json.response.user.lastName,
+ givenName: json.response.user.firstName };
+ profile.gender = json.response.user.gender;
+ profile.emails = [{ value: json.response.user.contact.email }];
+
+ profile._raw = body;
+ profile._json = json;
done(null, profile);
} catch(e) {
View
@@ -2,15 +2,29 @@
"name": "passport-foursquare",
"version": "0.1.0",
"description": "Foursquare authentication strategy for Passport.",
- "author": "Jared Hanson <jaredhanson@gmail.com> (http://www.jaredhanson.net/)",
+ "author": { "name": "Jared Hanson", "email": "jaredhanson@gmail.com", "url": "http://www.jaredhanson.net/" },
"repository": {
"type": "git",
- "url": "http://github.com/jaredhanson/passport-foursquare.git"
+ "url": "git://github.com/jaredhanson/passport-foursquare.git"
+ },
+ "bugs": {
+ "url": "http://github.com/jaredhanson/passport-foursquare/issues"
},
"main": "./lib/passport-foursquare",
"dependencies": {
- "passport-oauth": ">= 0.1.0"
+ "pkginfo": "0.2.x",
+ "passport-oauth": "0.1.x"
+ },
+ "devDependencies": {
+ "vows": "0.6.x"
+ },
+ "scripts": {
+ "test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
},
"engines": { "node": ">= 0.4.0" },
+ "licenses": [ {
+ "type": "MIT",
+ "url": "http://www.opensource.org/licenses/MIT"
+ } ],
"keywords": ["passport", "foursquare", "auth", "authn", "authentication", "identity"]
}
View
@@ -29,7 +29,7 @@ vows.describe('FoursquareStrategy').addBatch({
function() {});
// mock
- strategy._oauth2.getProtectedResource = function(url, accessToken, callback) {
+ strategy._oauth2.get = function(url, accessToken, callback) {
var body = '{"meta":{"code":200},"notifications":[{"type":"notificationTray","item":{"unreadCount":0}}],"response":{"user":{"id":"1419","firstName":"Jared","lastName":"Hanson","photo":"https://playfoursquare.s3.amazonaws.com/userpix_thumbs/1419_1238423817.jpg","gender":"male","homeCity":"Oakland, CA","relationship":"self","type":"user","pings":false,"contact":{"phone":"5105551234","email":"jaredhanson@example.com","twitter":"jaredhanson","facebook":"500308595"}}}}';
callback(null, body, undefined);
@@ -59,9 +59,15 @@ vows.describe('FoursquareStrategy').addBatch({
assert.equal(profile.name.familyName, 'Hanson');
assert.equal(profile.name.givenName, 'Jared');
assert.equal(profile.gender, 'male');
- assert.length(profile.emails, 1);
+ assert.lengthOf(profile.emails, 1);
assert.equal(profile.emails[0].value, 'jaredhanson@example.com');
},
+ 'should set raw property' : function(err, profile) {
+ assert.isString(profile._raw);
+ },
+ 'should set json property' : function(err, profile) {
+ assert.isObject(profile._json);
+ },
},
},
@@ -74,7 +80,7 @@ vows.describe('FoursquareStrategy').addBatch({
function() {});
// mock
- strategy._oauth2.getProtectedResource = function(url, accessToken, callback) {
+ strategy._oauth2.get = function(url, accessToken, callback) {
callback(new Error('something-went-wrong'));
}

0 comments on commit 8b92406

Please sign in to comment.