Skip to content

Commit

Permalink
Add mods and ruleset parameters to GetDifficultyAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
matte-ek committed Aug 21, 2024
1 parent c743d30 commit f4ecaa6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions OsuSharp/Endpoints/Beatmaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,16 @@ public async Task<BeatmapExtended[]> GetBeatmapsAsync(params int[] ids)
/// <a href="https://osu.ppy.sh/docs/index.html#get-beatmap"/>
/// </summary>
/// <param name="id">The ID of the beatmap.</param>
/// <param name="mods">The mods to get the attributes from.</param>
/// <param name="ruleset">The ruleset to get the attributes from.</param>
/// <returns>The difficulty attributes or null, if the beatmap was not found.</returns>
public async Task<DifficultyAttributes?> GetDifficultyAttributesAsync(int id)
public async Task<DifficultyAttributes?> GetDifficultyAttributesAsync(int id, string? mods = null, string? ruleset = null)
{
// Send the request and return the difficulty attributes object.
return await GetFromJsonAsync<DifficultyAttributes>($"beatmaps/{id}/attributes", jsonSelector: x => x["attributes"], method: HttpMethod.Post);
return await GetFromJsonAsync<DifficultyAttributes>($"beatmaps/{id}/attributes",new Dictionary<string, object?>()
{
{ "mods", mods },
{ "ruleset", ruleset }
}, x => x["attributes"], method: HttpMethod.Post);
}
}
10 changes: 9 additions & 1 deletion OsuSharp/OsuApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.ComponentModel;
using System.Net;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Reflection;
using System.Web;

Expand Down Expand Up @@ -116,8 +117,15 @@ public async Task EnsureAccessTokenAsync()

try
{
// Prepare HTTP request
var message = new HttpRequestMessage(method ?? HttpMethod.Get, method == HttpMethod.Get ? $"{url}?{BuildQueryString(parameters)}" : url);

// Append POST body if required
if (method == HttpMethod.Post)
message.Content = JsonContent.Create(parameters);

// Send the request and validate the response. If 404 is returned, return null.
HttpResponseMessage response = await _http.SendAsync(new HttpRequestMessage(method ?? HttpMethod.Get, $"{url}?{BuildQueryString(parameters)}"));
HttpResponseMessage response = await _http.SendAsync(message);
if (response.StatusCode == HttpStatusCode.NotFound)
return default;

Expand Down

0 comments on commit f4ecaa6

Please sign in to comment.