Comparing version 1.11.0 to 1.12.0
@@ -10,3 +10,3 @@ /** | ||
, jshint: { | ||
files: ['gruntfile.js', 'lib/*.js'], | ||
all: ['gruntfile.js', 'lib/*.js'], | ||
options: { | ||
@@ -13,0 +13,0 @@ maxlen: 80 |
21
index.js
@@ -22,23 +22,3 @@ /** | ||
var strava = {}; | ||
var configPath = "data/strava_config"; | ||
//attempt to grab the default config | ||
try { | ||
var config = fs.readFileSync(configPath, {encoding: 'utf-8'}); | ||
util.config = JSON.parse(config); | ||
} catch (err) { | ||
//console.log(err) | ||
console.log("no 'data/strava_config' file, continuing without..."); | ||
} | ||
//allow environment vars to override config vals | ||
if(process.env.STRAVA_ACCESS_TOKEN) | ||
util.config.access_token = process.env.STRAVA_ACCESS_TOKEN; | ||
if(process.env.STRAVA_CLIENT_SECRET) | ||
util.config.client_secret = process.env.STRAVA_CLIENT_SECRET; | ||
if(process.env.STRAVA_CLIENT_ID) | ||
util.config.client_id = process.env.STRAVA_CLIENT_ID; | ||
if(process.env.STRAVA_REDIRECT_URI) | ||
util.config.redirect_uri = process.env.STRAVA_REDIRECT_URI; | ||
//assign various api segments to strava object | ||
@@ -59,2 +39,1 @@ strava.oauth = oauth; | ||
module.exports = strava; | ||
@@ -6,2 +6,3 @@ /** | ||
var util = require('./util') | ||
, authenticator = require('./authenticator') | ||
, request = require('request') | ||
@@ -16,4 +17,4 @@ , querystring = require('querystring'); | ||
, oauthArgs = { | ||
client_id: util.config.client_id | ||
, redirect_uri: util.config.redirect_uri | ||
client_id: authenticator.getClientId() | ||
, redirect_uri: authenticator.getRedirectUri() | ||
, response_type: 'code' | ||
@@ -29,3 +30,2 @@ }; | ||
var qs = querystring.stringify(oauthArgs); | ||
@@ -43,4 +43,4 @@ | ||
code: code | ||
, client_secret: util.config.client_secret | ||
, client_id: util.config.client_id | ||
, client_secret: authenticator.getClientSecret() | ||
, client_id: authenticator.getClientId() | ||
}; | ||
@@ -47,0 +47,0 @@ |
@@ -46,3 +46,6 @@ /** | ||
var checkArgs = {id:payload.id}; | ||
var checkArgs = { | ||
id: payload.id, | ||
access_token: args.access_token | ||
}; | ||
self._check(checkArgs,args.statusCallback); | ||
@@ -49,0 +52,0 @@ } |
@@ -7,3 +7,4 @@ /** | ||
, querystring = require('querystring') | ||
, fs = require('fs'); | ||
, fs = require('fs') | ||
, authenticator = require('./authenticator'); | ||
@@ -15,3 +16,2 @@ //request.debug = true | ||
util.endpointBase = 'https://www.strava.com/api/v3/'; | ||
util.config = {}; | ||
@@ -25,10 +25,4 @@ //===== generic GET ===== | ||
//all strava requests require an access_token, so let's do that check here | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
} | ||
var token = args.access_token || authenticator.getToken(); | ||
if(!token) return done({msg: 'you must include an access_token'}); | ||
@@ -40,3 +34,3 @@ var url = this.endpointBase + endpoint | ||
, headers: { | ||
Authorization: 'Bearer ' + args.access_token | ||
Authorization: 'Bearer ' + token | ||
} | ||
@@ -55,10 +49,4 @@ }; | ||
//all strava requests require an access_token, so let's do that check here | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
} | ||
var token = args.access_token || authenticator.getToken(); | ||
if(!token) return done({msg: 'you must include an access_token'}); | ||
@@ -75,3 +63,3 @@ //stringify the body object for passage | ||
, headers: { | ||
Authorization: 'Bearer ' + args.access_token | ||
Authorization: 'Bearer ' + token | ||
} | ||
@@ -94,10 +82,4 @@ }; | ||
//all strava requests require an access_token, so let's do that check here | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
} | ||
var token = args.access_token || authenticator.getToken(); | ||
if(!token) return done({msg: 'you must include an access_token'}); | ||
@@ -114,3 +96,3 @@ //stringify the body object for passage | ||
, headers: { | ||
Authorization: 'Bearer ' + args.access_token | ||
Authorization: 'Bearer ' + token | ||
} | ||
@@ -137,10 +119,4 @@ }; | ||
//all strava requests require an access_token, so let's do that check here | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
} | ||
var token = args.access_token || authenticator.getToken(); | ||
if(!token) return done({msg: 'you must include an access_token'}); | ||
@@ -157,3 +133,3 @@ //stringify the body object for passage | ||
, headers: { | ||
Authorization: 'Bearer ' + args.access_token | ||
Authorization: 'Bearer ' + token | ||
} | ||
@@ -168,10 +144,4 @@ }; | ||
//all strava requests require an access_token, so let's do that check here | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
} | ||
var token = args.access_token || authenticator.getToken(); | ||
if(!token) return done({msg: 'you must include an access_token'}); | ||
@@ -184,3 +154,3 @@ var url = this.endpointBase + 'uploads' | ||
, headers: { | ||
Authorization: 'Bearer ' + args.access_token | ||
Authorization: 'Bearer ' + token | ||
} | ||
@@ -187,0 +157,0 @@ }; |
{ | ||
"name": "strava-v3", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "Simple wrapper for strava v3 api", | ||
@@ -28,8 +28,11 @@ "main": "index.js", | ||
"devDependencies": { | ||
"es6-promise": "^3.2.1", | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-jshint": "^0.10.0", | ||
"grunt-simple-mocha": "^0.4.0", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"grunt-simple-mocha": "^0.4.1", | ||
"mocha": "^1.21.5", | ||
"should": "^4.6.5" | ||
"mock-fs": "^3.9.0", | ||
"should": "^4.6.5", | ||
"sinon": "^1.17.4" | ||
} | ||
} |
@@ -5,2 +5,3 @@ /** | ||
var fs = require('fs'); | ||
var strava = require('../'); | ||
@@ -63,2 +64,11 @@ | ||
testsHelper.getAccessToken = function () { | ||
try { | ||
var config = fs.readFileSync('data/strava_config', {encoding: 'utf-8'}); | ||
return JSON.parse(config).access_token; | ||
} catch (e) { | ||
return process.env.STRAVA_ACCESS_TOKEN; | ||
} | ||
}; | ||
module.exports = testsHelper; |
@@ -6,4 +6,6 @@ /** | ||
var should = require("should") | ||
, sinon = require('sinon') | ||
, strava = require("../") | ||
, testHelper = require("./_helper"); | ||
, testHelper = require("./_helper") | ||
, authenticator = require('../lib/authenticator'); | ||
@@ -71,2 +73,18 @@ var testActivity = {} | ||
}); | ||
it('should work with a specified access token', function(done) { | ||
var token = testHelper.getAccessToken(); | ||
var tokenStub = sinon.stub(authenticator, 'getToken', function () { | ||
return undefined; | ||
}); | ||
strava.activities.get({ | ||
id: testActivity.id, | ||
access_token: token | ||
}, function(err, payload) { | ||
(payload.resource_state).should.be.exactly(3); | ||
tokenStub.restore(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -255,2 +273,2 @@ | ||
}); | ||
}); |
@@ -5,32 +5,38 @@ /** | ||
var should = require('should') | ||
, authenticator = require('../lib/authenticator') | ||
, querystring = require('querystring') | ||
, strava = require('../'); | ||
var should = require("should") | ||
, strava = require("../"); | ||
var _tokenExchangeCode = "a248c4c5dc49e71336010022efeb3a268594abb7"; | ||
describe.skip('oauth_test', function() { | ||
describe('oauth_test', function() { | ||
describe('#getRequestAccessURL()', function () { | ||
it('should return the full request access url', function () { | ||
var clientId = authenticator.getClientId(); | ||
var redirectUri = authenticator.getRedirectUri(); | ||
var targetUrl = 'https://www.strava.com/oauth/authorize?' | ||
+ querystring.stringify({ | ||
client_id: authenticator.getClientId(), | ||
redirect_uri: authenticator.getRedirectUri(), | ||
response_type: 'code', | ||
scope: 'view_private,write' | ||
}); | ||
it('should return the full request url for view_private and write permissions', function () { | ||
var url = strava.oauth.getRequestAccessURL({ | ||
scope:"view_private,write" | ||
}); | ||
var url = strava.oauth.getRequestAccessURL({scope:"view_private write"}); | ||
console.log(url); | ||
url.should.be.exactly(targetUrl); | ||
}); | ||
}); | ||
describe('#getToken()', function () { | ||
// TODO: Figure out a way to get a valid oAuth code for the token exchange | ||
describe.skip('#getToken()', function () { | ||
it('should return an access_token', function (done) { | ||
strava.oauth.getToken(_tokenExchangeCode,function(err,payload) { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -5,2 +5,3 @@ /** | ||
require('es6-promise').polyfill(); | ||
@@ -11,32 +12,32 @@ var should = require("should") | ||
describe.skip('uploads_test', function(){ | ||
describe('#post()', function() { | ||
it('should upload a GPX file', function(done) { | ||
this.timeout(30000); | ||
new Promise(function (resolve, reject) { | ||
strava.uploads.post({ | ||
activity_type:'run' | ||
, data_type:'gpx' | ||
, name:'test activity' | ||
, file:'test/assets/gpx_sample.gpx' | ||
, statusCallback: function(err,payload) { | ||
should.not.exist(err); | ||
should.not.exist(payload.error); | ||
it('should post example activity to strava', function(done) { | ||
if(payload.activity_id === null) { | ||
(payload.status).should.be.exactly('Your activity is still being processed.'); | ||
} else { | ||
(payload.status).should.be.exactly('Your activity is ready.'); | ||
(payload.activity_id).should.be.a.Number; | ||
strava.uploads.post({ | ||
activity_type:'run' | ||
, data_type:'gpx' | ||
, name:'test activity' | ||
, file:'data/Evening_Run.gpx' | ||
, statusCallback: function(err,payload) { | ||
//console.log(payload) | ||
done(); | ||
} | ||
},function(err,payload){ | ||
if(!err) { | ||
//console.log(payload); | ||
//(payload.resource_state).should.be.exactly(3); | ||
//(payload.city).should.be.exactly("Seattle"); | ||
} | ||
else { | ||
console.log(err); | ||
} | ||
//done(); | ||
}); | ||
resolve(payload.activity_id); | ||
} | ||
} | ||
},function(err,payload) {}); | ||
}).then(function (activityId) { | ||
// clean up the uploaded activity | ||
strava.activities.delete({id: activityId}, function (err, payload) { | ||
if(err) console.log(err); | ||
done(); | ||
}) | ||
}) | ||
}); | ||
@@ -43,0 +44,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114392
35
1927
8
25