npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fightmegg/riot-api

v0.0.19

Published

Client for for interactacting with Riot Games API

Downloads

952

Readme

RiotAPI

Version Downloads CircleCI

Node.JS minimal Riot API client written in Typescript

Features

  • Rate limiting through @fightmegg/riot-rate-limiter
  • Automatic retries
  • TypeScript typings
  • 100% endpoint coverage (incl. DDragon)
  • Caching with custom ttls per endpoint
  • Request prioritization

Installation

$ npm install @fightmegg/riot-api

Usage

import { RiotAPI, RiotAPITypes, PlatformId } from '@fightmegg/riot-api'

(async () => {
    const rAPI = new RiotAPI('RGAPI-KEY');

    const summoner = await rAPI.summoner.getBySummonerName({
        region: PlatformId.EUW1,
        summonerName: "Demos Kratos",
      });
})()

Config

const config: RiotAPITypes.Config = {
    debug: false,
    cache: {
        cacheType: 'ioredis', // local or ioredis
        client: 'redis://localhost:6379', // leave null if client is local
        ttls: {
            byMethod: {
                [RiotAPITypes.METHOD_KEY.SUMMONER.GET_BY_SUMMONER_NAME]: 5000, // ms
            }
        }
    }
}

const rAPI = new RiotAPI('RGAPI-TOKEN', config);

Error handling

If you use Promises then any error will reject the promise, this can either be an error value, or the response from the API.

Same as above with async/await, where the error thrown will be the response from the API if the error occured at that level.

Caching

Caching is turned off by default, but with the cache property in the config you can enable it with various settings. For now we only support local (in memory) or ioredis caches, will potential support for custom caches in future.

When setting up the cache, you can change the ttl of each method / endpoint individually. This is done through the METHOD_KEY type which can be found in the typings file.

DDragon

We also fully support DataDragon which can be accessed in two ways:

// ...
const rAPI = new RiotAPI('RGAPI-KEY');

const latestV = await rAPI.ddragon.versions.latest();
const champs = await rAPI.ddragon.champion.all();

If you want to just use static data only, then you can do the following:

import { DDragon } from '@fightmegg/riot-api';

const ddragon = new DDragon();
const champs = await ddragon.champion.all();

Just like the main API, we have full TypeScript typings for DDragon endpoints. Please note we do not support caching for DDragon endpoints.

TypeScript typing

import { RiotAPI, RiotAPITypes, PlatformId } from '@fightmegg/riot-api';

// ...

const summoner: RiotAPITypes.Summoner.SummonerDTO = await rAPI.summoner.getBySummonerName(...);

Debugging

If you want to see want the rate-limiter is currently doing, we use the debug module for logging. Simply run your app with:

DEBUG=riotapi* node ...

Testing

Unit tests: npm test

E2E tests: npm run test:e2e

Planned features

  • [ ] Custom Caches
  • [ ] Interceptors (before request & on response)

Maintainers

@olliejennings