<commit_before>A small library to work with Riot's League of Legend's API.

[![NPM](https://nodei.co/npm/kayn.png)](https://nodei.co/npm/kayn/)

[![Build Status](https://travis-ci.org/cnguy/kayn.svg?branch=master)](https://travis-ci.org/cnguy/kayn)
[![codecov](https://codecov.io/gh/cnguy/kayn/branch/master/graph/badge.svg)](https://codecov.io/gh/cnguy/kayn)
[![dependencies Status](https://david-dm.org/cnguy/kayn/status.svg)](https://david-dm.org/cnguy/kayn)

# Table of Contents:
* [Features](#features)
* [Methods](https://github.com/cnguy/kayn/blob/master/COVERAGE.md)
* [Installation & Usage](#installation-and-usage)
* [Configuration](#configuration)
* [My Project](#my-project)
* [Bugs / Changelog / Disclaimer](#bugs)

# Features

## Rate Limiting

Handled by [Colorfulstan](https://github.com/Colorfulstan)'s wonderful [riot-ratelimiter](https://github.com/Colorfulstan/RiotRateLimiter-node).

## All Endpoints Covered

Check out [COVERAGE.md](https://github.com/cnguy/kayn/blob/master/COVERAGE.md) to see the League of Legends API endpoints side-by-side with `kayn`'s methods.

## Caching

Currently supports a basic JS cache (for simple scripts) and Redis for anything more complicated.

## Compatible with Callbacks, Promises, Async / Await

## Good TypeScript Support

Works immediately upon installation.

As of v0.8.0, full DTO's are provided thanks to [MingweiSamuel](https://github.com/MingweiSamuel)'s [auto-updated Swagger JSON](https://github.com/MingweiSamuel/riotapi-schema).

# Installation and Usage

The minimum required [Node.js version is v7.6.0](https://nodejs.org/en/blog/release/v7.6.0/) for native async/await support (there's only a mere line in the codebase, though).

## npm

```sh
npm i --save kayn
```

## yarn

```sh
yarn add kayn
```

### Quick Setup with [Default Config](https://github.com/cnguy/kayn/blob/master/lib/KaynConfig.js)

```javascript
const { Kayn, REGIONS } = require('kayn')
const kayn = Kayn('RGAPI-my-api-key')(/*{
    region: REGIONS.NORTH_AMERICA,
    debugOptions: {
        isEnabled: true,
        showKey: false,
        loggers: {},
    },
    requestOptions: {
        shouldRetry: true,
        numberOfRetriesBeforeAbort: 3,
        delayBeforeRetry: 1000,
        burst: false,
    },
    cacheOptions: {
        cache: null,
        ttls: {},
    },
}*/)
```

**Note: Any config passed in is deeply merged with the default config.**

### Environment Variables

```javascript
const kayn = Kayn(/* process.env.RIOT_LOL_API_KEY */)(myConfig)
```

Although it is possible to manually pass in the API key, it is preferable to store the key in a secret file (which should not be committed).

This allows `kayn` to be constructed like in the above code.

```sh
# filename: .env
RIOT_LOL_API_KEY=RGAPI-my-api-key
```

### Callbacks

```javascript
kayn.Summoner.by.name('Contractz').callback(function(err, summoner) {
    // do something
})
```

### Promises

```javascript
kayn.Summoner.by.name('Contractz')
    .then(summoner => doSomething(summoner))
    .catch(error => console.error(error))
```

### Async / Await

```javascript
const main = async () => {
    const ctz = await kayn.Summoner.by.name('Contractz')
}
```

### Region 

This forces a request to target a specific region instead of the default region set in `kayn`'s config.

```javascript
kayn.Summoner.by.name('hide on bush')
    .region(REGIONS.KOREA)
    .callback(function(error, summoner) {
        doSomething(summoner)
    })
```

### Query Parameters

```javascript
kayn.Matchlist.by.accountID(3440481)
    .region(REGIONS.KOREA)
    .query({
        champion: 67,
        season: 9,
    })
    .callback(function(err, matchlist) {
        console.log(matchlist.matches.length)
    })
```

### Documentation

The auto-generated ESDoc documentation can be found [here](http://kayn.surge.sh).

# Configuration

## Request Options

### numberOfRetriesBeforeAbort

Default: 3 attempts.

### delayBeforeRetry

Default: 1000 ms (1 second).

This option will be scrapped in the future in favor for more flexibility (linear, exponential, random, etc).

### burst

Default: false.<commit_msg>docs (README): Make #Methods have a section in the README<commit_after>A small library to work with Riot's League of Legend's API.

[![NPM](https://nodei.co/npm/kayn.png)](https://nodei.co/npm/kayn/)

[![Build Status](https://travis-ci.org/cnguy/kayn.svg?branch=master)](https://travis-ci.org/cnguy/kayn)
[![codecov](https://codecov.io/gh/cnguy/kayn/branch/master/graph/badge.svg)](https://codecov.io/gh/cnguy/kayn)
[![dependencies Status](https://david-dm.org/cnguy/kayn/status.svg)](https://david-dm.org/cnguy/kayn)

# Table of Contents:
* [Features](#features)
* [Methods](#methods)
* [Installation & Usage](#installation-and-usage)
* [Configuration](#configuration)
* [My Project](#my-project)
* [Bugs / Changelog / Disclaimer](#bugs)

# Features

## Rate Limiting

Handled by [Colorfulstan](https://github.com/Colorfulstan)'s wonderful [riot-ratelimiter](https://github.com/Colorfulstan/RiotRateLimiter-node).

## All Endpoints Covered

## Caching

Currently supports a basic JS cache (for simple scripts) and Redis for anything more complicated.

## Compatible with Callbacks, Promises, Async / Await

## Good TypeScript Support

Works immediately upon installation.

As of v0.8.0, full DTO's are provided thanks to [MingweiSamuel](https://github.com/MingweiSamuel)'s [auto-updated Swagger JSON](https://github.com/MingweiSamuel/riotapi-schema).

# Methods

Check out [COVERAGE.md](https://github.com/cnguy/kayn/blob/master/COVERAGE.md) to see kayn's methods, as well as the endpoints covered.

## Documentation

The auto-generated ESDoc documentation can be found [here](http://kayn.surge.sh).

# Installation and Usage

The minimum required [Node.js version is v7.6.0](https://nodejs.org/en/blog/release/v7.6.0/) for native async/await support (there's only a mere line in the codebase, though).

## npm

```sh
npm i --save kayn
```

## yarn

```sh
yarn add kayn
```

### Quick Setup with [Default Config](https://github.com/cnguy/kayn/blob/master/lib/KaynConfig.js)

```javascript
const { Kayn, REGIONS } = require('kayn')
const kayn = Kayn('RGAPI-my-api-key')(/*{
    region: REGIONS.NORTH_AMERICA,
    debugOptions: {
        isEnabled: true,
        showKey: false,
        loggers: {},
    },
    requestOptions: {
        shouldRetry: true,
        numberOfRetriesBeforeAbort: 3,
        delayBeforeRetry: 1000,
        burst: false,
    },
    cacheOptions: {
        cache: null,
        ttls: {},
    },
}*/)
```

**Note: Any config passed in is deeply merged with the default config.**

### Environment Variables

```javascript
const kayn = Kayn(/* process.env.RIOT_LOL_API_KEY */)(myConfig)
```

Although it is possible to manually pass in the API key, it is preferable to store the key in a secret file (which should not be committed).

This allows `kayn` to be constructed like in the above code.

```sh
# filename: .env
RIOT_LOL_API_KEY=RGAPI-my-api-key
```

### Callbacks

```javascript
kayn.Summoner.by.name('Contractz').callback(function(err, summoner) {
    // do something
})
```

### Promises

```javascript
kayn.Summoner.by.name('Contractz')
    .then(summoner => doSomething(summoner))
    .catch(error => console.error(error))
```

### Async / Await

```javascript
const main = async () => {
    const ctz = await kayn.Summoner.by.name('Contractz')
}
```

### Region 

This forces a request to target a specific region instead of the default region set in `kayn`'s config.

```javascript
kayn.Summoner.by.name('hide on bush')
    .region(REGIONS.KOREA)
    .callback(function(error, summoner) {
        doSomething(summoner)
    })
```

### Query Parameters

```javascript
kayn.Matchlist.by.accountID(3440481)
    .region(REGIONS.KOREA)
    .query({
        champion: 67,
        season: 9,
    })
    .callback(function(err, matchlist) {
        console.log(matchlist.matches.length)
    })
```

# Configuration

## Request Options

### numberOfRetriesBeforeAbort

Default: 3 attempts.

### delayBeforeRetry

Default: 1000 ms (1 second).

This option will be scrapped in the future in favor for more flexibility (linear, exponential, random, etc).

### burst

Default: false.
{'fraction_non_alphanumeric': 0.14975082046918683, 'fraction_numerical': 0.0072930594384344235, 'mean_word_length': 3.909307875894988, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 31, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1129455', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2743, 'n_words': 673}