teemojs v1.11.0
TeemoJS
TeemoJS is a fast and lightweight Riot API wrapper written in Node.js. Contained in about 300 lines, it has a minimalist design to make it flexible and easy to maintain. There is a specific set of things TeemoJS aims to do, and it aims to do them well:
- Fast & Efficient Rate Limiting
- Automatic Retries
It is up to the developer to do the rest.
TeemoJS supports the new TFT APIs.
Installation
npm install --save teemojsUsage
const TeemoJS = require('teemojs');
let api = TeemoJS('RGAPI-KEY-HERE');
api.get('na1', 'summoner.getBySummonerName', 'LUG nutsk')
.then(data => console.log(data.name + "'s summoner id is " + data.id + '.'));
// Get C9 Sneaky's games on Ezreal and Kalista for a particular season.
api.get('na1', 'match.getMatchlist', 78247, { champion: [81, 429], season: 8 })
.then(...);All requests are done via .get(...).
- The first argument is the region.*
- The second is the
endpoint"path", period-delimited. (seedefaultConfig.json). - Then come any path arguments (usually zero or one, or two for
getChampionMastery) which are for summoner/match IDs, names, etc. - Last is an optional object for any query parameters.
*Note: this is optional if config.origin isn't interpolated in custom or Champion.GG configurations.
Configuration
The TeemoJS constructor can take an second argument which is a configuration object.
defaultConfig.json
is used by default. The supplied config object will override any corresponding values in the defaultConfig.
The configuration specifies the number of retries and maximum concurrent requests, as well as the Riot API
endpoint URLs.
Constructors with config
let api = TeemoJS('RGAPI-KEY-HERE', config);
let api = TeemoJS(configWithKey);config Object
retriesint: Number of times to retry request if the request fails with a retriable error. Zero for no retires.maxConcurrentint: Maximum live requests to allow.distFatorfloat 0..1: Factor to multiply rate limits by. This can be changed at any time using theapi.setDistFactor(x)method. For example, if your API key was distributed across two computers, you could set this to 0.5.keyOPTIONAL string: Overrides thekeyargument passed into the constructor. Do not set unless you actually use this key.
Only modify the following properties if you know what you're doing. This is mainly documentation for future reference.
origininterpolated string: String containing the protocol and host without a trailing forward slash. May have one%sfor the region or none if the API has no separate regions.defaultBuckets[object[]]: Array of configuration options for a rate limit's default buckets. These buckets remain in use until the actual rate limit is detected via headers. Each must have at leasttimespan(in milliseconds) andlimit.rateLimitTypeApplicationobject: Rate limit type object for the application rate limit. Containing stringsname,headerLimit, andheaderCount.nameis the name of the rate limit used for detecting which type caused a 429.headerLimitandheaderCountare header names for the max rate limit and rate limit count respectively.rateLimitTypeMethodobject/null: Same asrateLimitTypeApplicationbut for method rate limits. May be null if the API does not have per-method rate limits.defaultRetryAfterstring/null: Default retry after in seconds if theheaderRetryAfteris not provided in a 429. Usenullto cause missingheaderRetryAfterheaders to throw an error.headerRetryAfterstring/null: Header name to look for retry after time in seconds when a 429 is hit. Ifnull,defaultRetryAftershould be set.headerLimitTypestring: Header name to match with thenameof a rateLimitType to determine which rate limit hit a 429.defaultLimitTypestring/null: Defaultnamevalue to use when the API doesn't return which limit is hit. Set tonullto throw an error if a 429 happens for no reason. Set torateLimitTypeXYZ.nameto default to rate limit type XYZ.keyHeaderstring/null: Name of header to put key in ornullto use query parameters.keyQueryParamstring/null: Name of query parameter to put key in.keyHeadermust be set tonullfor this to be used.collapseQueryArraysboolean: Iffalse, query arrays will be represented asa=1&a=2&a=3. Iftrue,a=1,2,3will be used. Riot API uses the former, champion.gg uses the later.endpointsnested object: A (optionally) nested object structure where the leaf values are API endpoint URLs with leading forward slashes. Objects may be nested to any level for organizational purposes. When using the API, the period-delimited path is supplied.
Setting defaultConfig & Other premade configurations
defaultConfig is stored in the TeemoJS.defaultConfig property and can be changed if needed.
There are three more premade configurations provided:
TeemoJS.emptyConfigis the same asTeemoJS.defaultConfigbut without anyendpoints.TeemoJS.championGGConfigis a configuration for the Champion.GG API. Oh, by the way, TeemoJS also supports the Champion.GG API.- (
TeemoJS.ddragonConfigTODO)
Champion.GG Example:
let api = TeemoJS('cgg0api0key', TeemoJS.championGGConfig);
api.get('champion.getChampion', 143)
.then(data => console.log("Zyra's winrate as " + data[0].role + ' is ' + data[0].winRate + '.'));2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago