Skip to content

Commit

Permalink
Release Candidate: 1.0.0
Browse files Browse the repository at this point in the history
Release Candidate: 1.0.0
  • Loading branch information
KrystianLesniak authored Jul 12, 2023
2 parents 7aa40ff + 1abde31 commit 216f34a
Show file tree
Hide file tree
Showing 86 changed files with 1,272 additions and 563 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# RetroAchievements API .NET
## Work In Progress ⏳ Experimental use only. <br> Property and method names may change before stable release.

_A C# .NET library that lets you get achievement, user, and game data from RetroAchievements._
<br><br>
Expand All @@ -23,12 +22,10 @@ Learn how to authenticate and start pulling data from RetroAchievements.

## Installation

**Warning: This library is still in WIP experimental phase.**

Install `RetroAchievements.Api` NuGet via Package Manager or run the following dotnet CLI command:

```bash
dotnet add package RetroAchievements.Api --version <latest NuGet preview version>
dotnet add package RetroAchievements.Api
```

## How to begin making API calls
Expand Down Expand Up @@ -95,20 +92,20 @@ class Program
- ❌ GetGameInfoAndUserProgress() - Temporary disabled: [#46](https://github.com/RetroAchievements/retroachievements-api-js/issues/46) - Get metadata about a game as well as a user's progress on that game.
- GetUserAwards(string username) - Get a list of a user's site awards/badges.
- GetUserClaims(string username) - Get a list of set claims made over the lifetime of a user.
- GetUserCompletedGames(string username) - Get hardcore and softcore completion metadata about games a user has played.
- GetUserAllGamesProgress(string username) - Get hardcore and softcore completion metadata about games a user has played.
- GetUserGameRankAndScore(string username, int gameId) - Get metadata about how a user has performed on a given game.
- GetUserPoints(string username) - Get a user's total points.
- GetUserRankAndScore(string username) - Get a user's total points and rank.
- GetUserProgress(string username) - Get a user's progress on a list of specified games.
- GetUserGamesProgress(string username) - Get a user's progress on a list of specified games.
- GetUserRecentAchievements(string username, IEnumerable<int> gameIds) - Get a list of achievements recently earned by the user.
- ❌ GetUserRecentlyPlayedGames() - Temporary disabled: [#46](https://github.com/RetroAchievements/retroachievements-api-js/issues/46) - Get a list of games a user has recently played.
- ❌ GetUserSummary() - Temporary disabled: [#46](https://github.com/RetroAchievements/retroachievements-api-js/issues/46) - Get a user's profile metadata.

#### Games
- GetAchievementCount(int gameId) - Get the list of achievement IDs for a game.
- GetAchievementIdentifiers(int gameId) - Get the list of achievement IDs for a game.
- GetAchievementDistribution(int gameId, bool hardcoreOnly, bool unofficialAchievements) - Get how many players have unlocked how many achievements for a game.
- GetGame(int gameId) - Get basic metadata about a game.
- GetGameExtended(int gameId) - Get extended metadata about a game.
- GetGameData(int gameId) - Get basic metadata about a game.
- GetGameExtendedData(int gameId) - Get extended metadata about a game.
- GetGameRankAndScore(int gameId, RankType rankType) - Get a list of either the latest masters or highest points earners for a game.
- GetGameRating(int gameId) - Get how users have rated a game.

Expand All @@ -117,7 +114,7 @@ class Program

#### Consoles
- GetConsoleIds() - Get the complete list of console ID and name pairs on the site.
- GetGameList(int consoleId, bool onlyWithAchievements, bool getHashes) - Get the complete list of games for a console.
- GetGamesList(int consoleId, bool onlyWithAchievements, bool getHashes) - Get the complete list of games for a console.

#### Feed
- GetAchievementOfTheWeek() - Get comprehensive metadata about the current Achievement of the Week.
Expand All @@ -133,8 +130,6 @@ class Program
- GetGameTicketData(int gameId) - Get ticket statistics for the specified game.
- GetAchievementTicketData(int achievementId) - Get ticket statistics for the specified achievement.

<br />

## Different usages

TODO
Expand Down
8 changes: 2 additions & 6 deletions docs/ToDo.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<h1 align="center">To Do</h1>

- Create a GitHub Code scanning securities

- Add XML tags for C# documentation comments
- Make Collections ReadOnly
- Check if GuardAgainsts are in Requests
- Rename Properties / Responses / Requests to better reflect c# .net naming conventions

- 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.GetAchievementTicketDataAsync(26345);
var response = await client.GetGameExtendedDataAsync(12264);
};
9 changes: 8 additions & 1 deletion src/RetroAchievements.Api/BaseApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@

namespace RetroAchievements.Api
{
/// <summary>
/// Class with extension methods for calling APIs with Request class
/// </summary>
public static class BaseApi
{

/// <summary>
/// Calls passed RetroAchievements API request.
/// </summary>
/// <returns>Response data of called request.</returns>
public static async Task<TResponse> SendAsync<TResponse>(this RetroAchievementsHttpClient client, IRetroAchievementsRequest<TResponse> request, RetroAchievementsAuthenticationData? authenticationData = null) where TResponse : RetroAchievementsResponse, new()
{
return await client.HandleRequestCallAsync(request, authenticationData);
}

/// <inheritdoc cref="SendAsync{TResponse}(RetroAchievementsHttpClient, IRetroAchievementsRequest{TResponse}, RetroAchievementsAuthenticationData?)"/>
public static TResponse Send<TResponse>(this RetroAchievementsHttpClient client, IRetroAchievementsRequest<TResponse> request, RetroAchievementsAuthenticationData? authenticationData = null) where TResponse : RetroAchievementsResponse, new()
{
return client.HandleRequestCall(request, authenticationData);
Expand Down
21 changes: 15 additions & 6 deletions src/RetroAchievements.Api/ConsolesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,37 @@

namespace RetroAchievements.Api
{
/// <summary>
/// Class with extension methods for calling APIs from group "Consoles"
/// </summary>
public static class ConsolesApi
{
#region GetConsoleIds
/// <inheritdoc cref="GetConsoleIdsRequest()"/>
public static async Task<GetConsoleIdsResponse> GetConsoleIdsAsync(this RetroAchievementsHttpClient client, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetConsoleIdsRequest(), authenticationData);
}

/// <inheritdoc cref="GetConsoleIdsRequest()"/>
public static GetConsoleIdsResponse GetConsoleIds(this RetroAchievementsHttpClient client, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetConsoleIdsRequest(), authenticationData);
}
#endregion GetConsoleIds

#region GetGameList
public static async Task<GetGameListResponse> GetGameListAsync(this RetroAchievementsHttpClient client, int consoleId, bool onlyWithAchievements = false, bool getHashes = false, RetroAchievementsAuthenticationData? authenticationData = null)
#region GetGamesList
/// <inheritdoc cref="GetGamesListRequest(int, bool, bool)"/>
public static async Task<GetGamesListResponse> GetGamesListAsync(this RetroAchievementsHttpClient client, int consoleId, bool onlyWithAchievements = false, bool getHashes = false, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetGameListRequest(consoleId, onlyWithAchievements, getHashes), authenticationData);
return await client.SendAsync(new GetGamesListRequest(consoleId, onlyWithAchievements, getHashes), authenticationData);
}
public static GetGameListResponse GetGameList(this RetroAchievementsHttpClient client, int consoleId, bool onlyWithAchievements = false, bool getHashes = false, RetroAchievementsAuthenticationData? authenticationData = null)

/// <inheritdoc cref="GetGamesListRequest(int, bool, bool)"/>
public static GetGamesListResponse GetGamesList(this RetroAchievementsHttpClient client, int consoleId, bool onlyWithAchievements = false, bool getHashes = false, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetGameListRequest(consoleId, onlyWithAchievements, getHashes), authenticationData);
return client.Send(new GetGamesListRequest(consoleId, onlyWithAchievements, getHashes), authenticationData);
}
#endregion GetGameList
#endregion GetGamesList
}
}
12 changes: 12 additions & 0 deletions src/RetroAchievements.Api/FeedApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,61 @@

namespace RetroAchievements.Api
{
/// <summary>
/// Class with extension methods for calling APIs from group "Feed"
/// </summary>
public static class FeedApi
{
#region GetAchievementOfTheWeek
/// <inheritdoc cref="GetAchievementOfTheWeekRequest()"/>
public static async Task<GetAchievementOfTheWeekResponse> GetAchievementOfTheWeekAsync(this RetroAchievementsHttpClient client, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetAchievementOfTheWeekRequest(), authenticationData);
}

/// <inheritdoc cref="GetAchievementOfTheWeekRequest()"/>
public static GetAchievementOfTheWeekResponse GetAchievementOfTheWeek(this RetroAchievementsHttpClient client, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetAchievementOfTheWeekRequest(), authenticationData);
}
#endregion GetAchievementOfTheWeek

#region GetActiveClaims
/// <inheritdoc cref="GetActiveClaimsRequest()"/>
public static async Task<GetActiveClaimsResponse> GetActiveClaimsAsync(this RetroAchievementsHttpClient client, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetActiveClaimsRequest(), authenticationData);
}

