1.0.0 • Published 2 years ago

lor-api-wrapper v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

lor-api-wrapper

Node.js Riot Legends of Runeterra API Wrapper

Features

  • HTTPS REST API
  • Easy access to API responses
  • Supports all LoR API endpoints
  • No additional dependences required

Installation

Install lifx-api-wrapper with npm:

  npm install lor-api-wrapper

To run this project, you will need a RIOT API key. Get your key here: https://developer.riotgames.com/

Usage

Getting started

import Lor from "lor-api-wrapper.js";

//create instance with our Riot API Token
var lor = new Lor(lorKey);

//Now lor will always use your key

Specify what region to pull from

There are three regions available to pull data from:

  • Americas
  • Europe
  • SEA

Specify the region you want to pull from when calling your request.

//GET USER PUUID BY NAME AND TAG
var puuid = await lor.getUserByName('Otzo', 'Otzo', 'Americas')

API Reference

The wrapper is designed to use selectors that match RIOT API documentation to simply use.

For more information visit api.riotgames.com.

lor.getUserByPuuid(puuid, region)

ParameterTypeExampleDescription
puuidstring'K-1NczBPzqHG1Ab...'Required
regionstring'Americas'Required

lor.getUserByName(userName, tagLine, region)

ParameterTypeExampleDescription
userNamestring'Otzo'Required
tagLinestring'NA'Required
regionstring'Americas'Required

Note: This returns the same information as lor.getUserByPuuid(). The main difference is how you reference the user. Most likely you'll use their userName and tagLine in order to get their puuid for later use.

Example response:

{puuid: 'HfYckhbhJnSBzZZmcIvAJHy4Zpg9rEBeuom5gAIe60boHI7Vtb6D7pFqjIfpMdafWKEhZ0oFNUZCzA', 
gameName: 'Otzo', 
tagLine: 'NA'}

lor.getUserMatchHistory(puuid, region)

Returns matchId's for the last 20 games played by selected user.

ParameterTypeExampleDescription
puuidstring'K-1NczBPzqHG1Ab...'Required
regionstring'Americas'Required

Example response:

[
'bcdb95bc-beab-4e59-907d-2eff75aabd98', 
...
'7f10f485-3217-4a3b-bf22-4f63e19fb689', 
'cf36602d-215c-4a00-b0db-309f16695fed', 
'312174dd-2a52-4979-ae04-31aeed0ad7e4'
]

lor.getMatchDetails(matchId, region)

Returns match info, including: players, who won, decks played, and more.

ParameterTypeExampleDescription
matchIdstring'bcdb95bc-beab-4...'Required
regionstring'Americas'Required

lor.getLeaderboard(region)

Returns top players in that region, including: puuid, userName, and tagLine.

ParameterTypeExampleDescription
regionstring'Americas'Required

lor.getLorStatus(region)

Returns current server status for that region.

ParameterTypeExampleDescription
regionstring'Americas'Required

Examples

Grab list of top players in the Americas

var leaderboard = await lor.getLeaderboard('Americas')
    .then((data) => {
        var json = JSON.parse(data.body)

        return json
    }) //catch errors
    .catch((err) => console.log(err));

// do stuff with data
console.log(leaderboard['players'])

Find user's PUUID by userName and tagLine

var puuid = await lor.getUserByName('Otzo', 'Otzo', 'Americas')
    .then((data) => {
        var json = JSON.parse(data.body)

        return json.puuid
    }) //catch errors
    .catch((err) => console.log(err));

//do stuff with data
console.log(puuid);

Grab list of most recently played games by user PUUID

var matches = await lor.getUserMatchHistory(puuid, 'Americas')
    .then((data) => {
        var json = JSON.parse(data.body)

        return json
    }) //catch errors
    .catch((err) => console.log(err));

//do stuff with data
console.log(matches);

Feedback

I wrote this wrapper to use in my personal project. My goal was to not only to reduce outside dependencies in my own projects, but also make the API easier to use.

Writing this wrapper introduced me to javascript prototypes, classes, publishing NPM packages, and exporting/importing ES modules.

Any and all feedback is appreciated.

🔗 Links

telegram twitter wakatime