Skip to content

Commit

Permalink
add GetClashTeam method in clash endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezga12 committed May 11, 2020
1 parent fe46ab9 commit 4d24542
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 7 deletions.
37 changes: 30 additions & 7 deletions RiotSharp/Endpoints/ClashEndpoint/ClashEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ namespace RiotSharp.Endpoints.ClashEndpoint
/// </summary>
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;

Expand All @@ -39,7 +41,7 @@ public ClashEndpoint(IRateLimitedRequester requester, ICache cache)
/// <inheritdoc />
public async Task<List<ClashPlayer>> GetClashPlayersBySummonerIdAsync(Region region, string summonerId)
{
var cacheKey = string.Format(ClashPlayerCache, region, summonerId);
var cacheKey = string.Format(ClashPlayerCacheKey, region, summonerId);
var cachePLayerList = _cache.Get<string, List<ClashPlayer>>(cacheKey);

if (cachePLayerList != null)
Expand All @@ -48,13 +50,34 @@ public async Task<List<ClashPlayer>> 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<List<ClashPlayer>>(json);
_cache.Add(cacheKey, clashPlayers, ClashPlayersTtl);

return clashPlayers;
}


/// <inheritdoc />
public async Task<ClashTeam> GetClashTeamByTeamIdAsync(Region region, string teamId)
{
var cacheKey = string.Format(ClashTeamCacheKey, region, teamId);
var cacheTeam = _cache.Get<string, ClashTeam>(cacheKey);

if (cacheTeam != null)
{
return cacheTeam;
}

var json = await _requester.CreateGetRequestAsync(ClashRootUrl + string.Format(ClashTeamById, teamId), region)
.ConfigureAwait(false);

var clashTeam = JsonConvert.DeserializeObject<ClashTeam>(json);
_cache.Add(cacheKey, clashTeam, ClashPlayersTtl);

return clashTeam;
}
}
}
57 changes: 57 additions & 0 deletions RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace RiotSharp.Endpoints.ClashEndpoint.Models
{
public class ClashTeam
{
/// <summary>
/// Clash team id
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// Clash tournament id
/// </summary>
[JsonProperty("tournamentId")]
public int TournamentId { get; set; }

/// <summary>
/// Clash team name
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// clash team icon id
/// </summary>
[JsonProperty("iconId")]
public int IconId { get; set; }

/// <summary>
/// clash team tier
/// </summary>
[JsonProperty("tier")]
public int Tier { get; set; }

/// <summary>
/// Summoner Id of the team captain
/// </summary>
[JsonProperty("captain")]
public string CaptainId { get; set; }

/// <summary>
/// The team name 3 character long abbreviation
/// </summary>
[JsonProperty("abbreviation")]
public string Abbreviation { get; set; }

/// <summary>
/// List containing infos about team players
/// </summary>
[JsonProperty("players")]
public List<ClashTeamPlayer> Players { get; set; }
}
}
29 changes: 29 additions & 0 deletions RiotSharp/Endpoints/ClashEndpoint/Models/ClashTeamPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using RiotSharp.Endpoints.ClashEndpoint.Enums;

namespace RiotSharp.Endpoints.ClashEndpoint.Models
{
/// <summary>
/// Model Representing a player in the clash team
/// </summary>
public class ClashTeamPlayer
{
/// <summary>
/// Summoner Id
/// </summary>
[JsonProperty("summonerId")]
public string SummonerId { get; set; }

/// <summary>
/// Position In a game
/// </summary>
[JsonProperty("position")]
public PositionType Position { get; set; }

/// <summary>
/// hierarchy role in the team
/// </summary>
[JsonProperty("role")]
public RoleType Role { get; set; }
}
}
10 changes: 10 additions & 0 deletions RiotSharp/Endpoints/Interfaces/IClashEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,15 @@ public interface IClashEndpoint
/// <param name="summonerId">Summoner Id for which you need to retrieve clash player list</param>
/// <returns>A List of currently active clash players</returns>
Task<List<ClashPlayer>> GetClashPlayersBySummonerIdAsync(Region region, string summonerId);


/// <summary>
/// Gets Clash Team By Team Id
/// Returned Object also contains info about all team players
/// </summary>
/// <param name="region">Region in which team is registered on clash</param>
/// <param name="teamId">Clash team id</param>
/// <returns>Returns Clash Team model object containing all team info</returns>
Task<ClashTeam> GetClashTeamByTeamIdAsync(Region region, string teamId);
}
}

0 comments on commit 4d24542

Please sign in to comment.