Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TFT Endpoints : Issue#640 #645

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RiotSharp.Test/CommonTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class CommonTestBase
public static string Summoner3Name = "xsunx";
public static Region Summoner3Region = (Region)Enum.Parse(typeof(Region), "Ru");

public static Region TftSummonerRegion = (Region)Enum.Parse(typeof(Region), "Americas");

/// <summary>
/// Ensures that test returns data (Shows test warnings for 404 status exceptions)
/// </summary>
Expand Down
136 changes: 136 additions & 0 deletions RiotSharp.Test/RiotApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public void GetChallengerLeagueAsync_Test()
});
}


[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetMasterLeagueAsync_Test()
Expand All @@ -169,6 +170,7 @@ public void GetMasterLeagueAsync_Test()
Assert.IsTrue(league.Result.Entries.Count > 0);
});
}

#endregion

#region Match Tests
Expand Down Expand Up @@ -348,6 +350,7 @@ public void GetMatchListAsync_Index_Test()
Assert.IsTrue(matches.Count <= endIndex - beginIndex);
});
}

#endregion

#region Spectator Tests
Expand Down Expand Up @@ -476,5 +479,138 @@ public void GetThirdPartyCodeAsync_Test()
}, "Third party code was not found for the summoner. (404)");
}
#endregion

#region TFT Summoner Tests

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftSummonerBySummonerIdAsync_ExistingId_ReturnsSummoner()
{
EnsureCredibility(() =>
{
var summoner = Api.TftSummoner.GetTftSummonerBySummonerIdAsync(Summoner1And2Region,
Summoner1Id);

Assert.AreEqual(Summoner1Name, summoner.Result.Name);
});
}

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftSummonerByPuuidAsync_ExistingId_ReturnsSummoner()
{
EnsureCredibility(() =>
{
var summoner = Api.TftSummoner.GetTftSummonerByPuuidAsync(Summoner1And2Region,
Summoner1Puuid);

Assert.AreEqual(Summoner1Name, summoner.Result.Name);
});
}

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftSummonerByNameAsync_ExistingName_ReturnsSummoner()
{
EnsureCredibility(() =>
{
var summoner = Api.TftSummoner.GetTftSummonerByNameAsync(Summoner1And2Region,
Summoner1Name);

Assert.AreEqual(Summoner1Id, summoner.Result.Id);
});
}

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftSummonerByAccountIdAsync_ExistingAccountId_ReturnsSummoner()
{
EnsureCredibility(() =>
{
var summoner = Api.TftSummoner.GetTftSummonerByAccountIdAsync(Summoner1And2Region,
Summoner1AccountId);

Assert.AreEqual(Summoner1Name, summoner.Result.Name);
});
}
#endregion

#region TFT League Tests

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftLeagueByTierDivisionAsync_Test()
{
EnsureCredibility(() =>
{
var league = Api.TftLeague.GetTftLeagueByTierDivisionAsync(Summoner1And2Region,
Endpoints.LeagueEndpoint.Enums.Tier.Bronze,
Endpoints.LeagueEndpoint.Enums.Division.I);

Assert.IsTrue(league.Result.Count > 0);
});
}

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftGrandmasterLeagueAsync_Test()
{
EnsureCredibility(() =>
{
var league = Api.TftLeague.GetTftGrandmasterLeagueAsync(Summoner1And2Region);
Assert.IsTrue(league.Result.Entries.Count > 0);
});
}

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftChallengerLeagueAsync_Test()
{
EnsureCredibility(() =>
{
var league = Api.TftLeague.GetTftChallengerLeagueAsync(Summoner1And2Region);
Assert.IsTrue(league.Result.Entries.Count > 0);
});
}

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftMasterLeagueAsync_Test()
{
EnsureCredibility(() =>
{
var league = Api.TftLeague.GetTftMasterLeagueAsync(Summoner1And2Region);
Assert.IsTrue(league.Result.Entries.Count > 0);
});
}

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftLeagueEntriesBySummonerAsync_Test()
{
EnsureCredibility(() =>
{
// TODO: Properly implement encrypted SummonerId tests
return;
nolanbradshaw marked this conversation as resolved.
Show resolved Hide resolved
var leagues = Api.TftLeague.GetTftLeagueEntriesBySummonerAsync(RiotApiTestBase.SummonersRegion, RiotApiTestBase.SummonerIds.FirstOrDefault());

Assert.IsTrue(leagues.Result.Count > 0);
});
}

