Skip to content

Instantly share code, notes, and snippets.

@taycaldwell
Last active August 29, 2015 14:20
Show Gist options
  • Save taycaldwell/e05440d762bf79e65dd7 to your computer and use it in GitHub Desktop.
Save taycaldwell/e05440d762bf79e65dd7 to your computer and use it in GitHub Desktop.
riot-api-java example (5/9/2015)
package testing;
import java.util.List;
import constant.Region;
import dto.Match.MatchDetail;
import dto.Match.Team;
import dto.MatchHistory.MatchSummary;
import dto.MatchHistory.Participant;
import dto.MatchHistory.ParticipantStats;
import dto.MatchHistory.PlayerHistory;
import dto.Summoner.Summoner;
import main.java.riotapi.RiotApi;
import main.java.riotapi.RiotApiException;
public class Example {
public static void main(String[] args) throws RiotApiException {
// Create Riot API object with API key
RiotApi api = new RiotApi("API-KEY-HERE");
// Set Region
api.setRegion(Region.NA);
// Get Summoner
Summoner summoner = api.getSummonerByName("Ambedo");
// Get summoner's match history by summoner ID
PlayerHistory matchHistory = api.getMatchHistory(summoner.getId());
// Get list of match summaries from match history
List<MatchSummary> matchSummaries = matchHistory.getMatches();
// Get the first summary
MatchSummary matchSummary = matchSummaries.get(0);
// Get participant of match
Participant participant = matchSummary.getParticipants().get(0);
// Get the participant's stats
ParticipantStats stats = participant.getStats();
// Get kills
long kills = stats.getKills();
// Get deaths
long deaths = stats.getDeaths();
// Get assists
long assists = stats.getAssists();
// Print player Kills/Deaths/Assists
System.out.println("Kills/Deaths/Assists: " + kills + "/" + deaths + "/" + assists);
// Get match ID of match summary
long matchId = matchSummary.getMatchId();
// Get details of match by match ID
MatchDetail matchDetail = api.getMatch(matchId);
// Get match duration
long matchDuration = matchDetail.getMatchDuration();
// Print match duration
System.out.println("Match Duration: " + matchDuration + " seconds");
// Teams in match
List<Team> teams = matchDetail.getTeams();
// Print team that got first blood and first dragon
for(Team team : teams) {
if(team.isFirstBlood()) {
System.out.print("First Blood: ");
if(team.getTeamId() == 100) System.out.println("Team 1");
if(team.getTeamId() == 200) System.out.println("Team 2");
}
if(team.isFirstDragon()) {
System.out.print("First Dragon: ");
if(team.getTeamId() == 100) System.out.println("Team 1");
if(team.getTeamId() == 200) System.out.println("Team 2");
}
}
}
/*
* All methods and their return types strictly follow the official Riot Games API documentation.
* The official Riot Games API documentation can be found @ - https://developer.riotgames.com/api/methods
*
* For more information, documentation, and examples visit the riot-api-java library website @ - https://riot-api-java.com/
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment