lol-api-client
Version:
A Node client for interfacing with the League of Legends API
137 lines (76 loc) • 5.07 kB
Markdown
# lol-api-client [](https://travis-ci.org/kpollich/lol-api-client)
This is a (work in progess) Node module for interfacing with Riot's [developer API](https://developer.riotgames.com/)
View this project on [Github](https://github.com/kpollich/lol-api-client) or [npm](https://www.npmjs.com/package/lol-api-client).
## Installation
Simply run `npm install lol-api-client --save` to install the client as a dependency for your project.
## Usage
Require the client
```javascript
const Client = require('lol-api-client')
```
Instantiate the client. The constructor expects an `apiKey`, a `region`, and a `platformId`. A Riot API key can be acquired [here](https://developer.riotgames.com/). Riot's list of [valid regions](https://developer.riotgames.com/docs/regional-endpoints) provides the supported list of abbreviated region names. If you're not sure what region you should be using, the `global` region will work for most endpoints - though it's up to Riot whether or not that's fully supported. The `platformId` argument is one used in Riot's newer routes such as the Champion Mastery routes. Platforms for each region are indirectly documented at the bottom of [this page](https://developer.riotgames.com/docs/spectating-games) on Riot's developer portal.
```javascript
const client = new Client('your-api-key', 'na', 'NA1')
```
All request methods return a `Promise`. If you typically work with callbacks, or are otherwise new to promises, check out [MDN's docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to get a basic understanding of using promises for async code.
```javascript
client.champions.getAll()
.then(championData => {
const champions = championData.champions
console.log(champions)
})
.catch(error => {
console.error(error)
})
```
## API
### Champions
#### getAll
Riot endpoint: `/champion`
Get all existing champions
#### getById (id)
Riot endpoint: `/champion/{id}`
Get a single champion by its champion id
#### getAllStaticData
Riot endpoint: `/static-data/{region}/{version}/champion`
Get all static champion data. Lore, title, images, etc.
#### getStaticDataById (id)
Riot endpoint: `/static-data/{region}/{version}/champion/{id}`
Get static data for a single champion by champion id
### Matches
#### getById (id)
Riot endpoint: `matches/{matchId}`
Get a single match object by id
#### getMatchListBySummonerId (id)
Riot endpoint: `/matchlist/by-summoner/{summonerId}`
Get a list of recent matches for the provided summoner id.
### Summoners
#### getByName (name) or ([names])
Riot endpoint: `summoners/by-name/{summonerNames}`
Get a list of summoner objects from a provided array of names or a single summoner object from a provided summoner name.
#### getById (id) or ([ids])
Riot endpoint `summoners/{summonerIds}`
Get a list of summoner objects from a provided array of ids or a single summoner object from a provided summoner id.
#### getMasteryPagesById (id) or ([ids])
Riot endpoint `summoners/{summonerIds}/masteries`
Get a set of mastery pages objects for the provided or summoner or multiple sets of mastery pages for a provided
array of summoner ids.
### getRunePagesById (id) or ([ids])
Riot endpoint `summoners/{summonerIds}/runes`
Get a set of rune pages objects for the provided or summoner or multiple sets of rune pages for a provided
array of summoner ids.
### Champion Mastery
#### getByPlayerAndChampion (playerId, championId)
Riot endpoint: `/championmastery/location/{platformId}/player/{playerId}/champion/{championId}`
Get a Champion Mastery object for a given player on a specific champion.
#### getAllByPlayer (playerId)
Riot endpoint: `/championmastery/location/{platformId}/player/{playerId}/champions`
Get all mastery scores for the provided player
#### getScore (playerId)
Riot endpoint: `/championmastery/location/{platformId}/player/{playerId}/score`
Get a player's total champion mastery score
#### getTopChampions (playerId)
Riot endpoint: `/championmastery/location/{platformId}/player/{playerId}/topchampions`
Get a player's top three highest champion mastery scores.
## Contributing
If you'd like to contribute to this project, you can [file an issue](https://github.com/kpollich/lol-api-client/issues/new). When you've completed work and are looking for review, [file a pull request](https://github.com/kpollich/lol-api-client/compare) from your fork of this repository. This project uses [Javascript Standard Style](http://standardjs.com/rules.html), and `standard` is listed as a dev dependency. There are linter plugins for Atom, Sublime Text and more that can be found on [standard's Github page](https://github.com/feross/standard). `npm test` will lint all code and Travis will fail if `standard` throws any code style errors. This ensures that there are no pointless discussions about code style, and we can actually discuss implementation, logic, etc during code review.