Skip to content

Commit 60e7b7a

Browse files
committed
Modernize README
- More examples use promises/await instead of callbacks - Improve Markdown formatting - Add Author / Maintainer section
1 parent e89c30c commit 60e7b7a

File tree

1 file changed

+71
-68
lines changed

1 file changed

+71
-68
lines changed

README.md

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ The template `strava_config` file can be found at the modules root directory and
103103

104104
```json
105105
{
106-
, "client_id" :"Your apps Client ID (Required for oauth)"
107-
, "client_secret" :"Your apps Client Secret (Required for oauth)"
108-
, "redirect_uri" :"Your apps Authorization Redirection URI (Required for oauth)"
106+
"access_token" : "Your apps access token (Required for Quickstart)",
107+
"client_id" : "Your apps Client ID (Required for oauth)",
108+
"client_secret" : "Your apps Client Secret (Required for oauth)",
109+
"redirect_uri" : "Your apps Authorization Redirection URI (Required for oauth)",
109110
}
110111
```
111112

@@ -134,33 +135,29 @@ strava.athletes.get({id:12345},function(err,payload,limits) {
134135

135136
### Overriding the default `access_token`
136137

137-
You'll may want to use OAuth `acceess_token`s on behalf of specific users once
138+
You'll may want to use OAuth `access_token`s on behalf of specific users once
138139
your app is in production. Using an `access_token` specific to a validated user
139140
allows for detailed athlete information, as well as the option for additional
140141
`PUT`/`POST`/`DELETE` privileges.
141142

142-
Use app-specific logic to retrieve the access\_token for a particular user, then create a Strava client for that user, with their token:
143+
Use app-specific logic to retrieve the `access\_token` for a particular user, then create a Strava client for that user, with their token:
143144

144145
```js
145-
var stravaApi = require('strava-v3');
146+
const stravaApi = require('strava-v3');
146147

147148
// ... get access_token from somewhere
148149
strava = new stravaApi.client(access_token);
149150

150-
strava.athlete.get(function(err,payload,limits) {
151-
//do something with your payload, track rate limits
152-
});
151+
const payload = await strava.athlete.get({})
153152
```
154153

155-
Less conveniently, you can also explictly pass an access\_token to API calls:
154+
Less conveniently, you can also explictly pass an `access_token` to API calls:
156155

157156
Example usage:
158157

159158
```js
160-
var strava = require('strava-v3');
161-
strava.athlete.get({'access_token':'abcde'},function(err,payload,limits) {
162-
//do something with your payload, track rate limits
163-
});
159+
const strava = require('strava-v3');
160+
const payload = await strava.athlete.get({'access_token':'abcde'})
164161
```
165162

166163
### Dealing with pagination
@@ -170,12 +167,10 @@ For those API calls that support pagination, you can control both the `page` bei
170167
Example usage:
171168

172169
```js
173-
var strava = require('strava-v3');
174-
strava.athlete.listFollowers({
175-
'page':1
176-
, 'per_page':2
177-
},function(err,payload,limits) {
178-
//do something with your payload, track rate limits
170+
const strava = require('strava-v3');
171+
const payload = await strava.athlete.listFollowers({
172+
page: 1,
173+
per_page: 2
179174
});
180175
```
181176

@@ -185,16 +180,14 @@ To upload a file you'll have to pass in the `data_type` as specified in Strava's
185180
Example usage:
186181

187182
```js
188-
var strava = require('strava-v3');
189-
strava.uploads.post({
190-
'data_type':'gpx'
191-
, 'file': 'data/your_file.gpx'
192-
, 'name': 'Epic times'
193-
, 'statusCallback': function(err,payload) {
183+
const strava = require('strava-v3');
184+
const payload = await strava.uploads.post({
185+
data_type: 'gpx',
186+
file: 'data/your_file.gpx',
187+
name: 'Epic times',
188+
statusCallback: (err,payload) => {
194189
//do something with your payload
195190
}
196-
},function(err,payload,limits) {
197-
//do something with your payload, track rate limits
198191
});
199192
```
200193

@@ -221,7 +214,7 @@ rate limiting we use a global counter accessible through `strava.rateLimiting`.
221214
#### Callback interface (Rate limits)
222215

223216
```js
224-
var strava = require('strava-v3');
217+
const strava = require('strava-v3');
225218
strava.athlete.get({'access_token':'abcde'},function(err,payload,limits) {
226219
//do something with your payload, track rate limits
227220
console.log(limits);
@@ -240,14 +233,16 @@ strava.athlete.get({'access_token':'abcde'},function(err,payload,limits) {
240233

241234
To used the Promise-based API, do not provide a callback. A promise will be returned.
242235

243-
Oauth:
236+
See Strava API docs for returned data structures.
237+
238+
#### OAuth
244239

245240
* `strava.oauth.getRequestAccessURL(args)`
246241
* `strava.oauth.getToken(code,done)` (Used to token exchange)
247242
* `strava.oauth.refreshToken(code)` (Callback API not supported)
248243
* `strava.oauth.deauthorize(args,done)`
249244

250-
Athlete:
245+
#### Athlete
251246

252247
* `strava.athlete.get(args,done)`
253248
* `strava.athlete.update(args,done)` // only 'weight' can be updated.
@@ -256,12 +251,12 @@ Athlete:
256251
* `strava.athlete.listClubs(args,done)`
257252
* `strava.athlete.listZones(args,done)`
258253

259-
Athletes:
254+
#### Athletes
260255

261256
* `strava.athletes.get(args,done)` *Get a single activity. args.id is required*
262257
* `strava.athletes.stats(args,done)`
263258

264-
Activities:
259+
#### Activities
265260

266261
* `strava.activities.get(args,done)`
267262
* `strava.activities.create(args,done)`
@@ -274,7 +269,7 @@ Activities:
274269
* `strava.activities.listPhotos(args,done)`
275270
* `strava.activities.listRelated(args,done)`
276271

277-
Clubs:
272+
#### Clubs
278273

279274
* `strava.clubs.get(args,done)`
280275
* `strava.clubs.listMembers(args,done)`
@@ -285,51 +280,51 @@ Clubs:
285280
* `strava.clubs.joinClub(args,done)`
286281
* `strava.clubs.leaveClub(args,done)`
287282

288-
Gear:
283+
#### Gear
289284

290285
* `strava.gear.get(args,done)`
291286

292-
Push Subscriptions:
287+
#### Push Subscriptions
293288

294289
These methods Authenticate with a Client ID and Client Secret. Since they don't
295290
use OAuth, they are not available on the `client` object.
296291

297-
* `strava.pushSubscriptions.list({},done)`
298-
* `strava.pushSubscriptions.create({callback_url:...},done)`
292+
* `strava.pushSubscriptions.list({},done)`
293+
* `strava.pushSubscriptions.create({callback_url:...},done)`
299294
* We set 'object\_type to "activity" and "aspect\_type" to "create" for you.
300-
* `strava.pushSubscriptions.delete({id:...},done)`
295+
* `strava.pushSubscriptions.delete({id:...},done)`
301296

302-
Running Races:
297+
#### Running Races
303298

304-
* `strava.runningRaces.get(args,done)`
305-
* `strava.runningRaces.listRaces(args,done)`
299+
* `strava.runningRaces.get(args,done)`
300+
* `strava.runningRaces.listRaces(args,done)`
306301

307-
Routes:
302+
#### Routes
308303

309-
* `strava.routes.get(args,done)`
310304

311-
Segments:
305+
* `strava.routes.get(args,done)`
312306

313-
* `strava.segments.get(args,done)`
314-
* `strava.segments.listStarred(args,done)`
315-
* `strava.segments.listEfforts(args,done)`
316-
* `strava.segments.listLeaderboard(args,done)`
317-
* `strava.segments.explore(args,done)`
307+
#### Segments
318308

319-
Segment Efforts:
309+
* `strava.segments.get(args,done)`
310+
* `strava.segments.listStarred(args,done)`
311+
* `strava.segments.listEfforts(args,done)`
312+
* `strava.segments.listLeaderboard(args,done)`
313+
* `strava.segments.explore(args,done)`
320314

321-
* `strava.segmentEfforts.get(args,done)`
315+
#### Segment Efforts
322316

323-
Streams:
317+
* `strava.segmentEfforts.get(args,done)`
324318

325-
* `strava.streams.activity(args,done)`
326-
* `strava.streams.effort(args,done)`
327-
* `strava.streams.segment(args,done)`
319+
#### Streams
328320

329-
Uploads:
321+
* `strava.streams.activity(args,done)`
322+
* `strava.streams.effort(args,done)`
323+
* `strava.streams.segment(args,done)`
330324

331-
* `strava.uploads.post(args,done)`
325+
#### Uploads
332326

327+
* `strava.uploads.post(args,done)`
333328

334329
## Error Handling
335330

@@ -339,7 +334,8 @@ Promise-based API, the promise will be rejected. An error of type
339334
`RequestError` will be returned if the request fails for technical reasons.
340335
Example error checking:
341336

342-
var errors = require('request-promise/errors')
337+
```javascript
338+
const errors = require('request-promise/errors')
343339

344340
// Catch a non-2xx response with the Promise API
345341
badClient.athlete.get({})
@@ -349,7 +345,7 @@ Example error checking:
349345
badClient.athlete.get({},function(err,payload){
350346
// err will be instanceof errors.StatusCodeError
351347
}
352-
348+
```
353349
354350
## Development
355351
@@ -358,20 +354,20 @@ It will both lint and run shallow tests on API endpoints.
358354
359355
### Running the tests
360356
361-
You'll first need to supply `data/strava_config` with an `access_token` that has both private read and write permissions:
357+
You'll first need to supply `data/strava_config` with an `access_token` that
358+
has both private read and write permissions. Look in `./scripts` for a tool
359+
to help generate this token. Going forward we plan to more testing with a mocked
360+
version of the Strava API so testing with real account credentials are not required.
362361
363362
* Make sure you've filled out all the fields in `data/strava_config`.
364363
* Use `strava.oauth.getRequestAccessURL({scope:"view_private,write"})` to generate the request url and query it via your browser.
365364
* Strava will prompt you (the user) to allow access, say yes and you'll be sent to your Authorization Redirection URI - the parameter `code` will be included in the redirection url.
366365
* Exchange the `code` for a new `access_token`:
367366
368367
```js
369-
strava.oauth.getToken(code,function(err,payload,limits) {
370-
// access_token is at payload.access_token
371-
console.log(payload);
372-
});
368+
// access_token is at payload.access_token
369+
const payload = await strava.oauth.getToken(authorizationCode)
373370
```
374-
375371
Finally, the test suite has some expectations about the Strava account that it
376372
connects for the tests to pass. The following should be true about the Strava
377373
data in the account:
@@ -382,7 +378,8 @@ data in the account:
382378
* Must have created at least one route
383379
* Most recent activity with an achievement should also contain a segment
384380
385-
(Contributions to make the test suite more self-contained and robust are welcome!)
381+
(Contributions to make the test suite more self-contained and robust by converting more tests
382+
to use `nock` are welcome!)
386383
387384
* You're done! Paste the new `access_token` to `data/strava_config` and go run some tests:
388385
@@ -404,11 +401,17 @@ Strava API.
404401
405402
To enable this, set this in the environment before this module is loaded:
406403
407-
NODE_DEBUG=request
404+
NODE\_DEBUG=request
408405
409406
You can also set `process.env.NODE_DEBUG='request' in your script before this module is loaded.
410407

411408
## Resources
412409

413410
* [Strava Developers Center](http://www.strava.com/developers)
414411
* [Strava API Reference](https://developers.strava.com/docs/reference/)
412+
413+
## Author and Maintainer
414+
415+
Authored by Austin Brown <austin@unboundev.com> (http://austinjamesbrown.com/).
416+
417+
Currently Maintained by Mark Stosberg <mark@rideamigos.com>

0 commit comments

Comments
 (0)