GithubHelp home page GithubHelp logo

pacexy / poro Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 2.0 1.47 MB

API of Leaguepedia and League of Legends

License: MIT License

JavaScript 0.78% TypeScript 99.22%
league-of-legends leaguepedia data-dragon communitydragon hextech

poro's Introduction

poro

  • Leaguepedia API
  • Riot League of Legends API
  • Community Dragon
  • Data Dragon

Install

npm i poro

Usage

Leaguepedia

import { CargoClient } from 'poro'

const cargo = new CargoClient()
// specify fields
const teams = await cargo.query({
  tables: ['Teams'],
  fields: ['Teams.Name', 'Teams.Region'],
})
// filter
const g2 = await cargo.query({
  tables: ['Teams'],
  where: 'Teams.Name = "G2 Esports"',
})
// join on
const broadcastMusicUsages = await cargo.query({
  tables: ['BroadcastMusicUsages', 'BroadcastMusicTracks'],
  joinOn: [
    {
      left: 'BroadcastMusicUsages.TrackID',
      right: 'BroadcastMusicTracks.TrackID',
    },
  ],
})
// group
const proplayers = await cargo.query({
  tables: ['Pentakills'],
  groupBy: ['Pentakills.Name'],
  having: 'COUNT(DateDisplay) > 10',
})

Riot

import { RiotClient, Riot } from 'poro'

const riot = new RiotClient({
  auth: 'RIOT-API-KEY',
  platform: Riot.Platform.KR,
  region: Riot.Region.ASIA,
})
const leagueEntries = await riot
  .path('/lol/league-exp/v4/entries/{queue}/{tier}/{division}', {
    queue: Riot.Queue.RANKED_SOLO_5x5,
    tier: Riot.Tier.CHALLENGER,
    division: Riot.Division.I,
  })
  .get({ query: { page: 1 } })

General Data

import { general, Riot } from 'poro'

// https://static.developer.riotgames.com/docs/lol/gameModes.json
const gameModes = await axios<Riot.General.GameModes>(general.doc('gameModes'))

// https://ddragon.leagueoflegends.com/realms/na.json
const realm = await axios<Riot.General.Realm>(general.realm('na'))

Data Dragon

import { DataDragon, Riot } from 'poro'

const ddragon = new DataDragon('11.16.1', 'en_US')

// https://ddragon.leagueoflegends.com/cdn/11.16.1/data/en_US/summoner.json
const summoner = await axios<Riot.Data.SummonerJSON>(ddragon.meta('summoner'))

Community Dragon

import { CommunityDragon, Riot } from 'poro'

const cdragon = new CommunityDragon('latest', 'default')

// https://raw.communitydragon.org/latest/plugins/rcp-fe-lol-static-assets/global/default/images/ranked-mini-regalia/challenger.png
cdragon.tier(Riot.Tier.CHALLENGER)

APIs

CargoClient and RiotClient are designed for server side and use axios to send requests.

Types are out of box, so you don't have to define them yourself.

Leaguepedia

You can get the axios instance with cargo.axiosInstance.

interface CargoClientOptions {
  // Prefix to field names starting with '_' (like '_ID', '_pageName', etc.)
  metadataPrefix?: string
}

See the parameters needed for a query in Cargo query (or API sandbox)

See all fields of a table in Cargo tables.

interface CargoQueryParameter {
  tables: Table[]
  fields?: Field[] // defaults to all fields
  where?: string
  joinOn?: JoinOn[]
  groupBy?: Field[]
  having?: string
  orderBy?: OrderBy[] // defaults to `[{ field: `${tables[0]}._pageName` }]`
  limit?: number // defaults to `Number.MAX_SAFE_INTEGER`
  offset?: number // defaults to `0`
  format?: string // defaults to 'json'
}

interface JoinOn {
  left: Field
  right: Field
}

interface OrderBy {
  field: Field
  desc?: boolean // defaults to `false`
}

Riot

You can get the axios instance with riot.axiosInstance.

interface RiotClientConfig extends LimiterConfig {
  // Riot API KEY
  auth: string
  // Instance-scoped platform
  platform?: Platform
  // Instance-scoped region
  region?: Region
}

interface LimiterConfig {
  // Concurrency for each region
  concurrency?: number
  // If `true`, display debug info.
  // If 'mock', display debug info and mock requests.
  debug?: boolean | 'mock'
}

Sometime you need method-scoped platform and region. Add it as the last parameter in path method and it will override the instance-scoped one.

riot.path(
  '/lol/summoner/v4/summoners/{encryptedSummonerId}',
  { encryptedSummonerId: '...' },
  Riot.Platform.KR,
)

Credits

The Riot API client is inspired by Building Strongly Typed REST Clients with TypeScript (repository).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.