/// <inheritdoc cref="GetActiveClaimsRequest()"/>
public static GetActiveClaimsResponse GetActiveClaims(this RetroAchievementsHttpClient client, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetActiveClaimsRequest(), authenticationData);
}
#endregion GetActiveClaims

#region GetClaims
/// <inheritdoc cref="GetClaimsRequest(ClaimKind)"/>
public static async Task<GetClaimsResponse> GetClaimsAsync(this RetroAchievementsHttpClient client, ClaimKind claimKind = ClaimKind.Completed, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetClaimsRequest(claimKind), authenticationData);
}

/// <inheritdoc cref="GetClaimsRequest(ClaimKind)"/>
public static GetClaimsResponse GetClaims(this RetroAchievementsHttpClient client, ClaimKind claimKind = ClaimKind.Completed, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetClaimsRequest(claimKind), authenticationData);
}
#endregion GetClaims

#region GetTopTenUsers
/// <inheritdoc cref="GetTopTenUsersRequest()"/>
public static async Task<GetTopTenUsersResponse> GetTopTenUsersAsync(this RetroAchievementsHttpClient client, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetTopTenUsersRequest(), authenticationData);
}

/// <inheritdoc cref="GetTopTenUsersRequest()"/>
public static GetTopTenUsersResponse GetTopTenUsers(this RetroAchievementsHttpClient client, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetTopTenUsersRequest(), authenticationData);
Expand Down
46 changes: 34 additions & 12 deletions src/RetroAchievements.Api/GamesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,90 @@

