Skip to content

Commit

Permalink
Queue API (#14)
Browse files Browse the repository at this point in the history
* gitignore: .idea

* Queue API

* Queue API Tests

* Queue Client Tests

* Yandex.Music.Api README.md Updated

* Fix tests

* Remove Console.WriteLine for debugging

* Remove GetStringContent in favor of GetContent
  • Loading branch information
shuryak committed Jan 16, 2023
1 parent a4da66e commit 2337a3e
Show file tree
Hide file tree
Showing 24 changed files with 552 additions and 13 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
################################################################################
# Данный GITIGNORE-файл был автоматически создан Microsoft(R) Visual Studio.
################################################################################

.vs
.vs
.vscode
/docs/build
bin
obj
/output

.idea

/src/Yandex.Music.Api.Tests/appsettings.json
/src/Yandex.Music.Client.Tests/appsettings.json
/src/Yandex.Music.Api.sln.DotSettings.user
/src/Yandex.Music.Api/Yandex.Music.Api.csproj.user
src/Yandex.Music.Api/Yandex.Music.Api.csproj.user
78 changes: 78 additions & 0 deletions src/Yandex.Music.Api.Tests/Tests/API/QueueAPITest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections.Generic;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
using Xunit.Extensions.Ordering;
using Yandex.Music.Api.Models.Common;
using Yandex.Music.Api.Models.Queue;
using Yandex.Music.Api.Tests.Traits;

namespace Yandex.Music.Api.Tests.Tests.API
{
[Collection("Yandex Test Harness"), Order(9)]
[TestBeforeAfter]
public class QueueAPITest : YandexTest
{
[Fact, YandexTrait(TraitGroup.QueueAPI)]
[Order(0)]
public void Create_ValidData_True()
{
YResponse<YNewQueue> newQueue = Fixture.API.Queue.Create(Fixture.Storage, new YQueue
{
Context = new YContext
{
Description = "Сироп",
Id = "track:819992702",
Type = "radio"
},
Tracks = new List<YTrackId>
{
new()
{
TrackId = "109253661",
AlbumId = "24174855",
From = "desktop_win-radio-radio_track_81999270-default"
}
},
CurrentIndex = null,
From = "desktop_win-radio-radio_track_81999270-default",
IsInteractive = true
});

Fixture.NewQueue = newQueue.Result;

Fixture.NewQueue.Id.Should().NotBeNullOrWhiteSpace();
}

[Fact, YandexTrait(TraitGroup.QueueAPI)]
[Order(1)]
public void Get_ValidData_True()
{
YResponse<YQueue> queue = Fixture.API.Queue.Get(Fixture.Storage, Fixture.NewQueue.Id);

queue.Result.Id.Should().NotBeNullOrWhiteSpace();
}

[Fact, YandexTrait(TraitGroup.QueueAPI)]
[Order(2)]
public void List_ValidData_True()
{
YResponse<YQueueItemsContainer> queueItemsContainer = Fixture.API.Queue.List(Fixture.Storage);

queueItemsContainer.Result.Queues.Count.Should().BeGreaterThan(0);
}

[Fact, YandexTrait(TraitGroup.QueueAPI)]
[Order(3)]
public void UpdatePosition_ValidData_True()
{
YResponse<YUpdatedQueue> updatedQueue = Fixture.API.Queue.UpdatePosition(Fixture.Storage, Fixture.NewQueue.Id, 0, true);

updatedQueue.Result.Status.Should().Be("ok");
}

public QueueAPITest(YandexTestHarness fixture, ITestOutputHelper output) : base(fixture, output)
{
}
}
}
5 changes: 3 additions & 2 deletions src/Yandex.Music.Api.Tests/Traits/TraitGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum TraitGroup
RadioAPI,
SearchAPI,
TrackAPI,
UserAPI
UserAPI,
QueueAPI
}
}
}
5 changes: 4 additions & 1 deletion src/Yandex.Music.Api.Tests/YandexTestHarness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Yandex.Music.Api.Models.Artist;
using Yandex.Music.Api.Models.Common;
using Yandex.Music.Api.Models.Playlist;
using Yandex.Music.Api.Models.Queue;
using Yandex.Music.Api.Models.Radio;
using Yandex.Music.Api.Models.Track;

Expand Down Expand Up @@ -63,11 +64,13 @@ private AppSettings GetAppSettings()
public YTrack Track { get; set; }

