Git Product home page Git Product logo

zyra's Introduction

Zyra

Travis Maven Javadoc Stable

Java Library for the Riot Games API

Zyra's goals are speed and reliability. Zyra has built-in behind-the-scenes multi-threading which makes Zyra 6+ times faster than other libraries for large queries. Zyra handles rate limits and large requests seamlessly. Zyra does not support the tournament APIs.

Features

  • Fast, multi-threaded
  • Automatically retry failed requests
  • Asynchronous chaining with CompletableFuture
  • Highly-configurable

Setup

Zyra requires Java 8.

If you are using Maven or Gradle, see the Build Tools section. Otherwise, see the instructions below.

Jars

Nightly Build GitHub Release

If you are not using a build system, release packaged jars are available through GitHub's releases. Additionally, the most recent (nightly) build is available here. There are several different jars available:

  • zyra-VERSION-standalone.jar - Go with this if you are not sure what you need. The jar has the minimal required dependencies needed to use Zyra.
  • zyra-VERSION-standalone-full.jar - Has all Zyra's dependencies in their entirety, such as Google Guava. Larger than the minimal standalone jar.
  • zyra-VERSION.jar - Has only Zyra. You will need to manually include the (many) dependencies.

zyra-VERSION-javadoc.jar contains the Javadocs and zyra-VERSION-sources.jar contains the sources.

Build Tools

Maven

Maven

Add the following to your pom.xml dependencies section. Make sure to update VERSION.

<dependency>
    <groupId>com.mingweisamuel.zyra</groupId>
    <artifactId>zyra</artifactId>
    <version>VERSION</version>
</dependency>

Gradle

For stability, you should replace + with an explicit version.

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.mingweisamuel.zyra:zyra:+'
}

Usage

Javadoc Stable Javadoc Nightly

Full example

The following code prints the top 10 champions for Doublelift and C9 Sneaky.

import com.mingweisamuel.zyra.RiotApi;
import com.mingweisamuel.zyra.championMastery.ChampionMastery;
import com.mingweisamuel.zyra.enums.Region;
import com.mingweisamuel.zyra.lolStaticData.Champion;
import com.mingweisamuel.zyra.lolStaticData.ChampionList;
import com.mingweisamuel.zyra.summoner.Summoner;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class ZyraExample {

    public static void main(String[] args) throws ExecutionException, IOException {
        try (RiotApi api = RiotApi.builder("RGAPI-example-api-key").build()) {

            encId
            ChampionList champList = api.staticData.getChampions(Region.NA, null, null, true);
            Map<String, Champion> champs = champList.data;

            // get summoners by name
            Map<String, Summoner> summoners =
                    api.summoners.getByName(Region.NA, Arrays.asList("c9 sne aky", "DoUbleLIft"));

            for (Summoner summoner : summoners.values()) {
                System.out.println(summoner.name + "'s Top 10 Champs:");
                // get top 10 champs by mastery for each summoner
                List<ChampionMastery> masteries =
                        api.championMasteries.getTopChampions(Region.NA, summoner.id, 10);

                for (int i = 0; i < masteries.size(); i++) {
                    ChampionMastery mastery = masteries.get(i);
                    // get champion for this mastery
                    Champion champ = champs.get(Integer.toString(mastery.championId));
                    // print i, champ name, champ mastery points, and champ level
                    System.out.printf("%3d) %-16s %,7d (%d)%n", i + 1, champ.name,
                            mastery.championPoints, mastery.championLevel);
                }
                System.out.println();
            }
        }
    }
}

Output (2017-01-18):

C9 Sneaky's Top 10 Champs:
  1) Jhin             268,866 (7)
  2) Lucian           195,541 (7)
  3) Ezreal           146,950 (7)
  4) Ashe             144,269 (7)
  5) Caitlyn          139,390 (7)
  6) Sivir             84,331 (7)
  7) Twitch            82,702 (7)
  8) Vayne             80,733 (7)
  9) Tristana          75,150 (6)
 10) Miss Fortune      70,757 (7)

Doublelift's Top 10 Champs:
  1) Jhin             126,291 (7)
  2) Caitlyn           97,410 (7)
  3) Vayne             79,420 (7)
  4) Lucian            77,254 (7)
  5) Kalista           43,572 (5)
  6) Ashe              36,408 (7)
  7) Ezreal            35,754 (6)
  8) Twitch            33,169 (6)
  9) Kog'Maw           22,459 (5)
 10) Tristana          20,582 (4)
 

Building a RiotApi instance

API interaction is done using instances of the RiotApi class. RiotApi has a builder-helper for configuring Zyra. To get a default instance (with default development rate limits):

RiotApi api = RiotApi.build("RGAPI-example-api-key").build();

IMPORTANT: RiotApi implements Closeable. You should call api.close() if you are done with the RiotApi instance, otherwise your process may hang.

Interacting with the API

API interaction in Zyra is done through endpoint sets which correspond (almost) 1-to-1 to the sections listed in the official Riot API Reference.

Example:

// get summoners by name
List<Summoner> summoners = Arrays.asList(
    api.summoners.getBySummonerName(Region.NA, "C9 Sneaky"),
    api.summoners.getBySummonerName(Region.NA, "Dou ble lift"));
for (Summoner summoner : summoners) {
    // get total champion mastery points for each summoner
    int score = api.championMasteries.getChampionMasteryScore(Region.NA, summoner.id);
    System.out.println(summoner.name + ": " + score);
}

There are also asynchronous versions of every endpoint method which return CompletableFutures to allow chaining.

More examples can be found in Zyra's integration test sources.

zyra's People

Contributors

mingweisamuel avatar nickypoo avatar robrua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

nickypoo wendelas

zyra's Issues

Inconsistancy in Queue Enums

One of the weird things with the API is that matches use TEAM_BUILDER_RANKED_SOLO (420) but then when pulling the rank uses the string "RANKED_SOLO_5x5" (for example). May be worth adding some sort of logic to translate between the match queues and rank queues, but not sure if its worth trying to cover up issues with the API. Should at least add a note about this in docs.

Need to be updated for new keys ?

Riot keys have been updated to this.

Rate Limit(s):
20 requests every 1 seconds
100 requests every 2 minutes
Note that rate limits are enforced per region. For example, with the above rate limit, you could make 500 requests every 10 minutes to both NA and EUW endpoints simultaneously

Automatically detect rate limits

Rate limits are now included in headers. Deprecate constructors that take rate limits and instead detect rate limits in the response headers of the first request (and check the current request counts).

Allow for distributed key with uneven distribution

Currently there is the logic to divide a key evenly between n machines. It may be better to allow users to supply a percentage corresponding to the percent of the key the instance gets to use, so it doesn't have to been even among all machines.

Add role/lane/position representation to Entity API

Roles are pretty finicky and annoying to deal with, would be nice to have a system to deal with them in the entity API. Sometimes bot lanes are mislabeled as (bot, duo), (bot, duo) instead of (bot, duo_carry), (but, duo_support), could maybe deal with cases like that

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.