Returning HttpData instead of tuples.

This commit is contained in:
Filip Strajnar 2024-06-18 20:16:15 +02:00
parent 8b65461267
commit 3c462012e2

View file

@ -37,16 +37,20 @@ public class DiscordUserClient
return await GetShortProfile("@me");
}
public async Task<(
HttpResponseMessage Response,
MessageSearchResponse? JsonData
)> GetChannelMessages(string channelId, int offset = 0, string? authorId = null)
public async Task<HttpData<MessageSearchResponse>> GetChannelMessages(
string channelId,
int offset = 0,
string? authorId = null
)
{
string authorQuery = authorId is not null ? $"&author_id={authorId}" : "";
string url =
$"https://discord.com/api/v9/channels/{channelId}/messages/search?offset={offset}{authorQuery}";
HttpResponseMessage response = await _httpClient.GetAsync(url);
return (response, await response.Content.ReadFromJsonAsync<MessageSearchResponse>());
return new HttpData<MessageSearchResponse>(
response,
await response.Content.ReadFromJsonAsync<MessageSearchResponse>()
);
}
sealed class MessageContent
@ -84,15 +88,19 @@ public class DiscordUserClient
/// recent messages from this particular author.
/// </param>
/// <returns></returns>
public async Task<(
HttpResponseMessage Response,
MessageSearchResponse? JsonData
)> SearchGuildMessages(string guildId, int offset, string? authorId = null)
public async Task<HttpData<MessageSearchResponse>> SearchGuildMessages(
string guildId,
int offset,
string? authorId = null
)
{
string authorQuery = authorId is not null ? $"&author_id={authorId}" : "";
string url =
$"https://discord.com/api/v9/guilds/{guildId}/messages/search?offset={offset}{authorQuery}";
HttpResponseMessage response = await _httpClient.GetAsync(url);
return (response, await response.Content.ReadFromJsonAsync<MessageSearchResponse>());
return new HttpData<MessageSearchResponse>(
response,
await response.Content.ReadFromJsonAsync<MessageSearchResponse>()
);
}
}