Comparing version 1.2.1 to 1.3.0
10
index.js
@@ -14,2 +14,4 @@ /** | ||
, gear = require('./lib/gear') | ||
, segments = require('./lib/segments') | ||
, segmentEfforts = require('./lib/segmentEfforts') | ||
; | ||
@@ -36,2 +38,4 @@ | ||
strava.gear = gear; | ||
strava.segments = segments; | ||
strava.segmentEfforts = segmentEfforts; | ||
@@ -43,8 +47,2 @@ //and export | ||
/* TODO api functionality | ||
/v3/oauth | ||
/v3/athlete | ||
/v3/athletes/:id | ||
/v3/activities/:id | ||
/v3/activities/:id/streams | ||
/v3/clubs/:id | ||
/v3/segments/:id | ||
@@ -51,0 +49,0 @@ /v3/segments/:id/leaderboard |
@@ -5,3 +5,3 @@ /** | ||
var util = require("./util") | ||
var util = require('./util') | ||
; | ||
@@ -11,16 +11,16 @@ | ||
, _createAllowedProps = [ | ||
"name" | ||
, "type" | ||
, "start_date_local" | ||
, "elapsed_time" | ||
, "description" | ||
, "distance" | ||
'name' | ||
, 'type' | ||
, 'start_date_local' | ||
, 'elapsed_time' | ||
, 'description' | ||
, 'distance' | ||
] | ||
, _updateAllowedProps = [ | ||
"name" | ||
, "type" | ||
, "commute" | ||
, "trainer" | ||
, "description" | ||
, "gear_id" | ||
'name' | ||
, 'type' | ||
, 'commute' | ||
, 'trainer' | ||
, 'description' | ||
, 'gear_id' | ||
]; | ||
@@ -31,3 +31,3 @@ | ||
var endpoint = "activities/" | ||
var endpoint = 'activities/' | ||
, err = null; | ||
@@ -37,3 +37,3 @@ | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an activity 'id'"}; | ||
err = {msg:'args must include an activity id'}; | ||
return done(err); | ||
@@ -47,3 +47,3 @@ } | ||
var endpoint = "activities"; | ||
var endpoint = 'activities'; | ||
@@ -55,3 +55,3 @@ args.body = util.getRequestBodyObj(_createAllowedProps,args); | ||
var endpoint = "activities/" | ||
var endpoint = 'activities/' | ||
, err = null; | ||
@@ -61,3 +61,3 @@ | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an activity 'id'"}; | ||
err = {msg:'args must include an activity id'}; | ||
return done(err); | ||
@@ -69,3 +69,3 @@ } | ||
args.body = util.getRequestBodyObj(_updateAllowedProps,args); | ||
console.log(args) | ||
util.putEndpoint(endpoint,args,done); | ||
@@ -75,3 +75,3 @@ }; | ||
var endpoint = "activities/" | ||
var endpoint = 'activities/' | ||
, err = null; | ||
@@ -81,3 +81,3 @@ | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an activity 'id'"}; | ||
err = {msg:'args must include an activity id'}; | ||
return done(err); | ||
@@ -91,3 +91,3 @@ } | ||
var endpoint = "activities/following/"; | ||
var endpoint = 'activities/following/'; | ||
this._listHelper(endpoint,args,done); | ||
@@ -97,3 +97,3 @@ }; | ||
var endpoint = "activities/" | ||
var endpoint = 'activities/' | ||
, err = null; | ||
@@ -103,3 +103,3 @@ | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an activity 'id'"}; | ||
err = {msg:'args must include an activity id'}; | ||
return done(err); | ||
@@ -114,3 +114,3 @@ } | ||
var endpoint = "activities/" | ||
var endpoint = 'activities/' | ||
, err = null; | ||
@@ -120,3 +120,3 @@ | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an activity 'id'"}; | ||
err = {msg:'args must include an activity id'}; | ||
return done(err); | ||
@@ -131,3 +131,3 @@ } | ||
var endpoint = "activities/" | ||
var endpoint = 'activities/' | ||
, err = null; | ||
@@ -137,3 +137,3 @@ | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an activity 'id'"}; | ||
err = {msg:'args must include an activity id'}; | ||
return done(err); | ||
@@ -148,3 +148,3 @@ } | ||
var endpoint = "activities/" | ||
var endpoint = 'activities/' | ||
, err = null; | ||
@@ -154,3 +154,3 @@ | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an activity 'id'"}; | ||
err = {msg:'args must include an activity id'}; | ||
return done(err); | ||
@@ -165,3 +165,3 @@ } | ||
var endpoint = "activities/" | ||
var endpoint = 'activities/' | ||
, err = null; | ||
@@ -171,3 +171,3 @@ | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an activity 'id'"}; | ||
err = {msg:'args must include an activity id'}; | ||
return done(err); | ||
@@ -174,0 +174,0 @@ } |
@@ -5,11 +5,11 @@ /** | ||
var util = require("./util"); | ||
var util = require('./util'); | ||
var athlete = {} | ||
, _updateAllowedProps = [ | ||
"city" | ||
, "state" | ||
, "country" | ||
, "sex" | ||
, "weight" | ||
'city' | ||
, 'state' | ||
, 'country' | ||
, 'sex' | ||
, 'weight' | ||
]; | ||
@@ -20,3 +20,3 @@ | ||
var endpoint = "athlete"; | ||
var endpoint = 'athlete'; | ||
util.getEndpoint(endpoint,args,done); | ||
@@ -26,15 +26,15 @@ }; | ||
this._listHelper("friends",args,done); | ||
this._listHelper('friends',args,done); | ||
}; | ||
athlete.listFollowers = function(args,done) { | ||
this._listHelper("followers",args,done); | ||
this._listHelper('followers',args,done); | ||
}; | ||
athlete.listActivities = function(args,done) { | ||
this._listHelper("activities",args,done); | ||
this._listHelper('activities',args,done); | ||
}; | ||
athlete.listClubs = function(args,done) { | ||
this._listHelper("clubs",args,done); | ||
this._listHelper('clubs',args,done); | ||
}; | ||
@@ -44,3 +44,3 @@ | ||
var endpoint = "athlete" | ||
var endpoint = 'athlete' | ||
, body = util.getRequestBodyObj(_updateAllowedProps,args); | ||
@@ -56,3 +56,3 @@ | ||
var endpoint = "athlete/" | ||
var endpoint = 'athlete/' | ||
, err = null | ||
@@ -59,0 +59,0 @@ , qs = util.getPaginationQS(args); |
@@ -5,3 +5,3 @@ /** | ||
var util = require("./util") | ||
var util = require('./util') | ||
; | ||
@@ -14,15 +14,15 @@ | ||
this._listHelper("",args,done); | ||
this._listHelper('',args,done); | ||
}; | ||
athletes.listFriends = function(args,done) { | ||
this._listHelper("friends",args,done); | ||
this._listHelper('friends',args,done); | ||
}; | ||
athletes.listFollowers = function(args,done) { | ||
this._listHelper("followers",args,done); | ||
this._listHelper('followers',args,done); | ||
}; | ||
athletes.listKoms = function(args,done) { | ||
this._listHelper("koms",args,done); | ||
this._listHelper('koms',args,done); | ||
}; | ||
@@ -34,3 +34,3 @@ //===== athletes endpoint ===== | ||
var endpoint = "athletes/" | ||
var endpoint = 'athletes/' | ||
, err = null | ||
@@ -41,3 +41,3 @@ , qs = util.getPaginationQS(args); | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include an athlete 'id'"}; | ||
err = {'msg':'args must include an athlete id'}; | ||
return done(err); | ||
@@ -44,0 +44,0 @@ } |
@@ -5,3 +5,3 @@ /** | ||
var util = require("./util"); | ||
var util = require('./util'); | ||
@@ -13,7 +13,7 @@ var clubs = {}; | ||
var endpoint = "clubs/"; | ||
var endpoint = 'clubs/'; | ||
//require club id | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include a club 'id'"}; | ||
err = {msg:'args must include a club id'}; | ||
return done(err); | ||
@@ -27,7 +27,7 @@ } | ||
this._listHelper("members",args,done); | ||
this._listHelper('members',args,done); | ||
}; | ||
clubs.listActivities = function(args,done) { | ||
this._listHelper("activities",args,done); | ||
this._listHelper('activities',args,done); | ||
}; | ||
@@ -39,3 +39,3 @@ //===== clubs endpoint ===== | ||
var endpoint = "clubs/" | ||
var endpoint = 'clubs/' | ||
, err = null | ||
@@ -46,3 +46,3 @@ , qs = util.getPaginationQS(args); | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include a club 'id'"}; | ||
err = {'msg':'args must include a club id'}; | ||
return done(err); | ||
@@ -49,0 +49,0 @@ } |
@@ -5,3 +5,3 @@ /** | ||
var util = require("./util"); | ||
var util = require('./util'); | ||
@@ -12,7 +12,7 @@ var gear = {}; | ||
var endpoint = "gear/"; | ||
var endpoint = 'gear/'; | ||
//require gear id | ||
if(typeof args.id === 'undefined') { | ||
err = {"msg":"args must include a gear 'id'"}; | ||
err = {msg:'args must include a gear id'}; | ||
return done(err); | ||
@@ -19,0 +19,0 @@ } |
@@ -5,5 +5,5 @@ /** | ||
var util = require("./util") | ||
var util = require('./util') | ||
, request = require('request') | ||
, querystring = require("querystring"); | ||
, querystring = require('querystring'); | ||
@@ -14,7 +14,7 @@ var oauth = {}; | ||
var url = "https://www.strava.com/oauth/authorize?" | ||
var url = 'https://www.strava.com/oauth/authorize?' | ||
, oauthArgs = { | ||
client_id: util.config.client_id | ||
, redirect_uri: util.config.redirect_uri | ||
, response_type: "code" | ||
, response_type: 'code' | ||
}; | ||
@@ -38,3 +38,3 @@ | ||
var endpoint = "oauth/token" | ||
var endpoint = 'oauth/token' | ||
, args = {} | ||
@@ -53,3 +53,3 @@ , body = { | ||
var endpoint = "https://www.strava.com/oauth/deauthorize"; | ||
var endpoint = 'https://www.strava.com/oauth/deauthorize'; | ||
@@ -59,6 +59,6 @@ var url = endpoint | ||
url: url | ||
, method: "POST" | ||
, method: 'POST' | ||
, json: true | ||
, headers: { | ||
Authorization: "Bearer " + args.access_token | ||
Authorization: 'Bearer ' + args.access_token | ||
} | ||
@@ -65,0 +65,0 @@ }; |
@@ -6,7 +6,7 @@ /** | ||
var request = require('request') | ||
, querystring = require("querystring"); | ||
, querystring = require('querystring'); | ||
var util = {}; | ||
util.endpointBase = "https://www.strava.com/api/v3/"; | ||
util.endpointBase = 'https://www.strava.com/api/v3/'; | ||
util.config = {}; | ||
@@ -22,6 +22,7 @@ | ||
//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"}); | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
else if (typeof args.access_token === "undefined") { //add in default access_token, if not overwritten by args | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
@@ -35,3 +36,3 @@ } | ||
, headers: { | ||
Authorization: "Bearer " + args.access_token | ||
Authorization: 'Bearer ' + args.access_token | ||
} | ||
@@ -51,6 +52,7 @@ }; | ||
//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"}); | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
else if (typeof args.access_token === "undefined") { //add in default access_token, if not overwritten by args | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
@@ -60,3 +62,3 @@ } | ||
//stringify the body object for passage | ||
var qs = querystring.stringify(args.body);console.log(qs) | ||
var qs = querystring.stringify(args.body);console.log(qs); | ||
@@ -66,7 +68,7 @@ var url = this.endpointBase + endpoint | ||
url: url | ||
, method: "PUT" | ||
, method: 'PUT' | ||
, json: true | ||
, body: qs | ||
, headers: { | ||
Authorization: "Bearer " + args.access_token | ||
Authorization: 'Bearer ' + args.access_token | ||
} | ||
@@ -86,6 +88,7 @@ }; | ||
//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"}); | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
else if (typeof args.access_token === "undefined") { //add in default access_token, if not overwritten by args | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
@@ -100,7 +103,7 @@ } | ||
url: url | ||
, method: "POST" | ||
, method: 'POST' | ||
, json: true | ||
, body: qs | ||
, headers: { | ||
Authorization: "Bearer " + args.access_token | ||
Authorization: 'Bearer ' + args.access_token | ||
} | ||
@@ -120,6 +123,7 @@ }; | ||
//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"}); | ||
if (typeof args.access_token === 'undefined' && !this.config.access_token) { | ||
return done({'msg': 'you must include an access_token'}); | ||
} | ||
else if (typeof args.access_token === "undefined") { //add in default access_token, if not overwritten by args | ||
//add in default access_token, if not overwritten by args | ||
else if (typeof args.access_token === 'undefined') { | ||
args.access_token = this.config.access_token; | ||
@@ -134,7 +138,7 @@ } | ||
url: url | ||
, method: "DELETE" | ||
, method: 'DELETE' | ||
, json: true | ||
, body: qs | ||
, headers: { | ||
Authorization: "Bearer " + args.access_token | ||
Authorization: 'Bearer ' + args.access_token | ||
} | ||
@@ -151,4 +155,4 @@ }; | ||
//setup pagination query args | ||
var page = typeof args.page !== "undefined" ? args.page : null | ||
, per_page = typeof args.per_page !== "undefined" ? args.per_page : null | ||
var page = typeof args.page !== 'undefined' ? args.page : null | ||
, per_page = typeof args.per_page !== 'undefined' ? args.per_page : null | ||
, qa = {} | ||
@@ -166,4 +170,18 @@ , qs; | ||
}; | ||
//===== generic get query string ===== | ||
util.getQS = function(allowedProps,args) { | ||
var qa = {} | ||
, qs; | ||
for(var i = 0; i < allowedProps.length; i++) { | ||
if(args[allowedProps[i]]) | ||
qa[allowedProps[i]] = args[allowedProps[i]]; | ||
} | ||
qs = querystring.stringify(qa); | ||
return qs; | ||
}; | ||
//===== get request body object ===== | ||
@@ -170,0 +188,0 @@ util.getRequestBodyObj = function(allowedProps,args) { |
{ | ||
"name": "strava-v3", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Simple wrapper for strava v3 api", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha -t 20000" | ||
"test": "grunt jshint simplemocha" | ||
}, | ||
@@ -28,2 +28,5 @@ "repository": { | ||
"devDependencies": { | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-jshint": "^0.10.0", | ||
"grunt-simple-mocha": "^0.4.0", | ||
"mocha": "^1.21.4", | ||
@@ -30,0 +33,0 @@ "should": "^4.0.4" |
# strava-v3: Simple Node wrapper for Strava's v3 API | ||
[![NPM](https://nodei.co/npm/strava-v3.png?downloads=true)](https://nodei.co/npm/strava-v3/) | ||
###Status | ||
@@ -13,2 +15,3 @@ Currently supporting all API calls to endpoints: | ||
* `gear` | ||
* `segments` | ||
@@ -144,1 +147,11 @@ ## Installation | ||
Segments: | ||
* `strava.segments.get(args,done)` | ||
* `strava.segments.listStarred(args,done)` | ||
* `strava.segments.listEfforts(args,done)` | ||
* `strava.segments.listLeaderboard(args,done)` | ||
* `strava.segments.explore(args,done)` | ||
Segment Efforts: | ||
* `strava.segmentEfforts.get(args,done)` | ||
@@ -9,3 +9,3 @@ | ||
describe.only('#get()', function () { | ||
describe('#get()', function () { | ||
@@ -12,0 +12,0 @@ it('should return detailed athlete information about gear (level 3)', function (done) { |
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
45057
31
1147
156
5