Add getAlbum api call.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-08-20 22:04:41 +02:00
parent 1ede4f73c8
commit 6c0f43b2ff
5 changed files with 462 additions and 1 deletions

View File

@ -0,0 +1,66 @@
package org.moire.ultrasonic.api.subsonic
import org.amshove.kluent.`should contain`
import org.amshove.kluent.`should equal to`
import org.amshove.kluent.`should equal`
import org.junit.Test
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
/**
* Integration test for [SubsonicAPIClient] for getAlbum call.
*/
class SubsonicApiGetAlbumTest : SubsonicAPIClientTest() {
@Test
fun `Should parse error responce`() {
checkErrorCallParsed(mockWebServerRule, {
client.api.getAlbum(56L).execute()
})
}
@Test
fun `Should add id to request params`() {
mockWebServerRule.enqueueResponse("get_album_ok.json")
val id = 76L
client.api.getAlbum(id).execute()
val request = mockWebServerRule.mockWebServer.takeRequest()
request.requestLine `should contain` "id=$id"
}
@Test
fun `Should parse ok response`() {
mockWebServerRule.enqueueResponse("get_album_ok.json")
val response = client.api.getAlbum(512L).execute()
assertResponseSuccessful(response)
with(response.body().album) {
id `should equal to` 618L
name `should equal to` "Black Ice"
artist `should equal to` "AC/DC"
artistId `should equal to` 362L
coverArt `should equal to` "al-618"
songCount `should equal to` 15
duration `should equal to` 3331
created `should equal` parseDate("2016-10-23T15:31:22.000Z")
year `should equal to` 2008
genre `should equal to` "Hard Rock"
songList.size `should equal to` 15
songList[0] `should equal` MusicDirectoryChild(id = 6491L, parent = 6475L, isDir = false,
title = "Rock 'n' Roll Train", album = "Black Ice", artist = "AC/DC",
track = 1, year = 2008, genre = "Hard Rock", coverArt = "6475", size = 7205451,
contentType = "audio/mpeg", suffix = "mp3", duration = 261, bitRate = 219,
path = "AC_DC/Black Ice/01 Rock 'n' Roll Train.mp3", isVideo = false,
playCount = 0, discNumber = 1, created = parseDate("2016-10-23T15:31:20.000Z"),
albumId = 618L, artistId = 362L, type = "music")
songList[5] `should equal` MusicDirectoryChild(id = 6492L, parent = 6475L, isDir = false,
title = "Smash 'n' Grab", album = "Black Ice", artist = "AC/DC", track = 6,
year = 2008, genre = "Hard Rock", coverArt = "6475", size = 6697204,
contentType = "audio/mpeg", suffix = "mp3", duration = 246, bitRate = 216,
path = "AC_DC/Black Ice/06 Smash 'n' Grab.mp3", isVideo = false, playCount = 0,
discNumber = 1, created = parseDate("2016-10-23T15:31:20.000Z"),
albumId = 618L, artistId = 362L, type = "music")
}
}
}

View File

