Skip to content

Commit

Permalink
Added files
Browse files Browse the repository at this point in the history
  • Loading branch information
MManoah committed Jul 15, 2020
1 parent e4ed692 commit ad95fd3
Show file tree
Hide file tree
Showing 31 changed files with 5,711 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LCUSharp/Http/Endpoints/EndpointBase.cs
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 LCUSharp/Http/Endpoints/ProcessControl/IProcessControlEndpoint.cs
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 LCUSharp/Http/Endpoints/ProcessControl/ProcessControlEndpoint.cs
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);
}
}
}
58 changes: 58 additions & 0 deletions LCUSharp/Http/Endpoints/RiotClient/IRiotClientEndpoint.cs
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);
}
}
74 changes: 74 additions & 0 deletions LCUSharp/Http/Endpoints/RiotClient/RiotClientEndpoint.cs
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);
}
}
}
71 changes: 71 additions & 0 deletions LCUSharp/Http/ILeagueRequestHandler.cs
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);
}
}
Loading

0 comments on commit ad95fd3

Please sign in to comment.