Skip to content

Commit

Permalink
Merge pull request #11 from KrystianLesniak/develop
Browse files Browse the repository at this point in the history
RC: 1.1.0
  • Loading branch information
KrystianLesniak authored Jul 14, 2023
2 parents cabc69c + f960c63 commit 823a460
Show file tree
Hide file tree
Showing 51 changed files with 720 additions and 103 deletions.
2 changes: 0 additions & 2 deletions docs/ToDo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<h1 align="center">To Do</h1>

- Create a GitHub Code scanning securities
- Finish XML Documents
- Add more GuardAgainsts in Requests
- Create Unit Tests
2 changes: 1 addition & 1 deletion src/RetroAchievements.Api.ConsoleTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
// await Task.Delay(500);

//}
var response = await client.GetGameExtendedDataAsync(12264);
var response = await client.GetGameTicketDataAsync(4106);
};
6 changes: 6 additions & 0 deletions src/RetroAchievements.Api/AchievementsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

namespace RetroAchievements.Api
{
/// <summary>
/// Class with extension methods for calling APIs from group "Achievements"
/// </summary>
public static class AchievementsApi
{
#region GetAchievementUnlocks
/// <inheritdoc cref="GetAchievementUnlocksRequest(int, int, int)"/>
public static async Task<GetAchievementUnlocksResponse> GetAchievementUnlocksAsync(this RetroAchievementsHttpClient client, int achievementId, int offset = 0, int count = 50, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetAchievementUnlocksRequest(achievementId, offset, count), authenticationData);
}

/// <inheritdoc cref="GetAchievementUnlocksRequest(int, int, int)"/>
public static GetAchievementUnlocksResponse GetAchievementUnlocks(this RetroAchievementsHttpClient client, int achievementId, int offset = 0, int count = 50, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetAchievementUnlocksRequest(achievementId, offset, count), authenticationData);
Expand Down
12 changes: 12 additions & 0 deletions src/RetroAchievements.Api/Requests/Consoles/GetGamesListRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace RetroAchievements.Api.Requests.Consoles
{
/// <summary>
/// Get list of known games for specified console
/// </summary>
public record GetGamesListRequest : IRetroAchievementsRequest<GetGamesListResponse>
{
/// <inheritdoc />
Expand All @@ -19,12 +22,21 @@ public GetGamesListRequest(int consoleId, bool onlyWithAchievements = false, boo
GetHashes = getHashes ? 1 : 0;
}

/// <summary>
/// Console Identifier
/// </summary>
[ApiInputKey("i")]
public int ConsoleId { get; init; }

/// <summary>
/// Only return games that contains achievements
/// </summary>
[ApiInputKey("f")]
public int OnlyWithAchievements { get; init; }

/// <summary>
/// Also return game hashes
/// </summary>
[ApiInputKey("h")]
public int GetHashes { get; init; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

namespace RetroAchievements.Api.Requests.Users
{
/// <summary>
/// Get data about top ten users (by score) for the site.
/// </summary>
public record GetTopTenUsersRequest : IRetroAchievementsRequest<GetTopTenUsersResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetTopTenUsers";

///<inheritdoc cref="GetTopTenUsersRequest" />
public GetTopTenUsersRequest()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

namespace RetroAchievements.Api.Requests.Games
{
/// <summary>
/// Get 'Latest Masters' or 'High Scores' entries for a game.
/// </summary>
public record GetGameRankAndScoreRequest : IRetroAchievementsRequest<GetGameRankAndScoreResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetGameRankAndScore";

///<inheritdoc cref="GetGameRankAndScoreRequest" />
///<param name="gameId"><inheritdoc cref="GameId" path="/summary/node()"/></param>
///<param name="rankType"><inheritdoc cref="RankType" path="/summary/node()"/></param>
public GetGameRankAndScoreRequest(int gameId, RankType rankType = RankType.HighScores)
{
ArgumentNullException.ThrowIfNull(gameId);
Expand All @@ -17,16 +24,36 @@ public GetGameRankAndScoreRequest(int gameId, RankType rankType = RankType.HighS
RankType = rankType;
}

/// <summary>
/// Unique identifier of the game.
/// </summary>
[ApiInputKey("g")]
public int GameId { get; init; }

/// <summary>
/// Type of rank to seek for.
/// </summary>
/// <remarks>
/// <see cref="RankType.HighScores"/>: High Scores ranks. <br />
/// <see cref="RankType.LatestMasters"/>: Latest Masters ranks.
/// </remarks>
[ApiInputKey("t")]
public RankType RankType { get; init; }
}

/// <summary>
/// <see cref="RankType.HighScores"/>: High Scores ranks. <br />
/// <see cref="RankType.LatestMasters"/>: Latest Masters ranks.
/// </summary>
public enum RankType
{
/// <summary>
/// High Score ranks.
/// </summary>
HighScores = 0,
/// <summary>
/// Latest Masters ranks.
/// </summary>
LatestMasters = 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@

namespace RetroAchievements.Api.Requests.Games
{
/// <summary>
/// Get the overall rating of the game.
/// </summary>
public record GetGameRatingRequest : IRetroAchievementsRequest<GetGameRatingResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetGameRating";

///<inheritdoc cref="GetGameRatingRequest" />
///<param name="gameId"><inheritdoc cref="GameId" path="/summary/node()"/></param>
public GetGameRatingRequest(int gameId)
{
ArgumentNullException.ThrowIfNull(gameId);

GameId = gameId;
}

/// <summary>
/// Unique identifier of the game
/// </summary>
[ApiInputKey("i")]
public int GameId { get; init; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@

namespace RetroAchievements.Api.Requests.Tickets
{
/// <summary>
/// Get ticket statistics data for the specified achievement.
/// </summary>
public record GetAchievementTicketDataRequest : IRetroAchievementsRequest<GetAchievementTicketDataResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetTicketData";

///<inheritdoc cref="GetAchievementTicketDataRequest" />
///<param name="achievementId"><inheritdoc cref="AchievementId" path="/summary/node()"/></param>
public GetAchievementTicketDataRequest(int achievementId)
{
AchievementId = achievementId;
}

/// <summary>
/// Unique identifier of achievement.
/// </summary>
[ApiInputKey("a")]
public int AchievementId { get; init; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@

namespace RetroAchievements.Api.Requests.Tickets
{
/// <summary>
/// Get ticket data for the specified game.
/// </summary>
public record GetGameTicketDataRequest : IRetroAchievementsRequest<GetGameTicketDataResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetTicketData";

///<inheritdoc cref="GetGameTicketDataRequest" />
///<param name="gameId"><inheritdoc cref="GameId" path="/summary/node()"/></param>
public GetGameTicketDataRequest(int gameId)
{
GameId = gameId;
}

/// <summary>
/// Unique identifier of the game.
/// </summary>
[ApiInputKey("g")]
public int GameId { get; init; }

[ApiInputKey("f")]
public int ConstApiFlag { get; init; } = 5;

/// <summary>
/// Internal API Flag
/// </summary>
[ApiInputKey("d")]
public int ConstApiDataFlag { get; init; } = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@

namespace RetroAchievements.Api.Requests.Tickets
{
/// <summary>
/// Get games with the most open tickets.
/// </summary>
public record GetGamesWithMostTicketsRequest : IRetroAchievementsRequest<GetGamesWithMostTicketsResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetTicketData";

///<inheritdoc cref="GetGamesWithMostTicketsRequest" />
///<param name="offset"><inheritdoc cref="Offset" path="/summary/node()"/></param>
///<param name="count"><inheritdoc cref="Count" path="/summary/node()"/></param>
public GetGamesWithMostTicketsRequest(int offset = 0, int count = 10)
{
ArgumentExceptionGuard.ThrowIfGreaterThan(count, nameof(count), 100);
Expand All @@ -17,12 +24,21 @@ public GetGamesWithMostTicketsRequest(int offset = 0, int count = 10)
Count = count;
}

/// <summary>
/// Number of entries to skip (default: <see langword="0"/>).
/// </summary>
[ApiInputKey("o")]
public int Offset { get; init; }

/// <summary>
/// Number of entries to return (default: <see langword="10"/>, max: <see langword="100"/>).
/// </summary>
[ApiInputKey("c")]
public int Count { get; init; }

/// <summary>
/// Internal API Flag
/// </summary>
[ApiInputKey("f")]
public int ConstApiFlag { get; init; } = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@

namespace RetroAchievements.Api.Requests.Tickets
{
/// <summary>
/// Get open tickets, starting from the most recent.
/// </summary>
public record GetOpenTicketsRequest : IRetroAchievementsRequest<GetOpenTicketsResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetTicketData";

///<inheritdoc cref="GetOpenTicketsRequest" />
///<param name="offset"><inheritdoc cref="Offset" path="/summary/node()"/></param>
///<param name="count"><inheritdoc cref="Count" path="/summary/node()"/></param>
public GetOpenTicketsRequest(int offset = 0, int count = 10)
{
ArgumentExceptionGuard.ThrowIfGreaterThan(count, nameof(count), 100);
Expand All @@ -17,9 +24,15 @@ public GetOpenTicketsRequest(int offset = 0, int count = 10)
Count = count;
}

/// <summary>
/// Number of entries to skip (default: <see langword="0"/>).
/// </summary>
[ApiInputKey("o")]
public int Offset { get; init; }

/// <summary>
/// Number of entries to return (default: <see langword="10"/>, max: <see langword="100"/>).
/// </summary>
[ApiInputKey("c")]
public int Count { get; init; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@

namespace RetroAchievements.Api.Requests.Tickets
{
/// <summary>
/// Get details data for a specific ticket.
/// </summary>
public record GetTicketDataRequest : IRetroAchievementsRequest<GetTicketDataResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetTicketData";

///<inheritdoc cref="GetTicketDataRequest" />
///<param name="ticketId"><inheritdoc cref="TicketId" path="/summary/node()"/></param>
public GetTicketDataRequest(int ticketId)
{
ArgumentNullException.ThrowIfNull(ticketId);

TicketId = ticketId;
}

/// <summary>
/// Ticket identifier.
/// </summary>
[ApiInputKey("i")]
public int TicketId { get; init; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@

namespace RetroAchievements.Api.Requests.Tickets
{
/// <summary>
/// Get ticket statistics data for the specified user.
/// </summary>
public record GetUserTicketDataRequest : IRetroAchievementsRequest<GetUserTicketDataResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetTicketData";

///<inheritdoc cref="GetUserTicketDataRequest" />
///<param name="username"><inheritdoc cref="Username" path="/summary/node()"/></param>
public GetUserTicketDataRequest(string username)
{
ArgumentNullException.ThrowIfNull(username);

Username = username;
}

/// <summary>
/// Username of user to seek tickets data for.
/// </summary>
[ApiInputKey("u")]
public string Username { get; init; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@

namespace RetroAchievements.Api.Requests.Users
{
/// <summary>
/// Get games progress for specified user.
/// </summary>
public record GetUserAllGamesProgressRequest : IRetroAchievementsRequest<GetUserAllGamesProgressResponse>
{
/// <inheritdoc />
public string RequestEndpoint => "API_GetUserCompletedGames";


///<inheritdoc cref="GetUserAwardsRequest" />
///<param name="username"><inheritdoc cref="Username" path="/summary/node()"/></param>
public GetUserAllGamesProgressRequest(string username)
{
ArgumentNullException.ThrowIfNull(username, nameof(username));

Username = username;
}

public string RequestEndpoint => "API_GetUserCompletedGames";

/// <summary>
/// Username of the user.
/// </summary>
[ApiInputKey("u")]
public string Username { get; init; }
}
Expand Down
Loading

0 comments on commit 823a460

Please sign in to comment.