strava-api-handler
Version:
Unofficial handler for Strava API
78 lines (53 loc) • 2.24 kB
Markdown
# Strava API handler
[](https://badge.fury.io/js/strava-api-handler)
[](https://renovateapp.com/)
[](https://snyk.io/test/github/fabulator/strava-api-handler)
[](https://codecov.io/gh/fabulator/strava-api-handler)
[](https://travis-ci.org/fabulator/strava-api-handler)
This an unofficial handler for Strava API. Methods for getting, creating and filtering activities are incorporated in API class, other endpoints can be called manually.
## How it works
It uses a library for handling REST API request - [rest-api-handler](https://github.com/fabulator/rest-api-handler). It is based on browser fetch feature so it needs polyfill.
## How to use
Install npm library:
```
npm install strava-api-handler --save
```
Include fetch polyfill. I recommend cross-fetch:
```javascript
import 'cross-fetch/polyfill';
```
### Authentize
You need to use oAuth. First get login url and then autentize through the code.
```javascript
const { Api, ApiScope } = require('./../dist');
(async () => {
const api = new Api('CLIENT_ID', 'CLIENT_SECRET');
// generate login link
console.log(api.getLoginUrl('http://developers.strava.com', [ApiScope.READ_ALL]));
// use it and get code
const token = await api.requestToken({ code: 'AUTH_CODE', grant_type: 'authorization_code' });
// this is token
console.log(token);
// later
// save it and use later
api.setAccessToken(token.access_token);
})();
```
### Getting workout/s
To get single activity use getActivity method:
```javascript
const activity = await api.getActivity(775131509);
```
Search for activities:
```javascript
const { DateTime } = require('luxon');
const activities = await api.getActivities({
after: DateTime.fromObject({
year: 2018,
month: 3,
day: 1,
}),
per_page: 2,
});
console.log(activities);
```