From 4d245426adda337ce267b3aed700506168914e95 Mon Sep 17 00:00:00 2001 From: rezga12 Date: Wed, 6 May 2020 21:18:30 +0400 Subject: [PATCH 1/3] add GetClashTeam method in clash endpoint --- .../Endpoints/ClashEndpoint/ClashEndpoint.cs | 37 +++++++++--- .../ClashEndpoint/Models/ClashTeam.cs | 57 +++++++++++++++++++ .../ClashEndpoint/Models/ClashTeamPlayer.cs | 29 ++++++++++ .../Endpoints/Interfaces/IClashEndpoint.cs | 10 ++++ 4 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeam.cs create mode 100644 RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeamPlayer.cs diff --git a/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs b/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs index 87aa9e5f..d311ea91 100644 --- a/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs +++ b/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs @@ -15,13 +15,15 @@ namespace RiotSharp.Endpoints.ClashEndpoint /// public class ClashEndpoint : IClashEndpoint { - private const string ClashPlayersRootUrl = "/lol/clash/v1/players"; - private const string ClashPlayersBySummonerId = "/by-summoner/{0}"; + private const string ClashRootUrl = "/lol/clash/v1"; + private const string ClashPlayersBySummonerId = "/players/by-summoner/{0}"; + private const string ClashTeamById = "/teams/{0}"; - private const string ClashPlayerCache = "clash-player-{0}_{1}"; - private static readonly TimeSpan ClashPlayersTtl = TimeSpan.FromDays(5); - + private const string ClashPlayerCacheKey = "clash-player-{0}_{1}"; + private const string ClashTeamCacheKey = "clash-team-{0}_{1}"; + private static readonly TimeSpan ClashPlayersTtl = TimeSpan.FromDays(5); + private readonly IRateLimitedRequester _requester; private readonly ICache _cache; @@ -39,7 +41,7 @@ public ClashEndpoint(IRateLimitedRequester requester, ICache cache) /// public async Task> GetClashPlayersBySummonerIdAsync(Region region, string summonerId) { - var cacheKey = string.Format(ClashPlayerCache, region, summonerId); + var cacheKey = string.Format(ClashPlayerCacheKey, region, summonerId); var cachePLayerList = _cache.Get>(cacheKey); if (cachePLayerList != null) @@ -48,7 +50,7 @@ public async Task> GetClashPlayersBySummonerIdAsync(Region reg } var json = await _requester - .CreateGetRequestAsync(ClashPlayersRootUrl + string.Format(ClashPlayersBySummonerId, summonerId), region) + .CreateGetRequestAsync(ClashRootUrl + string.Format(ClashPlayersBySummonerId, summonerId), region) .ConfigureAwait(false); var clashPlayers = JsonConvert.DeserializeObject>(json); @@ -56,5 +58,26 @@ public async Task> GetClashPlayersBySummonerIdAsync(Region reg return clashPlayers; } + + + /// + public async Task GetClashTeamByTeamIdAsync(Region region, string teamId) + { + var cacheKey = string.Format(ClashTeamCacheKey, region, teamId); + var cacheTeam = _cache.Get(cacheKey); + + if (cacheTeam != null) + { + return cacheTeam; + } + + var json = await _requester.CreateGetRequestAsync(ClashRootUrl + string.Format(ClashTeamById, teamId), region) + .ConfigureAwait(false); + + var clashTeam = JsonConvert.DeserializeObject(json); + _cache.Add(cacheKey, clashTeam, ClashPlayersTtl); + + return clashTeam; + } } } \ No newline at end of file diff --git a/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeam.cs b/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeam.cs new file mode 100644 index 00000000..42a068fc --- /dev/null +++ b/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeam.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace RiotSharp.Endpoints.ClashEndpoint.Models +{ + public class ClashTeam + { + /// + /// Clash team id + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Clash tournament id + /// + [JsonProperty("tournamentId")] + public int TournamentId { get; set; } + + /// + /// Clash team name + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// clash team icon id + /// + [JsonProperty("iconId")] + public int IconId { get; set; } + + /// + /// clash team tier + /// + [JsonProperty("tier")] + public int Tier { get; set; } + + /// + /// Summoner Id of the team captain + /// + [JsonProperty("captain")] + public string CaptainId { get; set; } + + /// + /// The team name 3 character long abbreviation + /// + [JsonProperty("abbreviation")] + public string Abbreviation { get; set; } + + /// + /// List containing infos about team players + /// + [JsonProperty("players")] + public List Players { get; set; } + } +} \ No newline at end of file diff --git a/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeamPlayer.cs b/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeamPlayer.cs new file mode 100644 index 00000000..601089e8 --- /dev/null +++ b/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeamPlayer.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using RiotSharp.Endpoints.ClashEndpoint.Enums; + +namespace RiotSharp.Endpoints.ClashEndpoint.Models +{ + /// + /// Model Representing a player in the clash team + /// + public class ClashTeamPlayer + { + /// + /// Summoner Id + /// + [JsonProperty("summonerId")] + public string SummonerId { get; set; } + + /// + /// Position In a game + /// + [JsonProperty("position")] + public PositionType Position { get; set; } + + /// + /// hierarchy role in the team + /// + [JsonProperty("role")] + public RoleType Role { get; set; } + } +} \ No newline at end of file diff --git a/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs b/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs index ef73d42a..80152630 100644 --- a/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs +++ b/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs @@ -19,5 +19,15 @@ public interface IClashEndpoint /// Summoner Id for which you need to retrieve clash player list /// A List of currently active clash players Task> GetClashPlayersBySummonerIdAsync(Region region, string summonerId); + + + /// + /// Gets Clash Team By Team Id + /// Returned Object also contains info about all team players + /// + /// Region in which team is registered on clash + /// Clash team id + /// Returns Clash Team model object containing all team info + Task GetClashTeamByTeamIdAsync(Region region, string teamId); } } \ No newline at end of file From 8de60673c2c1c3924250cbffacb73ca5ac460bf5 Mon Sep 17 00:00:00 2001 From: rezga12 Date: Tue, 16 Jun 2020 17:08:02 +0400 Subject: [PATCH 2/3] add clash tournament list endpoint --- .../Endpoints/ClashEndpoint/ClashEndpoint.cs | 22 ++++++++++ .../ClashEndpoint/Models/ClashTournament.cs | 42 +++++++++++++++++++ .../Models/ClashTournamentPhase.cs | 35 ++++++++++++++++ .../Endpoints/Interfaces/IClashEndpoint.cs | 7 ++++ 4 files changed, 106 insertions(+) create mode 100644 RiotSharp/Endpoints/ClashEndpoint/Models/ClashTournament.cs create mode 100644 RiotSharp/Endpoints/ClashEndpoint/Models/ClashTournamentPhase.cs diff --git a/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs b/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs index d311ea91..94b5ee2e 100644 --- a/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs +++ b/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs @@ -18,9 +18,11 @@ public class ClashEndpoint : IClashEndpoint private const string ClashRootUrl = "/lol/clash/v1"; private const string ClashPlayersBySummonerId = "/players/by-summoner/{0}"; private const string ClashTeamById = "/teams/{0}"; + private const string ClashTournaments = "/tournaments"; private const string ClashPlayerCacheKey = "clash-player-{0}_{1}"; private const string ClashTeamCacheKey = "clash-team-{0}_{1}"; + private const string ClashTournamentListCacheKey = "clash-tournaments-{0}"; private static readonly TimeSpan ClashPlayersTtl = TimeSpan.FromDays(5); @@ -79,5 +81,25 @@ public async Task GetClashTeamByTeamIdAsync(Region region, string tea return clashTeam; } + + /// + public async Task> GetClashTournamentListAsync(Region region) + { + var cacheKey = string.Format(ClashTournamentListCacheKey, region); + var cacheTournamentList = _cache.Get>(cacheKey); + + if (cacheTournamentList != null) + { + return cacheTournamentList; + } + + var json = await _requester.CreateGetRequestAsync(ClashRootUrl + ClashTournaments, region) + .ConfigureAwait(false); + + var tournaments = JsonConvert.DeserializeObject>(json); + _cache.Add(cacheKey, tournaments, ClashPlayersTtl); + + return tournaments; + } } } \ No newline at end of file diff --git a/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTournament.cs b/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTournament.cs new file mode 100644 index 00000000..c53f7450 --- /dev/null +++ b/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTournament.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace RiotSharp.Endpoints.ClashEndpoint.Models +{ + /// + /// Model class representing Clash Tournament entity + /// + public class ClashTournament + { + /// + /// Tournament Id + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// Tournament theme Id + /// + [JsonProperty("themeId")] + public int ThemeId { get; set; } + + /// + /// Tournament Name (ex: Piltover) + /// + [JsonProperty("nameKey")] + public string NameKey { get; set; } + + /// + /// Secondary name of a tournament (ex: Day 4) + /// + [JsonProperty("nameKeySecondary")] + public string NameKeySecondary { get; set; } + + /// + /// List of tournament phases + /// + [JsonProperty("schedule")] + public List Schedule { get; set; } + } +} \ No newline at end of file diff --git a/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTournamentPhase.cs b/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTournamentPhase.cs new file mode 100644 index 00000000..3952c549 --- /dev/null +++ b/RiotSharp/Endpoints/ClashEndpoint/Models/ClashTournamentPhase.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace RiotSharp.Endpoints.ClashEndpoint.Models +{ + /// + /// This model class defines properties of tournament phase model in clash + /// + public class ClashTournamentPhase + { + /// + /// Id of the tournament phase + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// registration start time in tournament phase in ms + /// + [JsonProperty("registrationTime")] + public long RegistrationTime { get; set; } + + /// + /// Tournament start time in ms + /// + [JsonProperty("startTime")] + public long StartTime { get; set; } + + /// + /// boolean indicating if tournament has been cancelled or not + /// + [JsonProperty("cancelled")] + public bool Cancelled { get; set; } + } +} \ No newline at end of file diff --git a/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs b/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs index 80152630..5a1ab44f 100644 --- a/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs +++ b/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs @@ -29,5 +29,12 @@ public interface IClashEndpoint /// Clash team id /// Returns Clash Team model object containing all team info Task GetClashTeamByTeamIdAsync(Region region, string teamId); + + /// + /// Returns a list of active and upcoming tournaments in specified tournament. + /// + /// Region in which the tournament is held + /// Return a list of tournament entity models + Task> GetClashTournamentListAsync(Region region); } } \ No newline at end of file From 93fb6ca5d6d535d1523c54359f5950eb6c599e68 Mon Sep 17 00:00:00 2001 From: rezga12 Date: Wed, 17 Jun 2020 19:31:41 +0400 Subject: [PATCH 3/3] add tournament by team method in clash endpoint --- .../Endpoints/ClashEndpoint/ClashEndpoint.cs | 22 +++++++++++++++++++ .../Endpoints/Interfaces/IClashEndpoint.cs | 12 ++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs b/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs index 94b5ee2e..9add081c 100644 --- a/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs +++ b/RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs @@ -19,10 +19,12 @@ public class ClashEndpoint : IClashEndpoint private const string ClashPlayersBySummonerId = "/players/by-summoner/{0}"; private const string ClashTeamById = "/teams/{0}"; private const string ClashTournaments = "/tournaments"; + private const string ClashTournamentByTeam = "/tournaments/by-team/{0}"; private const string ClashPlayerCacheKey = "clash-player-{0}_{1}"; private const string ClashTeamCacheKey = "clash-team-{0}_{1}"; private const string ClashTournamentListCacheKey = "clash-tournaments-{0}"; + private const string ClashTournamentByTeamCacheKey = "clash-tournament-by-team-{0}-{1}"; private static readonly TimeSpan ClashPlayersTtl = TimeSpan.FromDays(5); @@ -101,5 +103,25 @@ public async Task> GetClashTournamentListAsync(Region regi return tournaments; } + + /// + public async Task GetClashTournamentByTeamAsync(Region region, string teamId) + { + var cacheKey = string.Format(ClashTournamentByTeamCacheKey, region, teamId); + var cacheTournament = _cache.Get(cacheKey); + + if (cacheTournament != null) + { + return cacheTournament; + } + + var json = await _requester.CreateGetRequestAsync(ClashRootUrl + string.Format(ClashTournamentByTeam, teamId), region) + .ConfigureAwait(false); + + var tournament = JsonConvert.DeserializeObject(json); + _cache.Add(cacheKey, tournament, ClashPlayersTtl); + + return tournament; + } } } \ No newline at end of file diff --git a/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs b/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs index 5a1ab44f..34491bf1 100644 --- a/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs +++ b/RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs @@ -31,10 +31,18 @@ public interface IClashEndpoint Task GetClashTeamByTeamIdAsync(Region region, string teamId); /// - /// Returns a list of active and upcoming tournaments in specified tournament. + /// Returns a list of active and upcoming tournaments in specified region. /// - /// Region in which the tournament is held + /// Region in which the tournaments are held /// Return a list of tournament entity models Task> GetClashTournamentListAsync(Region region); + + /// + /// Returns a active or upcoming tournament for specified team. + /// + /// Region in which the tournament is held + /// Team Id for which the tournament list is fetched + /// Return a list of tournament entity models + Task GetClashTournamentByTeamAsync(Region region, string teamId); } } \ No newline at end of file