https://github.com/nehle/open-shl
Node.js client library for the open SHL API
https://github.com/nehle/open-shl
Last synced: about 1 year ago
JSON representation
Node.js client library for the open SHL API
- Host: GitHub
- URL: https://github.com/nehle/open-shl
- Owner: Nehle
- License: isc
- Created: 2016-01-09T01:58:36.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-01-21T21:50:32.000Z (over 5 years ago)
- Last Synced: 2025-04-17T17:23:51.714Z (about 1 year ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
#open-shl
[](https://travis-ci.org/Nehle/open-shl)
Node.js client for the open SHL (Swedish Hockey League) API. Developed with and for node.js 5+
## Install
`npm install --save open-shl`
## Usage
First make sure you have a valid `clientId` and `clientSecret` for the API,
which can be gained by emailing support@shl.se
After that, you can access the api thusly:
```javascript
const shl = require("open-shl");
const options = {
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
userAgent: "YourUserAgent" // Optional
}
const client = shl.connect(options);
```
### The SHL API
This client is built to mimic the API as documented on http://doc.openapi.shl.se
Many methods support extra query parameters, if they are supported in the API
they can be supplied in an optional `query` argument as final (or only) parameter
to the matching method. Most of the time this is the `teamId`, which is supplied
as an array of three letter team codes.
#### `client.season(season)`
**Parameters**
- `season: int`: The year the season started
**Returns**
- `season`: The `season` API object
#### `season.games([query])`
Fetches all games for the season
**Query Properties**
- `teamIds: string[]`: List of team codes of to include. Leave empty to include all teams
**Returns**
- `Promise`: Promise of all games for the season
#### `season.game(gameId)`
Fetches a specific games
**Parameters**
- `gameId: int`: Id for the game to fetch
**Returns**
- `Promise`: The game with the specified id
#### `season.statistics.goalkeepers([query])`
Gets the top goalkeepers for the season
**Query Properties**
- `teamIds: string[]`: List of teams to include. Leave empty to include all teams
- `sort: string`: What attribute to sort on: `saves|savesPercent|goalsAgainst|goalsAgainstAverage|won|tied|lost|shooutOuts|minutesInPlay`
**Returns**
- `Promise`: Statistics for all goalkeepers during that season
#### `season.statistics.players([query])`
Gets the top players for the season
**Query Properties**
- `teamIds: string[]`: List of teams to include. Leave empty to include all teams
- `sort: string`: What attribute to sort the players on `assists|goals|points|pim|hits|plusminus`
**Returns**
- `Promise`: Statistics for top players during that season
#### `season.statistics.teams.standings([query])`
Get current standings for that season
**Query Properties**
- `teamIds: string[]`: List of teams to include. Leave empty to include all teams
**Returns**
- `Promise`: List of all teams and their current standing
#### `client.teams()`
Get a list of all teams
**Returns**
- `Promise`: A list of basic facts for all teams in the SHL
#### `client.team(teamCode)`
Get details for a particular team.
**Parameters**
- `teamCode: String`: is the three-character team code. i.e. "FHC" for Frölunda HC
**Returns**
- `Promise`: All information about the requested team. Includes team facts, player facts and more
#### `client.videos([query])`
Get the ten latest videos
**Query Properties**
- `teamIds: string[]`: List of teams to include. Leave empty to include all teams
**Returns**
- `Promise`: Ten latest videos
#### `client.articles([query])`
Get the latest articles
**Query Properties**
- `teamIds: string[]`: List of teams to include. Leave empty to include all teams
**Returns**
- `Promise`: Ten latest articles
## Examples
```javascript
const shl = require("open-shl");
let client = shl.connect({clientId: "", clientSecret:""});
// Fetch the current standings
client.season(2015).statistics.teams.standings()
.then(teams => {
console.log(teams[0].team_code, "is currently leading the SHL");
});
//Fetch the top hitters between FHC and FBK
client.season(2015).statistics.players({sort: "hits", teamIds: ["FHC", "FBK"]})
.then(players => {
console.log("Between FBK and FHC, ", players[0].info.first_name, players[0].info.last_name, ", hits the most")
});
```
## License ##
Copyright © 2016, Jakob Nilsson-Ehle.
Published under [ISC license](https://opensource.org/licenses/ISC). See [LICENSE.md](LICENSE.md)