[TestMethod]
[TestCategory("RiotApi"), TestCategory("Async")]
public void GetTftLeagueByIdAsync_Test()
{
EnsureCredibility(() =>
{
// TODO: Properly implement League id test
return;
var leagues = Api.TftLeague.GetTftLeagueByIdAsync(RiotApiTestBase.SummonersRegion, "LEAGUE-ID-HERE");

Assert.IsTrue(leagues.Result.Queue != null);
});
}
#endregion
}
}
1 change: 1 addition & 0 deletions RiotSharp/Endpoints/Interfaces/ILeagueEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ public interface ILeagueEndpoint
/// <param name="rankedQueue">A ranked queue (Supported: <see cref="Misc.Queue.RankedSolo5x5"/>, <see cref="Misc.Queue.RankedFlexSR"/>, <see cref="Misc.Queue.RankedFlexTT"/>)</param>
/// <returns>A <see cref="League" /> which contains all the grandmasters for this specific region and queue.</returns>
Task<League> GetLeagueGrandmastersByQueueAsync(Region region, string rankedQueue);

nolanbradshaw marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 1 addition & 0 deletions RiotSharp/Endpoints/Interfaces/ISummonerEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public interface ISummonerEndpoint
/// <param name="puuid">PUUID of the summoner you're looking for.</param>
/// <returns>A summoner.</returns>
Task<Summoner> GetSummonerByPuuidAsync(Region region, string puuid);

nolanbradshaw marked this conversation as resolved.
Show resolved Hide resolved
}
}
59 changes: 59 additions & 0 deletions RiotSharp/Endpoints/Interfaces/ITftLeagueEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using RiotSharp.Endpoints.LeagueEndpoint;
using RiotSharp.Endpoints.TftLeagueEndpoint;
using RiotSharp.Misc;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace RiotSharp.Endpoints.Interfaces
{
public interface ITftLeagueEndpoint
{
/// <summary>
/// Get the TFT grandmaster league
/// </summary>
/// <param name="region">Participants server region</param>
/// <returns><see cref="LeagueEntry"> class</returns>
Task<TftLeague> GetTftGrandmasterLeagueAsync(Region region);

/// <summary>
/// Get the TFT challenger league
/// </summary>
/// <param name="region">Participants server region</param>
/// <returns><see cref="League"> class</returns>
Task<TftLeague> GetTftChallengerLeagueAsync(Region region);

/// <summary>
/// Get the TFT master league
/// </summary>
/// <param name="region">Participants server region</param>
/// <returns><see cref="League"> class</returns>
Task<TftLeague> GetTftMasterLeagueAsync(Region region);

/// <summary>
/// Gets a list of TFT league entries
/// </summary>
/// <param name="region">Summoners server region</param>
/// <param name="encryptedSummonerId">Summoners encrypted id</param>
/// <returns>List of <see cref="LeagueEntry"> class</returns>
Task<List<TftLeagueEntry>> GetTftLeagueEntriesBySummonerAsync(Region region, string encryptedSummonerId);

/// <summary>
/// Gets a list of league entries for a given tier/division
/// </summary>
/// <param name="region">Participants server region</param>
/// <param name="tier">Tier to get league entries from</param>
/// <param name="division">Tier division to get league entries from</param>
/// <returns>List of <see cref="LeagueEntry"> class</returns>
Task<List<TftLeagueEntry>> GetTftLeagueByTierDivisionAsync(Region region, LeagueEndpoint.Enums.Tier tier, LeagueEndpoint.Enums.Division division);

/// <summary>
/// Gets the TFT league by league uuid
/// </summary>
/// <param name="region">Participants server region</param>
/// <param name="leagueId">UUID of the league</param>
/// <returns><see cref="League"> object/returns>
Task<TftLeague> GetTftLeagueByIdAsync(Region region, string leagueId);
}
}
28 changes: 28 additions & 0 deletions RiotSharp/Endpoints/Interfaces/ITftMatchEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using RiotSharp.Endpoints.TftMatchEndpoint;
using RiotSharp.Misc;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace RiotSharp.Endpoints.Interfaces
{
public interface ITftMatchEndpoint
{
/// <summary>
/// Gets a list of match ids by puuid
/// </summary>
/// <param name="region">Region in which the summoner is.</param>
/// <param name="puuid"></param>
/// <returns>A list of strings</returns>
Task<List<string>> GetTftMatchIdsByPuuidAsync(Region region, string puuid, int count = 20);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove ByPuuid from the naming to match the naming of the match endpoint.


/// <summary>
/// Get a match by id
/// </summary>
/// <param name="region">Region in which the summoner is.</param>
/// <param name="matchId">The match id for the match wanting to be retrieved</param>
/// <returns><see cref="Match"> object </returns>
Task<TftMatch> GetTftMatchByIdAsync(Region region, string matchId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with ById

}
}
47 changes: 47 additions & 0 deletions RiotSharp/Endpoints/Interfaces/ITftSummonerEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using RiotSharp.Endpoints.TftSummonerEndpoint;
using RiotSharp.Misc;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace RiotSharp.Endpoints.Interfaces
{
/// <summary>
/// Tft Summoner Endpoint.
/// </summary>
public interface ITftSummonerEndpoint
{
/// <summary>
/// Get a Teamfight Tactics summoner by account id asynchronously.
/// </summary>
/// <param name="region">Region in which you wish to look for a summoner.</param>
/// <param name="accountId">Account id of the summoner you're looking for.</param>
/// <returns>A summoner.</returns>
Task<TftSummoner> GetTftSummonerByAccountIdAsync(Region region, string accountId);

/// <summary>
/// Get a Teamfight Tactics summoner by name asynchronously.
/// </summary>
/// <param name="region">Region in which you wish to look for a summoner.</param>
/// <param name="summonerName">Name of the summoner you're looking for.</param>
/// <returns>A summoner.</returns>
Task<TftSummoner> GetTftSummonerByNameAsync(Region region, string summonerName);

/// <summary>
/// Get a Teamfight Tactics summoner by puuid asynchronously.
/// </summary>
/// <param name="region">Region in which you wish to look for a summoner.</param>
/// <param name="puuid">PUUID of the summoner you're looking for.</param>
/// <returns>A summoner.</returns>
Task<TftSummoner> GetTftSummonerByPuuidAsync(Region region, string summonerName);

/// <summary>
/// Get a Teamfight Tactics summoner by summoner id asynchronously.
/// </summary>
/// <param name="region">Region in which you wish to look for a summoner.</param>
/// <param name="summonerId">Id of the summoner you're looking for.</param>
/// <returns>A summoner.</returns>
Task<TftSummoner> GetTftSummonerBySummonerIdAsync(Region region, string summonerId);
}
}
3 changes: 3 additions & 0 deletions RiotSharp/Endpoints/LeagueEndpoint/LeagueEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public async Task<League> GetChallengerLeagueAsync(Region region, string queue)
{
var json = await _requester.CreateGetRequestAsync(LeagueRootUrl + string.Format(LeagueChallengerUrl, queue),
region).ConfigureAwait(false);

return JsonConvert.DeserializeObject<League>(json);
}

Expand All @@ -44,6 +45,7 @@ public async Task<League> GetMasterLeagueAsync(Region region, string queue)
{
var json = await _requester.CreateGetRequestAsync(LeagueRootUrl + string.Format(LeagueMasterUrl, queue),
region).ConfigureAwait(false);

return JsonConvert.DeserializeObject<League>(json);
}

Expand Down Expand Up @@ -84,5 +86,6 @@ public async Task<League> GetLeagueByIdAsync(Region region, string leagueId)

return JsonConvert.DeserializeObject<League>(json);
}

}
}
5 changes: 5 additions & 0 deletions RiotSharp/Endpoints/MatchEndpoint/MatchEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class MatchEndpoint : IMatchEndpoint
private const string MatchListByAccountIdUrl = "/by-account/{0}";
private const string TimelineByMatchIdUrl = "/by-match/{0}";
private const string MatchCache = "match-{0}_{1}";