public YPlaylist CreatedPlaylist { get; set; }

public YNewQueue NewQueue { get; set; }

public YResponse<List<YStation>> Station {get; set; }

#endregion Поля для сохранения тестовых данных

#endregion Свойства
}
}
}
11 changes: 10 additions & 1 deletion src/Yandex.Music.Api.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=EnumMember/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/AutoDetectedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpAutoNaming/IsNamingAutoDetectionCompleted/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=2cb47fd7_002Df6d9_002D4d57_002Db033_002D8deb9d4b56cf/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Get_ValidData_True" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=2cb47fd7_002Df6d9_002D4d57_002Db033_002D8deb9d4b56cf/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Get_ValidData_True" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Solution /&gt;&#xD;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=903e74f7_002Dea8e_002D4324_002Dbdb1_002D205b85d16768/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Get_ValidData_True #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;xUnit::ED0FC303-CFCC-424B-B62E-0DD427794AD6::net5.0::Yandex.Music.Client.Tests.Tests.PlaylistTest.Get_ValidData_True&lt;/TestId&gt;&#xD;
&lt;TestId&gt;xUnit::ED0FC303-CFCC-424B-B62E-0DD427794AD6::net5.0::Yandex.Music.Client.Tests.Tests.QueueTest.CreateQueue_ValidData_True&lt;/TestId&gt;&#xD;
&lt;TestId&gt;xUnit::ED0FC303-CFCC-424B-B62E-0DD427794AD6::net5.0::Yandex.Music.Client.Tests.Tests.PlaylistTest.Premiere_ValidData_True&lt;/TestId&gt;&#xD;
&lt;TestId&gt;xUnit::ED0FC303-CFCC-424B-B62E-0DD427794AD6::net5.0::Yandex.Music.Client.Tests.Tests.PlaylistTest&lt;/TestId&gt;&#xD;
&lt;TestId&gt;xUnit::ED0FC303-CFCC-424B-B62E-0DD427794AD6::net5.0::Yandex.Music.Client.Tests.Tests.QueueTest&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
121 changes: 121 additions & 0 deletions src/Yandex.Music.Api/API/YQueueAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Yandex.Music.Api.Common;
using Yandex.Music.Api.Models.Common;
using Yandex.Music.Api.Models.Queue;
using Yandex.Music.Api.Requests.Queue;

