From 687ecb82574d54fa646ff9f011f346c0c940a436 Mon Sep 17 00:00:00 2001 From: Steve Soltys Date: Wed, 14 Dec 2022 02:29:50 -0500 Subject: [PATCH] Add support for fetching multiple albums by identifier --- .../com/stevesoltys/applemusic/AppleMusic.kt | 9 +++++++++ .../stevesoltys/applemusic/AppleMusicE2ETest.kt | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/stevesoltys/applemusic/AppleMusic.kt b/src/main/kotlin/com/stevesoltys/applemusic/AppleMusic.kt index a4019ca..f728ef5 100644 --- a/src/main/kotlin/com/stevesoltys/applemusic/AppleMusic.kt +++ b/src/main/kotlin/com/stevesoltys/applemusic/AppleMusic.kt @@ -114,6 +114,15 @@ class AppleMusic( return call(appleMusicService.getAlbumById(id, include?.toTypedArray())) } + /** + * Get a set of albums by their identifiers. + */ + fun getAlbumsById( + ids: Array + ): AlbumResponse { + return call(appleMusicService.getAlbumsById(ids)) + } + /** * Get albums for a given artist. */ diff --git a/src/test/kotlin/com/stevesoltys/applemusic/AppleMusicE2ETest.kt b/src/test/kotlin/com/stevesoltys/applemusic/AppleMusicE2ETest.kt index 81d30bf..2200385 100644 --- a/src/test/kotlin/com/stevesoltys/applemusic/AppleMusicE2ETest.kt +++ b/src/test/kotlin/com/stevesoltys/applemusic/AppleMusicE2ETest.kt @@ -29,6 +29,8 @@ class AppleMusicE2ETest { private const val TEST_ALBUM_IDENTIFIER = "259814641" private const val TEST_ALBUM_NAME = "An Innocent Man" + + private const val TEST_ALBUM_IDENTIFIER_2 = "1440903530" } private lateinit var appleMusic: AppleMusic @@ -65,13 +67,26 @@ class AppleMusicE2ETest { } @Test - fun `can get artist albums by identifier`() { + fun `can get a single album by identifier`() { val result = appleMusic.getAllAlbumsByArtistId(TEST_ARTIST_IDENTIFIER) val albums = result.data albums.shouldNotBeNull().shouldNotBeEmpty() } + @Test + fun `can get multiple albums by their identifiers`() { + val result = appleMusic.getAlbumsById( + arrayOf(TEST_ALBUM_IDENTIFIER, TEST_ALBUM_IDENTIFIER_2) + ) + + val albums = result.data + albums.shouldNotBeNull().shouldNotBeEmpty() + + albums.first().attributes?.artistName.shouldNotBeNull() + albums.first().relationships?.artists?.data.shouldNotBeNull().shouldHaveSize(1) + } + @Test fun `can get album by identifier`() { val result = appleMusic.getAlbumById(TEST_ALBUM_IDENTIFIER)