-
Notifications
You must be signed in to change notification settings - Fork 109
/
index.js
85 lines (71 loc) · 2.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const HttpClient = require('./lib/httpClient')
const oauth = require('./lib/oauth')
const authenticator = require('./lib/authenticator')
const Athlete = require('./lib/athlete')
const Athletes = require('./lib/athletes')
const Activities = require('./lib/activities')
const Clubs = require('./lib/clubs')
const Gear = require('./lib/gear')
const Segments = require('./lib/segments')
const SegmentEfforts = require('./lib/segmentEfforts')
const Streams = require('./lib/streams')
const Uploads = require('./lib/uploads')
const rateLimiting = require('./lib/rateLimiting')
const RunningRaces = require('./lib/runningRaces')
const Routes = require('./lib/routes')
const PushSubscriptions = require('./lib/pushSubscriptions')
const request = require('request-promise')
const version = require('./package.json').version
const strava = {}
strava.defaultRequest = request.defaults({
baseUrl: 'https://www.strava.com/api/v3/',
headers: {
'User-Agent': 'node-strava-v3 v' + version
}
})
strava.client = function (token, request) {
this.access_token = token
this.request = request || strava.defaultRequest
this.request = this.request.defaults({
headers: {
'Authorization': 'Bearer ' + this.access_token
}
})
var httpClient = new HttpClient(this.request)
this.athlete = new Athlete(httpClient)
this.athletes = new Athletes(httpClient)
this.activities = new Activities(httpClient)
this.clubs = new Clubs(httpClient)
this.gear = new Gear(httpClient)
this.segments = new Segments(httpClient)
this.segmentEfforts = new SegmentEfforts(httpClient)
this.streams = new Streams(httpClient)
this.uploads = new Uploads(httpClient)
this.rateLimiting = rateLimiting
this.runningRaces = new RunningRaces(httpClient)
this.routes = new Routes(httpClient)
// No Push subscriptions on the client object because they don't use OAuth.
}
strava.config = authenticator.fetchConfig
strava.oauth = oauth
// The original behavior was to use global configuration.
strava.defaultHttpClient = new HttpClient(strava.defaultRequest.defaults({
headers: {
'Authorization': 'Bearer ' + authenticator.getToken()
}
}))
strava.athlete = new Athlete(strava.defaultHttpClient)
strava.athletes = new Athletes(strava.defaultHttpClient)
strava.activities = new Activities(strava.defaultHttpClient)
strava.clubs = new Clubs(strava.defaultHttpClient)
strava.gear = new Gear(strava.defaultHttpClient)
strava.segments = new Segments(strava.defaultHttpClient)
strava.segmentEfforts = new SegmentEfforts(strava.defaultHttpClient)
strava.streams = new Streams(strava.defaultHttpClient)
strava.uploads = new Uploads(strava.defaultHttpClient)
strava.rateLimiting = rateLimiting
strava.runningRaces = new RunningRaces(strava.defaultHttpClient)
strava.routes = new Routes(strava.defaultHttpClient)
strava.pushSubscriptions = new PushSubscriptions(strava.defaultHttpClient)
// and export
module.exports = strava