namespace RetroAchievements.Api
{
/// <summary>
/// Class with extension methods for calling APIs from group "Games"
/// </summary>
public static class GamesApi
{
#region GetAchievementCount
public static async Task<GetAchievementCountResponse> GetAchievementCountAsync(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
/// <inheritdoc cref="GetAchievementIdentifiersRequest(int)"/>
public static async Task<GetAchievementIdentifiersResponse> GetAchievementIdentifiersAsync(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetAchievementCountRequest(gameId), authenticationData);
return await client.SendAsync(new GetAchievementIdentifiersRequest(gameId), authenticationData);
}
public static GetAchievementCountResponse GetAchievementCount(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)

/// <inheritdoc cref="GetAchievementIdentifiersRequest(int)"/>
public static GetAchievementIdentifiersResponse GetAchievementIdentifiers(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetAchievementCountRequest(gameId), authenticationData);
return client.Send(new GetAchievementIdentifiersRequest(gameId), authenticationData);
}
#endregion GetAchievementCount

#region GetAchievementDistribution
/// <inheritdoc cref="GetAchievementDistributionRequest(int, bool, bool)"/>
public static async Task<GetAchievementDistributionResponse> GetAchievementDistributionAsync(this RetroAchievementsHttpClient client, int gameId, bool hardcoreOnly = false, bool unofficialAchievements = false, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetAchievementDistributionRequest(gameId, hardcoreOnly, unofficialAchievements), authenticationData);
}