@ -0,0 +1,379 @@
{
"subsonic-response" : {
"status" : "ok",
"version" : "1.15.0",
"album" : {
"id" : "618",
"name" : "Black Ice",
"artist" : "AC/DC",
"artistId" : "362",
"coverArt" : "al-618",
"songCount" : 15,
"duration" : 3331,
"created" : "2016-10-23T15:31:22.000Z",
"year" : 2008,
"genre" : "Hard Rock",
"song" : [ {
"id" : "6491",
"parent" : "6475",
"isDir" : false,
"title" : "Rock 'n' Roll Train",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 1,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 7205451,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 261,
"bitRate" : 219,
"path" : "AC_DC/Black Ice/01 Rock 'n' Roll Train.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:20.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6500",
"parent" : "6475",
"isDir" : false,
"title" : "Skies on Fire",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 2,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 5634607,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 214,
"bitRate" : 209,
"path" : "AC_DC/Black Ice/02 Skies on Fire.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:22.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6496",
"parent" : "6475",
"isDir" : false,
"title" : "Big Jack",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 3,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 6274247,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 237,
"bitRate" : 211,
"path" : "AC_DC/Black Ice/03 Big Jack.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:22.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6488",
"parent" : "6475",
"isDir" : false,
"title" : "Anything Goes",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 4,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 5763074,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 202,
"bitRate" : 227,
"path" : "AC_DC/Black Ice/04 Anything Goes.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:20.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6501",
"parent" : "6475",
"isDir" : false,
"title" : "War Machine",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 5,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 4962101,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 189,
"bitRate" : 208,
"path" : "AC_DC/Black Ice/05 War Machine.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:20.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6492",
"parent" : "6475",
"isDir" : false,
"title" : "Smash 'n' Grab",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 6,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 6697204,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 246,
"bitRate" : 216,
"path" : "AC_DC/Black Ice/06 Smash 'n' Grab.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:20.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6499",
"parent" : "6475",
"isDir" : false,
"title" : "Spoilin' for a Fight",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 7,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 5481070,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 197,
"bitRate" : 222,
"path" : "AC_DC/Black Ice/07 Spoilin' for a Fight.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:21.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6487",
"parent" : "6475",
"isDir" : false,
"title" : "Wheels",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 8,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 5837241,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 208,
"bitRate" : 223,
"path" : "AC_DC/Black Ice/08 Wheels.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:22.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6495",
"parent" : "6475",
"isDir" : false,
"title" : "Decibel",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 9,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 5251982,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 213,
"bitRate" : 195,
"path" : "AC_DC/Black Ice/09 Decibel.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:19.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6494",
"parent" : "6475",
"isDir" : false,
"title" : "Stormy May Day",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 10,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 5105168,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 190,
"bitRate" : 214,
"path" : "AC_DC/Black Ice/10 Stormy May Day.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:20.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6493",
"parent" : "6475",
"isDir" : false,
"title" : "She Likes Rock 'n' Roll",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 11,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 6135766,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 232,
"bitRate" : 210,
"path" : "AC_DC/Black Ice/11 She Likes Rock 'n' Roll.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:22.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6497",
"parent" : "6475",
"isDir" : false,
"title" : "Money Made",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 12,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 6816386,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 255,
"bitRate" : 213,
"path" : "AC_DC/Black Ice/12 Money Made.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:21.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6489",
"parent" : "6475",
"isDir" : false,
"title" : "Rock 'n' Roll Dream",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 13,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 7486707,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 280,
"bitRate" : 212,
"path" : "AC_DC/Black Ice/13 Rock 'n' Roll Dream.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:20.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6498",
"parent" : "6475",
"isDir" : false,
"title" : "Rocking All the Way",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 14,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 4927026,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 202,
"bitRate" : 194,
"path" : "AC_DC/Black Ice/14 Rocking All the Way.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:22.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
}, {
"id" : "6490",
"parent" : "6475",
"isDir" : false,
"title" : "Black Ice",
"album" : "Black Ice",
"artist" : "AC/DC",
"track" : 15,
"year" : 2008,
"genre" : "Hard Rock",
"coverArt" : "6475",
"size" : 5192799,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 205,
"bitRate" : 202,
"path" : "AC_DC/Black Ice/15 Black Ice.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T15:31:22.000Z",
"albumId" : "618",
"artistId" : "362",
"type" : "music"
} ]
}
}
}

View File

@ -1,5 +1,6 @@
package org.moire.ultrasonic.api.subsonic package org.moire.ultrasonic.api.subsonic
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse
import org.moire.ultrasonic.api.subsonic.response.GetArtistsResponse import org.moire.ultrasonic.api.subsonic.response.GetArtistsResponse
import org.moire.ultrasonic.api.subsonic.response.GetIndexesResponse import org.moire.ultrasonic.api.subsonic.response.GetIndexesResponse
@ -48,4 +49,7 @@ interface SubsonicAPIDefinition {
@GET("getArtist.view") @GET("getArtist.view")
fun getArtist(@Query("id") id: Long): Call<GetArtistResponse> fun getArtist(@Query("id") id: Long): Call<GetArtistResponse>
@GET("getAlbum.view")
fun getAlbum(@Query("id") id: Long): Call<GetAlbumResponse>
} }

View File

@ -1,5 +1,6 @@
package org.moire.ultrasonic.api.subsonic.models package org.moire.ultrasonic.api.subsonic.models
import com.fasterxml.jackson.annotation.JsonProperty
import java.util.Calendar import java.util.Calendar
data class Album( data class Album(
@ -12,4 +13,5 @@ data class Album(
val duration: Int = 0, val duration: Int = 0,
val created: Calendar? = null, val created: Calendar? = null,
val year: Int = 0, val year: Int = 0,
val genre: String = "") val genre: String = "",
@JsonProperty("song") val songList: List<MusicDirectoryChild> = emptyList())

View File

@ -0,0 +1,10 @@
package org.moire.ultrasonic.api.subsonic.response
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
import org.moire.ultrasonic.api.subsonic.SubsonicError
import org.moire.ultrasonic.api.subsonic.models.Album
class GetAlbumResponse(status: Status,
version: SubsonicAPIVersions,
error: SubsonicError?,
val album: Album = Album()) : SubsonicResponse(status, version, error)