-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
5,711 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace LCUSharp.Http.Endpoints | ||
{ | ||
/// <summary> | ||
/// An endpoint within the league client's API. | ||
/// </summary> | ||
internal abstract class EndpointBase | ||
{ | ||
/// <summary> | ||
/// The request handler. | ||
/// </summary> | ||
protected ILeagueRequestHandler RequestHandler { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EndpointBase"/> class. | ||
/// </summary> | ||
/// <param name="requestHandler">The request handler.</param> | ||
public EndpointBase(ILeagueRequestHandler requestHandler) | ||
{ | ||
RequestHandler = requestHandler; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
LCUSharp/Http/Endpoints/ProcessControl/IProcessControlEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace LCUSharp.Http.Endpoints | ||
{ | ||
/// <summary> | ||
/// Handles operations relating to the process-control endpoint. | ||
/// </summary> | ||
public interface IProcessControlEndpoint | ||
{ | ||
/// <summary> | ||
/// Quits the league client processes. | ||
/// </summary> | ||
Task QuitAsync(); | ||
|
||
/// <summary> | ||
/// Restarts the league client processes. | ||
/// </summary> | ||
/// <param name="delaySeconds">The amount of time to wait before restarting.</param> | ||
Task RestartAsync(int delaySeconds); | ||
|
||
/// <summary> | ||
/// Restarts the league client processes. | ||
/// </summary> | ||
/// <param name="delaySeconds">The amount of time to wait before restarting.</param> | ||
/// <param name="restartVersion">The client version to use on restart.</param> | ||
Task RestartAsync(int delaySeconds, int restartVersion); | ||
|
||
/// <summary> | ||
/// Restarts the league client processes to repair the client. | ||
/// </summary> | ||
Task RestartToRepair(); | ||
|
||
/// <summary> | ||
/// Restarts the league client processes to update. | ||
/// </summary> | ||
/// <param name="delaySeconds">The amount of time to wait before restarting.</param> | ||
/// <param name="selfUpdateUrl">The update source url.</param> | ||
Task RestartToUpdate(int delaySeconds, string selfUpdateUrl); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
LCUSharp/Http/Endpoints/ProcessControl/ProcessControlEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace LCUSharp.Http.Endpoints | ||
{ | ||
/// <inheritdoc cref="IProcessControlEndpoint"/> | ||
internal class ProcessControlEndpoint : EndpointBase, IProcessControlEndpoint | ||
{ | ||
private const string BaseUrl = "process-control/v1/process/"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RiotClientEndpoint"/> class. | ||
/// </summary> | ||
public ProcessControlEndpoint(ILeagueRequestHandler requestHandler) | ||
: base(requestHandler) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task QuitAsync() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}quit").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task RestartAsync(int delaySeconds) | ||
{ | ||
var queryParameters = new List<string>(); | ||
await RestartAsync(delaySeconds, queryParameters).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task RestartAsync(int delaySeconds, int restartVersion) | ||
{ | ||
var queryParameters = new List<string> { $"restartVersion={restartVersion}" }; | ||
await RestartAsync(delaySeconds, queryParameters).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task RestartToRepair() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}restart-to-repair").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task RestartToUpdate(int delaySeconds, string selfUpdateUrl) | ||
{ | ||
var queryParameters = new string[] | ||
{ | ||
$"delaySeconds={delaySeconds}", | ||
$"selfUpdateUrl={selfUpdateUrl}" | ||
}; | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}restart-to-update", queryParameters).ConfigureAwait(false); | ||
} | ||
|
||
/// <summary> | ||
/// Restarts the league client process. | ||
/// </summary> | ||
/// <param name="delaySeconds">The amount of time to wait before restarting.</param> | ||
/// <param name="queryParameters">The query parameters.</param> | ||
/// <returns></returns> | ||
private async Task RestartAsync(int delaySeconds, ICollection<string> queryParameters) | ||
{ | ||
queryParameters.Add($"delaySeconds={delaySeconds}"); | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}restart", queryParameters).ConfigureAwait(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace LCUSharp.Http.Endpoints | ||
{ | ||
/// <summary> | ||
/// Handles operations relating to the riotclient endpoint. | ||
/// </summary> | ||
public interface IRiotClientEndpoint | ||
{ | ||
/// <summary> | ||
/// Minimizes the client. | ||
/// </summary> | ||
Task MinimizeUxAsync(); | ||
|
||
/// <summary> | ||
/// Show the client. | ||
/// </summary> | ||
Task ShowUxAsync(); | ||
|
||
/// <summary> | ||
/// Flashes the client's icon on the taskbar. | ||
/// </summary> | ||
Task FlashUxAsync(); | ||
|
||
/// <summary> | ||
/// Kills the client ux. | ||
/// </summary> | ||
Task KillUxAsync(); | ||
|
||
/// <summary> | ||
/// Kills and restarts the client ux. | ||
/// </summary> | ||
Task KillAndRestartUxAsync(); | ||
|
||
/// <summary> | ||
/// Kills the client ux and resets the state (logs out user, etc.). | ||
/// </summary> | ||
Task UnloadUxAsync(); | ||
|
||
/// <summary> | ||
/// Launches the client ux. | ||
/// </summary> | ||
Task LaunchUxAsync(); | ||
|
||
/// <summary> | ||
/// Gets the client ux zoom scale. | ||
/// </summary> | ||
/// <returns>The zoom scale.</returns> | ||
Task<double> GetZoomScaleAsync(); | ||
|
||
/// <summary> | ||
/// Sets the client ux zoom scale. | ||
/// </summary> | ||
/// <param name="scale">The zoom scale.</param> | ||
/// <returns></returns> | ||
Task SetZoomScaleAsync(double scale); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace LCUSharp.Http.Endpoints | ||
{ | ||
/// <inheritdoc cref="IRiotClientEndpoint"/> | ||
internal class RiotClientEndpoint : EndpointBase, IRiotClientEndpoint | ||
{ | ||
private const string BaseUrl = "riotclient/"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RiotClientEndpoint"/> class. | ||
/// </summary> | ||
public RiotClientEndpoint(ILeagueRequestHandler requestHandler) | ||
: base(requestHandler) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task MinimizeUxAsync() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}ux-minimize").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task ShowUxAsync() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}ux-show").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task FlashUxAsync() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}ux-flash").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task KillUxAsync() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}kill-ux").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task KillAndRestartUxAsync() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}kill-and-restart-ux").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task UnloadUxAsync() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}unload").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task LaunchUxAsync() | ||
{ | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}launch-ux").ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<double> GetZoomScaleAsync() | ||
{ | ||
return double.Parse(await RequestHandler.GetJsonResponseAsync(HttpMethod.Get, $"{BaseUrl}zoom-scale").ConfigureAwait(false)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task SetZoomScaleAsync(double scale) | ||
{ | ||
var queryParameters = new string[] { $"newZoomScale={scale}" }; | ||
await RequestHandler.GetJsonResponseAsync(HttpMethod.Post, $"{BaseUrl}zoom-scale", queryParameters).ConfigureAwait(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace LCUSharp.Http | ||
{ | ||
/// <summary> | ||
/// A request handler for the league client that requires the client's port and the user's Basic authentication token. | ||
/// </summary> | ||
public interface ILeagueRequestHandler | ||
{ | ||
/// <summary> | ||
/// The league client's port. | ||
/// </summary> | ||
int Port { get; set; } | ||
|
||
/// <summary> | ||
/// The user's Basic authentication token | ||
/// </summary> | ||
string Token { get; set; } | ||
|
||
/// <summary> | ||
/// Changes the request handler's settings. | ||
/// </summary> | ||
/// <param name="port">The league client's port.</param> | ||
/// <param name="token">The user's Basic authentication token.</param> | ||
void ChangeSettings(int port, string token); | ||
|
||
/// <summary> | ||
/// Creates and sends a new <see cref="HttpRequestMessage"/> and returns the <see cref="HttpResponseMessage"/>'s content. | ||
/// </summary> | ||
/// <param name="httpMethod">The <see cref="HttpMethod"/>.</param> | ||
/// <param name="relativeUrl">The relative url.</param> | ||
/// <param name="queryParameters">The query parameters.</param> | ||
/// <returns>The <see cref="HttpResponseMessage"/>'s content.</returns> | ||
Task<string> GetJsonResponseAsync(HttpMethod httpMethod, string relativeUrl, IEnumerable<string> queryParameters = null); | ||
|
||
/// <summary> | ||
/// Creates and sends a new <see cref="HttpRequestMessage"/> and returns the <see cref="HttpResponseMessage"/>'s content. | ||
/// </summary> | ||
/// <typeparam name="TRequest">The object to serialize into the body.</typeparam> | ||
/// <param name="httpMethod">The <see cref="HttpMethod"/>.</param> | ||
/// <param name="relativeUrl">The relative url.</param> | ||
/// <param name="queryParameters">The query parameters.</param> | ||
/// <param name="body">The request's body.</param> | ||
/// <returns>The <see cref="HttpResponseMessage"/>'s content.</returns> | ||
Task<string> GetJsonResponseAsync<TRequest>(HttpMethod httpMethod, string relativeUrl, IEnumerable<string> queryParameters, TRequest body); | ||
|
||
/// <summary> | ||
/// Creates and sends a new <see cref="HttpRequestMessage"/> and deserializes the <see cref="HttpResponseMessage"/>'s content (json) as <typeparamref name="TResponse"/>. | ||
/// </summary> | ||
/// <typeparam name="TResponse">The object to deserialize the response into.</typeparam> | ||
/// <param name="httpMethod">The <see cref="HttpMethod"/>/</param> | ||
/// <param name="relativeUrl">The relative url.</param> | ||
/// <param name="queryParameters">The query parameters.</param> | ||
/// <returns>The deserialized response.</returns> | ||
Task<TResponse> GetResponseAsync<TResponse>(HttpMethod httpMethod, string relativeUrl, IEnumerable<string> queryParameters = null); | ||
|
||
/// <summary> | ||
/// Creates and sends a new <see cref="HttpRequestMessage"/> and deserializes the <see cref="HttpResponseMessage"/>'s content (json) as <typeparamref name="TResponse"/>. | ||
/// </summary> | ||
/// <typeparam name="TRequest">The object to serialize into the body.</typeparam> | ||
/// <typeparam name="TResponse">The object to deserialize the response into.</typeparam> | ||
/// <param name="httpMethod">The <see cref="HttpMethod"/>/</param> | ||
/// <param name="relativeUrl">The relative url.</param> | ||
/// <param name="queryParameters">The query parameters.</param> | ||
/// <param name="body">The request's body.</param> | ||
/// <returns>The deserialized response.</returns> | ||
Task<TResponse> GetResponseAsync<TRequest, TResponse>(HttpMethod httpMethod, string relativeUrl, IEnumerable<string> queryParameters, TRequest body); | ||
} | ||
} |
Oops, something went wrong.