Giter VIP home page Giter VIP logo

Comments (1)

taycaldwell avatar taycaldwell commented on September 16, 2024
import java.util.List;
import constant.*;
import dto.Summoner.*;
import com.google.gson.*;
import main.java.riotapi.*;
import dto.League.*;

public class LeagueApp {

    public static void main(String[] args) throws RiotApiException {

        RiotApi api = new RiotApi("API-KEY-HERE");

        Summoner summoner = api.getSummonerByName(Region.NA, "RiotSchmick");

        // Get list of leagues the player is in
        List<League> leagues = api.getLeagueEntryBySummoner(summoner.getId());

        // Iterate through leagues to find Solo-Q, and print out the league name and tier
        for(League league : leagues) {
            if(league.getQueue().equals(QueueType.RANKED_SOLO_5x5.name())) {
                System.out.println("League Name: " + league.getName());
                System.out.println("Tier: " + league.getTier());

                // Get the league entry for the given player of this que
                // and print out the division, lp, and wins and losses
                LeagueEntry entry = league.getEntries().get(0);
                System.out.println("Division: " + entry.getDivision());
                System.out.println("LP: " + entry.getLeaguePoints());
                System.out.println("Wins: " + entry.getWins());
                System.out.println("Losses: " + entry.getLosses());
            }

        }
    }
}

As you can probably see, the API separates this info into two different objects, League, and LeagueEntry. That's because a League can have multiple divisions, consisting of multiple summoners, thus multiple league entries.

You use getLeagueEntryBySummoner() instead of getLeagueBySummoner() if you only want to get league entry info for the summoner you want. getLeagueBySummoner() returns league entry info for ALL summoners in the same league as the summoner.

Hope this helps.

Output:
League Name: Sona's Templars
Tier: SILVER
Division: I
LP: 22
Wins: 6
Losses: 9

from riot-api-java.

Related Issues (20)

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.