private const string MatchTimeLineCacheKey = "match-timeline-{0}_{1}";
private static readonly TimeSpan MatchTtl = TimeSpan.FromDays(60);

Expand All @@ -33,6 +34,7 @@ public MatchEndpoint(IRateLimitedRequester requester, ICache cache)
_cache = cache;
}

/// <inheritdoc />
public async Task<List<long>> GetMatchIdsByTournamentCodeAsync(Region region, string tournamentCode)
{
var json = await _requester.CreateGetRequestAsync(MatchRootUrl +
Expand All @@ -42,6 +44,7 @@ public async Task<List<long>> GetMatchIdsByTournamentCodeAsync(Region region, st
return JsonConvert.DeserializeObject<List<long>>(json);
}

/// <inheritdoc />
public async Task<Match> GetMatchAsync(Region region, long matchId)
{
var matchInCache = _cache.Get<string, Match>(string.Format(MatchCache, region, matchId));
Expand All @@ -56,6 +59,7 @@ public async Task<Match> GetMatchAsync(Region region, long matchId)
return match;
}

/// <inheritdoc />
public async Task<MatchList> GetMatchListAsync(Region region, string accountId, List<int> championIds = null, List<int> queues = null, List<Season> seasons = null,
DateTime? beginTime = null, DateTime? endTime = null, long? beginIndex = null, long? endIndex = null)
{
Expand All @@ -67,6 +71,7 @@ public async Task<MatchList> GetMatchListAsync(Region region, string accountId,
return JsonConvert.DeserializeObject<MatchList>(json);
}

/// <inheritdoc />
public async Task<MatchTimeline> GetMatchTimelineAsync(Region region, long matchId)
{
var cacheKey = string.Format(MatchTimeLineCacheKey, region, matchId);
Expand Down
Loading