Skip to content

Commit

Permalink
Moved status api to v3, fixes BenFradet#344 (BenFradet#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
toothlessG22 authored and BenFradet committed May 20, 2017
1 parent f18fb2b commit 9f6477b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 70 deletions.
23 changes: 6 additions & 17 deletions RiotSharp/Interfaces/IStatusRiotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,21 @@ namespace RiotSharp.Interfaces
/// </summary>
public interface IStatusRiotApi
{
/// <summary>
/// Get the list of shards synchronously.
/// </summary>
/// <returns>A list of shards.</returns>
List<Shard> GetShards();

/// <summary>
/// Get the list of shards asynchronously.
/// </summary>
/// <returns>A list of shards.</returns>
Task<List<Shard>> GetShardsAsync();

/// <summary>
/// Get shard status synchronously.
/// Returns the data available on the status.leagueoflegends.com website for the given region.
/// Returns the data available on the status.leagueoflegends.com website for the given platform.
/// </summary>
/// <param name="region">Region for which to check the status.</param>
/// <param name="platform">Platform for which to check the status.</param>
/// <returns>A shard status object containing different information regarding the shard.</returns>
ShardStatus GetShardStatus(Region region);
ShardStatus GetShardStatus(Platform platform);

/// <summary>
/// Get shard status asynchronously.
/// Returns the data available on the status.leagueoflegends.com website for the given region.
/// Returns the data available on the status.leagueoflegends.com website for the given platform.
/// </summary>
/// <param name="region">Region for which to check the status.</param>
/// <param name="platform">Platform for which to check the status.</param>
/// <returns>A shard status object containing different information regarding the shard.</returns>
Task<ShardStatus> GetShardStatusAsync(Region region);
Task<ShardStatus> GetShardStatusAsync(Platform platform);
}
}
34 changes: 12 additions & 22 deletions RiotSharp/StatusRiotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using RiotSharp.Http.Interfaces;
using RiotSharp.Interfaces;
using RiotSharp.StatusEndpoint;
using System.Collections.Generic;
using System.Threading.Tasks;
using RiotSharp.Misc;
using System;
Expand All @@ -14,11 +13,11 @@ public class StatusRiotApi : IStatusRiotApi
{
#region Private Fields

private const string StatusRootUrl = "/shards";
private const string StatusRootUrl = "/lol/status/v3/shard-data";

private const string RegionUrl = "/{0}";
private const string PlatformSubdomain = "{0}.";

private const string RootDomain = "status.leagueoflegends.com";
private const string RootDomain = "api.riotgames.com";

private IRequester requester;

Expand All @@ -29,6 +28,7 @@ public class StatusRiotApi : IStatusRiotApi
/// <summary>
/// Get the instance of StatusRiotApi.
/// </summary>
/// <param name="apiKey">The api key.</param>
/// <returns>The instance of StatusRiotApi.</returns>
public static StatusRiotApi GetInstance(string apiKey)
{
Expand All @@ -52,29 +52,19 @@ public StatusRiotApi(IRequester requester)

#region Public Methods

public List<Shard> GetShards()
public ShardStatus GetShardStatus(Platform platform)
{
var json = requester.CreateGetRequest(StatusRootUrl, RootDomain, null, false);
return JsonConvert.DeserializeObject<List<Shard>>(json);
}

public async Task<List<Shard>> GetShardsAsync()
{
var json = await requester.CreateGetRequestAsync(StatusRootUrl, RootDomain, null, false);
return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<List<Shard>>(json));
}

public ShardStatus GetShardStatus(Region region)
{
var json = requester.CreateGetRequest(StatusRootUrl + string.Format(RegionUrl, region.ToString()),
RootDomain, null, false);
var json = requester.CreateGetRequest(StatusRootUrl,
string.Format(PlatformSubdomain, platform.ToString()) + RootDomain, null, true);

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

public async Task<ShardStatus> GetShardStatusAsync(Region region)
public async Task<ShardStatus> GetShardStatusAsync(Platform platform)
{
var json = await requester.CreateGetRequestAsync(StatusRootUrl + string.Format(RegionUrl, region.ToString()),
RootDomain, null, false);
var json = await requester.CreateGetRequestAsync(StatusRootUrl,
string.Format(PlatformSubdomain, platform.ToString()) + RootDomain, null, true);

return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<ShardStatus>(json));
}

Expand Down
1 change: 1 addition & 0 deletions RiotSharpExample/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<add key="Team2Id" value="TEAM-0a2ea1b0-f1cf-11e4-bc7e-c81f66ddabda"/>
<add key="GameId" value="1826202304"/>
<add key="Region" value="na"/>
<add key="Platform" value="na1"/>
</appSettings>
</configuration>
5 changes: 2 additions & 3 deletions RiotSharpExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static void Main(string[] args)
string name2 = ConfigurationManager.AppSettings["Summoner2Name"];
int gameId = int.Parse(ConfigurationManager.AppSettings["GameId"]);
Region region = (Region)Enum.Parse(typeof(Region), ConfigurationManager.AppSettings["Region"]);
Platform platform = (Platform)Enum.Parse(typeof(Platform), ConfigurationManager.AppSettings["Platform"]);

var mastery = staticApi.GetMastery(Region.euw, 6111, MasteryData.all);

Expand All @@ -34,9 +35,7 @@ static void Main(string[] args)

Console.WriteLine(match1.MapType);

var shards = statusApi.GetShards();

var shardStatus = statusApi.GetShardStatus(region);
var shardStatus = statusApi.GetShardStatus(platform);

var statSummaries = api.GetStatsSummaries(region, id);

Expand Down
4 changes: 2 additions & 2 deletions RiotSharpTest/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<add key="StaticRuneName" value="Lesser Mark of Attack Damage"/>
<add key="StaticSummonerSpellName" value="Barrier"/>
<!--StatusApiTest-->
<add key="StatusRegion" value="na"/>
<add key="StatusPlatform" value="NA1"/>
<!--TournamentTest-->
<add key="TournamentApiKey" value="YOUR-API-KEY"/>
<add key="TournamentRegion" value="euw"/>
Expand All @@ -45,7 +45,7 @@
<add key="TournamentPickType" value="TournamentDraft"/>
<add key="TournamentMapType" value="SummonersRift"/>
<!--CommonTest-->
<add key="ApiKey" value="YOUR-API-KEY"/>
<add key="ApiKey" value="YOUR_API_KEY"/>
<add key="Summoner1Id" value="73074921"/>
<add key="Summoner1AccountId" value="231816919"/>
<add key="Summoner1Name" value="toothlessG"/>
Expand Down
34 changes: 9 additions & 25 deletions RiotSharpTest/StatusRiotApiTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RiotSharp;
using System.Linq;
using RiotSharp.Misc;


namespace RiotSharpTest
{
Expand All @@ -9,44 +10,27 @@ public class StatusRiotApiTest
{
private static StatusRiotApi api = StatusRiotApi.GetInstance(CommonTestBase.apiKey);

[TestMethod]
[TestCategory("StatusRiotApi")]
public void GetShards_Test()
{
var shards = api.GetShards();

Assert.IsNotNull(shards);
Assert.IsTrue(shards.Count() > 0);
}

[TestMethod]
[TestCategory("StatusRiotApi"), TestCategory("Async")]
public void GetShardsAsync_Test()
{
var shards = api.GetShardsAsync();

Assert.IsNotNull(shards.Result);
Assert.IsTrue(shards.Result.Count() > 0);
}

[TestMethod]
[TestCategory("StatusRiotApi")]
public void GetShardStatus_Test()
{
var shardStatus = api.GetShardStatus(StatusRiotApiTestBase.region);
Platform p = StatusRiotApiTestBase.platform;
var shardStatus = api.GetShardStatus(StatusRiotApiTestBase.platform);

Assert.IsNotNull(shardStatus);
Assert.AreEqual(StatusRiotApiTestBase.region.ToString(), shardStatus.Slug.ToString());
Assert.AreEqual(StatusRiotApiTestBase.platform.ToString().ToLower(),
shardStatus.RegionTag.ToString());
}

[TestMethod]
[TestCategory("StatusRiotApi"), TestCategory("Async")]
public void GetShardStatusAsync_Test()
{
var shardStatus = api.GetShardStatusAsync(StatusRiotApiTestBase.region);
var shardStatus = api.GetShardStatusAsync(StatusRiotApiTestBase.platform);

Assert.IsNotNull(shardStatus.Result);
Assert.AreEqual(StatusRiotApiTestBase.region.ToString(), shardStatus.Result.Slug.ToString());
Assert.AreEqual(StatusRiotApiTestBase.platform.ToString().ToLower(),
shardStatus.Result.RegionTag.ToString());
}
}
}
3 changes: 2 additions & 1 deletion RiotSharpTest/StatusRiotApiTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace RiotSharpTest
{
public class StatusRiotApiTestBase : CommonTestBase
{
public static Region region = (Region)Enum.Parse(typeof(Region), ConfigurationManager.AppSettings["StatusRegion"]);
public static Platform platform = (Platform)Enum.Parse(typeof(Platform),
ConfigurationManager.AppSettings["StatusPlatform"]);
}
}

0 comments on commit 9f6477b

Please sign in to comment.