/// <inheritdoc cref="GetAchievementDistributionRequest(int, bool, bool)"/>
public static GetAchievementDistributionResponse GetAchievementDistribution(this RetroAchievementsHttpClient client, int gameId, bool hardcoreOnly = false, bool unofficialAchievements = false, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetAchievementDistributionRequest(gameId, hardcoreOnly, unofficialAchievements), authenticationData);
}
#endregion GetAchievementDistribution

#region GetGame
public static async Task<GetGameResponse> GetGameAsync(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
/// <inheritdoc cref="GetGameDataRequest(int)"/>
public static async Task<GetGameDataResponse> GetGameDataAsync(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetGameRequest(gameId), authenticationData);
return await client.SendAsync(new GetGameDataRequest(gameId), authenticationData);
}
public static GetGameResponse GetGame(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)

/// <inheritdoc cref="GetGameDataRequest(int)"/>
public static GetGameDataResponse GetGameData(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetGameRequest(gameId), authenticationData);
return client.Send(new GetGameDataRequest(gameId), authenticationData);
}
#endregion GetGame

#region GetGameExtended
public static async Task<GetGameExtendedResponse> GetGameExtendedAsync(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
/// <inheritdoc cref="GetGameExtendedDataRequest(int)"/>
public static async Task<GetGameExtendedDataResponse> GetGameExtendedDataAsync(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetGameExtendedRequest(gameId), authenticationData);
return await client.SendAsync(new GetGameExtendedDataRequest(gameId), authenticationData);
}
public static GetGameExtendedResponse GetGameExtended(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)

/// <inheritdoc cref="GetGameExtendedDataRequest(int)"/>
public static GetGameExtendedDataResponse GetGameExtendedData(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetGameExtendedRequest(gameId), authenticationData);
return client.Send(new GetGameExtendedDataRequest(gameId), authenticationData);
}
#endregion GetGameExtended

#region GetGameRankAndScore
/// <inheritdoc cref="GetGameRankAndScoreRequest(int, RankType)"/>
public static async Task<GetGameRankAndScoreResponse> GetGameRankAndScoreAsync(this RetroAchievementsHttpClient client, int gameId, RankType rankType = RankType.HighScores, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetGameRankAndScoreRequest(gameId, rankType), authenticationData);
}

/// <inheritdoc cref="GetGameRankAndScoreRequest(int, RankType)"/>
public static GetGameRankAndScoreResponse GetGameRankAndScore(this RetroAchievementsHttpClient client, int gameId, RankType rankType = RankType.HighScores, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetGameRankAndScoreRequest(gameId, rankType), authenticationData);
}
#endregion GetGameRankAndScore

#region GetGameRating

/// <inheritdoc cref="GetGameRatingRequest(int)"/>
public static async Task<GetGameRatingResponse> GetGameRatingAsync(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
{
return await client.SendAsync(new GetGameRatingRequest(gameId), authenticationData);
}

/// <inheritdoc cref="GetGameRatingRequest(int)"/>
public static GetGameRatingResponse GetGameRating(this RetroAchievementsHttpClient client, int gameId, RetroAchievementsAuthenticationData? authenticationData = null)
{
return client.Send(new GetGameRatingRequest(gameId), authenticationData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
{
return parsedDate;
}
else if (DateTime.TryParseExact(reader.GetString(), "yyyy-MM-dd", null,
DateTimeStyles.None, out DateTime parsedDate2))
{
return parsedDate2;
}
else if (DateTime.TryParseExact(reader.GetString(), "yyyy-MM", null,
DateTimeStyles.None, out DateTime parsedDate3))
{
return parsedDate3;
}
else if (DateTime.TryParseExact(reader.GetString(), "yyyy", null,
DateTimeStyles.None, out DateTime parsedDate4))
{
return parsedDate4;
}
else
{
return DateTime.Parse(reader.GetString()!);
Expand Down
Loading

0 comments on commit 216f34a

Please sign in to comment.