Полностью переписанное api
All checks were successful
Release / pack-and-publish (release) Successful in 36s

This commit is contained in:
FrigaT
2026-04-19 17:00:05 +03:00
parent 5541d0ad27
commit 36e28ce3fe
111 changed files with 1552 additions and 3358 deletions

View File

@@ -5,67 +5,45 @@ using System.Net.Http.Json;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using YandexMusic.API.Common;
using YandexMusic.API.Models.Radio;
using YandexMusic.API.Models.Track;
using YandexMusic.API.Requests.Common;
using YandexMusic.API.Requests.Common.Attributes;
namespace YandexMusic.API.Requests.Radio;
[YApiRequest(WebRequestMethods.Http.Post, "rotor/station/{type}:{tag}/feedback")]
public class YSetStationFeedbackBuilder : YRequestBuilder<string, (YStationFeedbackType type, YStation station, YTrack track, string batchId, double totalPlayedSeconds)>
public class YSetStationFeedbackBuilder : YMusicRequestBuilder<string?, (YStationFeedbackType type, YStation station, YTrack? track, string batchId, double totalPlayedSeconds)>
{
public YSetStationFeedbackBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
public YSetStationFeedbackBuilder(YandexMusicApi api) : base(api) { }
protected override string Method => WebRequestMethods.Http.Post;
protected override string PathTemplate => "rotor/station/{type}:{tag}/feedback";
protected override Dictionary<string, string> GetSubstitutions((YStationFeedbackType type, YStation station, YTrack? track, string batchId, double totalPlayedSeconds) tuple)
=> new() { { "type", tuple.station.Station.Id.Type }, { "tag", tuple.station.Station.Id.Tag } };
protected override NameValueCollection GetQueryParams((YStationFeedbackType type, YStation station, YTrack? track, string batchId, double totalPlayedSeconds) tuple)
{
var query = new NameValueCollection();
if (!string.IsNullOrWhiteSpace(tuple.batchId))
query.Add("batch-id", tuple.batchId);
return query;
}
protected override Dictionary<string, string> GetSubstitutions((YStationFeedbackType type, YStation station, YTrack track, string batchId, double totalPlayedSeconds) tuple)
protected override HttpContent? GetContent((YStationFeedbackType type, YStation station, YTrack? track, string batchId, double totalPlayedSeconds) tuple)
{
return new Dictionary<string, string> {
{ "type", tuple.station.Station.Id.Type },
{ "tag", tuple.station.Station.Id.Tag }
};
}
protected override HttpContent GetContent((YStationFeedbackType type, YStation station, YTrack track, string batchId, double totalPlayedSeconds) tuple)
{
long timestamp = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
JsonSerializerOptions settings = new()
{
Converters = {
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)
},
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
};
YStationFeedback feedBack = new()
var feedback = new YStationFeedback
{
Type = tuple.type,
From = tuple.station.Station.IdForFrom,
Timestamp = timestamp
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds()
};
if (tuple.track != null)
feedBack.TrackId = tuple.track.Id;
feedback.TrackId = tuple.track.Id;
if (tuple.totalPlayedSeconds > 0)
feedBack.TotalPlayedSeconds = tuple.totalPlayedSeconds;
feedback.TotalPlayedSeconds = tuple.totalPlayedSeconds;
return JsonContent.Create(feedBack, new MediaTypeHeaderValue("application/json"), settings); ;
}
protected override NameValueCollection GetQueryParams((YStationFeedbackType type, YStation station, YTrack track, string batchId, double totalPlayedSeconds) tuple)
{
NameValueCollection query = new();
if (!string.IsNullOrWhiteSpace(tuple.batchId))
query.Add("batch-id", tuple.batchId);
return query;
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
};
return JsonContent.Create(feedback, new MediaTypeHeaderValue("application/json"), options);
}
}