namespace Yandex.Music.Api.API
{
/// <summary>
/// API для взаимодействия с очередями
/// </summary>
public class YQueueAPI : YCommonAPI
{
public YQueueAPI(YandexMusicApi yandex) : base(yandex)
{
}

/// <summary>
/// Получение всех очередей треков с разных устройств для синхронизации между ними
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="device">Устройство</param>
/// <returns></returns>
public Task<YResponse<YQueueItemsContainer>> ListAsync(AuthStorage storage, string device = null)
{
return new YQueuesListBuilder(api, storage)
.Build(device)
.GetResponseAsync();
}

/// <summary>
/// Получение всех очередей треков с разных устройств для синхронизации между ними
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="device">Устройство</param>
/// <returns></returns>
public YResponse<YQueueItemsContainer> List(AuthStorage storage, string device = null)
{
return ListAsync(storage, device).GetAwaiter().GetResult();
}

/// <summary>
/// Получение очереди
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="queueId">Идентификатор очереди</param>
/// <returns></returns>
public Task<YResponse<YQueue>> GetAsync(AuthStorage storage, string queueId)
{
return new YGetQueueBuilder(api, storage)
.Build(queueId)
.GetResponseAsync();
}

/// <summary>
/// Получение очереди
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="queueId">Идентификатор очереди</param>
/// <returns></returns>
public YResponse<YQueue> Get(AuthStorage storage, string queueId)
{
return GetAsync(storage, queueId).GetAwaiter().GetResult();
}

/// <summary>
/// Создание новой очереди треков
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="queue">Очередь треков</param>
/// <param name="device">Устройство</param>
/// <returns></returns>
public Task<YResponse<YNewQueue>> CreateAsync(AuthStorage storage, YQueue queue, string device = null)
{
return new YQueueCreateBuilder(api, storage, device)
.Build(queue)
.GetResponseAsync();
}

/// <summary>
/// Создание новой очереди треков
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="queue">Очередь треков</param>
/// <param name="device">Устройство</param>
/// <returns></returns>
public YResponse<YNewQueue> Create(AuthStorage storage, YQueue queue, string device = null)
{
return CreateAsync(storage, queue, device).GetAwaiter().GetResult();
}

/// <summary>
/// Установка текущего индекса проигрываемого трека в очереди треков.
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="queueId">Идентификатор очереди</param>
/// <param name="currentIndex">Текущий индекс</param>
/// <param name="device">Устройство</param>
/// <returns></returns>
public Task<YResponse<YUpdatedQueue>> UpdatePositionAsync(AuthStorage storage, string queueId, int currentIndex, bool isInteractive, string device = null)
{
return new YQueueUpdatePositionBuilder(api, storage, device)
.Build((queueId, currentIndex, isInteractive))
.GetResponseAsync();
}

/// <summary>
/// Установка текущего индекса проигрываемого трека в очереди треков.
/// </summary>
/// <param name="storage">Хранилище</param>
/// <param name="queueId">Идентификатор очереди</param>
/// <param name="currentIndex">Текущий индекс</param>
/// <param name="device">Устройство</param>
/// <returns></returns>
public YResponse<YUpdatedQueue> UpdatePosition(AuthStorage storage, string queueId, int currentIndex, bool isInteractive, string device = null)
{
return UpdatePositionAsync(storage, queueId, currentIndex, isInteractive, device).GetAwaiter().GetResult();
}
}
}
9 changes: 9 additions & 0 deletions src/Yandex.Music.Api/Models/Common/YTrackId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Yandex.Music.Api.Models.Common
{
public class YTrackId
{
public string TrackId { get; set; }
public string AlbumId { get; set; }
public string From { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Yandex.Music.Api/Models/Queue/YContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Yandex.Music.Api.Models.Queue
{
public class YContext
{
public string Type { get; set; }
public string Id { get; set; }
public string Description { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Yandex.Music.Api/Models/Queue/YNewQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Yandex.Music.Api.Models.Common;

namespace Yandex.Music.Api.Models.Queue
{
public class YNewQueue : YId
{
public string Modified { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Yandex.Music.Api/Models/Queue/YQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using Yandex.Music.Api.Models.Common;

namespace Yandex.Music.Api.Models.Queue
{
public class YQueue
{
public string Id { get; set; }
public YContext Context { get; set; }
public List<YTrackId> Tracks { get; set; }
public int? CurrentIndex { get; set; }
public string Modified { get; set; }
public string From { get; set; }
public bool IsInteractive { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/Yandex.Music.Api/Models/Queue/YQueueItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Yandex.Music.Api.Models.Queue
{
public class YQueueItem
{
public string Id { get; set; }
public YContext Context { get; set; }
public YContext InitialContext { get; set; }
public string Modified { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Yandex.Music.Api/Models/Queue/YQueueItemsContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Yandex.Music.Api.Models.Queue
{
public class YQueueItemsContainer
{
public List<YQueueItem> Queues { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/Yandex.Music.Api/Models/Queue/YUpdatedQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Yandex.Music.Api.Models.Queue
{
public class YUpdatedQueue
{
public string Status { get; set; }
public bool MostRecentQueue { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Yandex.Music.Api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ YandexMusicApi
│   ├── GetStation / Async (AuthStorage storage, YStationId id)
│   ├── GetStationTracks / Async (AuthStorage storage, YStation station, string prevTrackId = "")
│   └── SetStationSettings2 / Async (AuthStorage storage, YStation station, YStationSettings2 settings)
├── Queue
│   ├── List / Async (AuthStorage storage, string device = null)
│   ├── Get / Async (AuthStorage storage, string queueId)
│   ├── Create / Async (AuthStorage storage, YQueue queue, string device = null)
│   └── UpdatePosition / Async (AuthStorage storage, string queueId, int currentIndex, bool isInteractive, string device = null)
└── Future
   ...
```
Expand Down
3 changes: 2 additions & 1 deletion src/Yandex.Music.Api/Requests/Common/YRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class YRequestBuilder<ResponseType, ParamsTuple>

protected YandexMusicApi api;
protected AuthStorage storage;
protected string Device = "os=CSharp; os_version=; manufacturer=Marshal; model=Yandex Music API; clid=; device_id=random; uuid=random";

#endregion Поля

Expand Down Expand Up @@ -155,4 +156,4 @@ internal YRequest<ResponseType> Build(ParamsTuple tuple)

#endregion Основные функции
}
}
}

0 comments on commit 2337a3e

Please sign in to comment.