Skip to content

Commit

Permalink
Rename Camille.RiotApi to Camille.RiotGames, add 'Api' suffix to clas…
Browse files Browse the repository at this point in the history
…ses #43
  • Loading branch information
MingweiSamuel committed Aug 26, 2020
1 parent 4882fb1 commit 1543d8f
Show file tree
Hide file tree
Showing 49 changed files with 891 additions and 891 deletions.
2 changes: 1 addition & 1 deletion Camille.Lcu.Test/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task TestLcuRest()
public async Task TestMethod1()
{
var lockfile = Lockfile.GetFromProcess();
using var lcu = new Lcu(lockfile);
using var lcu = new LcuApi(lockfile);
var wamp = lcu.wamp;

wamp.OnConnect += async () =>
Expand Down
2 changes: 1 addition & 1 deletion Camille.Lcu/gen/DataClasses.cs.dt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const { spec, schemasToInclude } = require(it.path + '/specTransform');

const header = `// Version ${spec.info.version}`;
const usings = []; /* 'using Camille.RiotApi.Enums;' ]; */
const usings = []; /* 'using Camille.RiotGames.Enums;' ]; */
const useSchema = (schemaKey)
=> schemasToInclude.has(schemaKey);
const namespace = 'Lcu';
Expand Down
6 changes: 3 additions & 3 deletions Camille.Lcu/src/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public abstract class Endpoints
#endif


protected readonly ILcu Lcu;
protected readonly ILcuApi @base;

protected Endpoints(ILcu lcu)
protected Endpoints(ILcuApi @base)
{
Lcu = lcu;
this.@base = @base;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
52 changes: 26 additions & 26 deletions Camille.Lcu/src/ILcu.cs → Camille.Lcu/src/ILcuApi.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Camille.Lcu
{
public interface ILcu
{
/// <summary>
/// Send a custom request to the LCU, parsing a value as JSON.
/// </summary>
/// <typeparam name="T">Type to parse as JSON.</typeparam>
/// <param name="request">Request to send.</param>
/// <param name="token">Cancellation token to cancel the request.</param>
/// <returns>The parsed value. May be null if endpoint returned an empty success response.</returns>
public Task<T> Send<T>(HttpRequestMessage request, CancellationToken? token = null);

/// <summary>
/// Send a custom request to the LCU, ignoring the return value.
/// </summary>
/// <typeparam name="T">Type to parse as JSON.</typeparam>
/// <param name="request">Request to send.</param>
/// <param name="token">Cancellation token to cancel the request.</param>
public Task Send(HttpRequestMessage request, CancellationToken? token = null);
}
}
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Camille.Lcu
{
public interface ILcuApi
{
/// <summary>
/// Send a custom request to the LCU, parsing a value as JSON.
/// </summary>
/// <typeparam name="T">Type to parse as JSON.</typeparam>
/// <param name="request">Request to send.</param>
/// <param name="token">Cancellation token to cancel the request.</param>
/// <returns>The parsed value. May be null if endpoint returned an empty success response.</returns>
public Task<T> Send<T>(HttpRequestMessage request, CancellationToken? token = null);

/// <summary>
/// Send a custom request to the LCU, ignoring the return value.
/// </summary>
/// <typeparam name="T">Type to parse as JSON.</typeparam>
/// <param name="request">Request to send.</param>
/// <param name="token">Cancellation token to cancel the request.</param>
public Task Send(HttpRequestMessage request, CancellationToken? token = null);
}
}
108 changes: 54 additions & 54 deletions Camille.Lcu/src/Lcu.cs → Camille.Lcu/src/LcuApi.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
using Camille.Lcu.Util;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Camille.Lcu
{
public class Lcu : ILcu, IDisposable
{
private readonly LcuRequester _requester;
public readonly Wamp wamp;

public Lcu(Lockfile lockfile) : this(lockfile, new LcuConfig())
{}

public Lcu(Lockfile lockfile, LcuConfig config) : base()
{
_requester = new LcuRequester(lockfile, config);
wamp = new Wamp(lockfile, config);
}

/// <inheritdoc/>
public async Task<T> Send<T>(HttpRequestMessage request, CancellationToken? token = null)
{
// Camille's code is context-free.
// This slightly improves performance and helps prevent GUI thread deadlocks.
// https://blogs.msdn.microsoft.com/benwilli/2017/02/09/an-alternative-to-configureawaitfalse-everywhere/
await new SynchronizationContextRemover();
var content = await _requester.SendAsync(request, token.GetValueOrDefault());
if (null == content) return default!; // TODO: throw exception on unexpected null.
#if USE_NEWTONSOFT
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(content);
#elif USE_SYSTEXTJSON
return System.Text.Json.JsonSerializer.Deserialize<T>(content);
#else
#error Must have one of USE_NEWTONSOFT or USE_SYSTEXTJSON set.
#endif
}

/// <inheritdoc/>
public async Task Send(HttpRequestMessage request, CancellationToken? token = null)
{
await new SynchronizationContextRemover();
await _requester.SendAsync(request, token.GetValueOrDefault());
}

public void Dispose()
{
_requester.Dispose();
wamp.Dispose();
}
}
}
using Camille.Lcu.Util;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Camille.Lcu
{
public class LcuApi : ILcuApi, IDisposable
{
private readonly LcuRequester _requester;
public readonly Wamp wamp;

public LcuApi(Lockfile lockfile) : this(lockfile, new LcuConfig())
{}

public LcuApi(Lockfile lockfile, LcuConfig config) : base()
{
_requester = new LcuRequester(lockfile, config);
wamp = new Wamp(lockfile, config);
}

/// <inheritdoc/>
public async Task<T> Send<T>(HttpRequestMessage request, CancellationToken? token = null)
{
// Camille's code is context-free.
// This slightly improves performance and helps prevent GUI thread deadlocks.
// https://blogs.msdn.microsoft.com/benwilli/2017/02/09/an-alternative-to-configureawaitfalse-everywhere/
await new SynchronizationContextRemover();
var content = await _requester.SendAsync(request, token.GetValueOrDefault());
if (null == content) return default!; // TODO: throw exception on unexpected null.
#if USE_NEWTONSOFT
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(content);
#elif USE_SYSTEXTJSON
return System.Text.Json.JsonSerializer.Deserialize<T>(content);
#else
#error Must have one of USE_NEWTONSOFT or USE_SYSTEXTJSON set.
#endif
}

/// <inheritdoc/>
public async Task Send(HttpRequestMessage request, CancellationToken? token = null)
{
await new SynchronizationContextRemover();
await _requester.SendAsync(request, token.GetValueOrDefault());
}

public void Dispose()
{
_requester.Dispose();
wamp.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
apikey.txt
apikey.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Camille.RiotApi.SummonerV4;
using Camille.RiotGames.SummonerV4;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class AdditionalPropertiesTest
Expand All @@ -20,7 +20,7 @@ public void TestAdditionalProperties()
'summonerLevel': 111
}".Replace('\'', '"');

var summoner = RiotApi.Deserialize<Summoner>(str);
var summoner = RiotGamesApi.Deserialize<Summoner>(str);
Assert.AreEqual(1, summoner._AdditionalProperties.Count);
Assert.IsTrue(summoner._AdditionalProperties.ContainsKey("oopsExtraField"));
Assert.AreEqual("spooky rito", summoner._AdditionalProperties["oopsExtraField"].ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.Enums;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class ApiCancellationTest : ApiTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.RiotApi.ChampionMasteryV4;
using Camille.RiotGames.ChampionMasteryV4;
using Camille.Enums;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class ApiChampionMasteryV4Test : ApiTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.RiotApi.ChampionV3;
using Camille.RiotGames.ChampionV3;
using Camille.Enums;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class ApiChampionV3Test : ApiTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.Enums;
using Camille.RiotApi.SpectatorV4;
using Camille.RiotGames.SpectatorV4;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
[Ignore("Unreliable")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.Enums;
using Camille.RiotApi.LeagueV4;
using Camille.RiotGames.LeagueV4;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class ApiLeagueV4Test : ApiTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.Enums;
using Camille.RiotApi.LorRankedV1;
using Camille.RiotGames.LorRankedV1;
using System.Linq;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class ApiLorRankedV1Test : ApiTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.Enums;
using Camille.RiotApi.MatchV4;
using Camille.RiotGames.MatchV4;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
[Ignore("Requires updating")] // TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.Enums;
using Camille.RiotApi.SummonerV4;
using Camille.RiotGames.SummonerV4;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class ApiSummonerV4Test : ApiTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
public class ApiTest
{
Expand All @@ -11,9 +11,9 @@ public class ApiTest

protected const string AccountIdC9Sneaky = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw";

protected static readonly RiotApi Api = RiotApi.NewInstance
protected static readonly RiotGamesApi Api = RiotGamesApi.NewInstance
(
new RiotApiConfig.Builder(
new RiotGamesApiConfig.Builder(
Environment.GetEnvironmentVariable("RGAPI_KEY")
?? File.ReadAllText("apikey.txt").Trim())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netcoreapp3.1</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Camille.Enums\Camille.Enums.csproj" />
<ProjectReference Include="..\Camille.RiotApi\Camille.RiotApi.csproj" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>

<ItemGroup>
<None Update="apikey.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netcoreapp3.1</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Camille.Enums\Camille.Enums.csproj" />
<ProjectReference Include="..\Camille.RiotGames\Camille.RiotGames.csproj" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>

<ItemGroup>
<None Update="apikey.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.Enums;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class ChampionTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Camille.Enums;

namespace Camille.RiotApi.Test
namespace Camille.RiotGames.Test
{
[TestClass]
public class ReadmeExampleTest : ApiTest
Expand Down
Loading

0 comments on commit 1543d8f

Please sign in to comment.