Skip to content

Commit

Permalink
Merge pull request #3 from stevesoltys/feature/albums-by-ids
Browse files Browse the repository at this point in the history
Add support for fetching multiple albums by identifier
  • Loading branch information
stevesoltys committed Dec 14, 2022
2 parents f5f4044 + 687ecb8 commit a946025
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/kotlin/com/stevesoltys/applemusic/AppleMusic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
): AlbumResponse {
return call(appleMusicService.getAlbumsById(ids))
}

/**
* Get albums for a given artist.
*/
Expand Down
17 changes: 16 additions & 1 deletion src/test/kotlin/com/stevesoltys/applemusic/AppleMusicE2ETest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a946025

Please sign in to comment.