Skip to content

Commit

Permalink
feat(data): support challenge api
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdayo committed Oct 23, 2022
1 parent 8171809 commit dc4da6d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ArcaeaUnlimitedAPI.Lib/ArcaeaUnlimitedAPI.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Title>ArcaeaUnlimitedAPI.Lib</Title>
<PackageVersion>2.0.0</PackageVersion>
<PackageVersion>2.1.0</PackageVersion>
<Authors>b1acksoil</Authors>
<Description>Lib for ArcaeaUnlimitedAPI.</Description>
<PackageTags>Arcaea</PackageTags>
Expand Down
40 changes: 40 additions & 0 deletions ArcaeaUnlimitedAPI.Lib/Core/AuaDataApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,44 @@ public Task<int[][]> Density(string songname, ArcaeaDifficulty difficulty = Arca
=> GetDensity(songname, AuaSongQueryType.SongName, difficulty);

#endregion /data/density

#region /data/challenge

private async Task<string> GetChallenge(string path, string? body, long? timestamp)
{
var qb = new QueryBuilder()
.Add("path", path);

if (body is not null) qb.Add("body", body);
if (timestamp is not null) qb.Add("timestamp", timestamp.ToString()!);

var response = JsonSerializer.Deserialize<AuaResponse<string>>(
await _client.GetStringAsync("data/challenge" + qb.Build()))!;
if (response.Status < 0)
throw new AuaException(response.Status, response.Message!);
return response.Content!;
}

/// <summary>
/// Get challenge of a specified arcapi path.
/// </summary>
/// <param name="path">Request arcapi path.</param>
/// <param name="body">Request body, optional when body is empty.</param>
/// <param name="timestamp">Request timestamp.</param>
/// <returns>Challenge string.</returns>
/// <remarks>It is designed for the release version of AUA, and not available for the release version.</remarks>
public Task<string> Challenge(string path, string? body = null, long? timestamp = null)
=> GetChallenge(path, body, timestamp);

/// <summary>
/// Get challenge of a specified arcapi path.
/// </summary>
/// <param name="path">Request arcapi path.</param>
/// <param name="timestamp">Request timestamp.</param>
/// <returns>Challenge string.</returns>
/// <remarks>It is designed for the release version of AUA, and not available for the release version.</remarks>
public Task<string> Challenge(string path, long? timestamp = null)
=> GetChallenge(path, null, timestamp);

#endregion /data/challenge
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Console.WriteLine(songinfo.Difficulties[2].NameEn);
- [x] [data/theory](https://github.com/Arcaea-Infinity/ArcaeaUnlimitedAPI-Wiki/blob/main/data/theory.md)
- [x] [data/playdata](https://github.com/Arcaea-Infinity/ArcaeaUnlimitedAPI-Wiki/blob/main/data/playdata.md)
- [x] [data/density](https://github.com/Arcaea-Infinity/ArcaeaUnlimitedAPI-Wiki/blob/main/data/density.md)
- [ ] [data/challenge](https://github.com/Arcaea-Infinity/ArcaeaUnlimitedAPI-Wiki/blob/main/data/challenge.md)
- [x] [data/challenge](https://github.com/Arcaea-Infinity/ArcaeaUnlimitedAPI-Wiki/blob/main/data/challenge.md)

## License

Expand Down

0 comments on commit dc4da6d

Please sign in to comment.