Files
YandexMusic/YandexMusic.API/Requests/Common/YRequest.cs
2026-04-10 15:05:32 +03:00

45 lines
950 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using YandexMusic.API.Common;
using YandexMusic.API.Common.Providers;
namespace YandexMusic.API.Requests.Common;
internal class YRequest<T>
{
#region Поля
private HttpRequestMessage msg;
private IRequestProvider provider;
protected YandexMusicApi api;
#endregion Поля
public YRequest(HttpRequestMessage message, YandexMusicApi yandex, AuthStorage auth)
{
msg = message;
api = yandex;
provider = auth.Provider;
}
public async Task<T> GetResponseAsync()
{
if (msg == null)
return default;
HttpResponseMessage response = await provider.GetWebResponseAsync(msg);
if (typeof(T) == typeof(HttpResponseMessage))
return (T)(object)response;
try
{
return await provider.GetDataFromResponseAsync<T>(api, response);
}
finally
{
response.Dispose();
}
}
}