1
0
mirror of https://github.com/ultrasonic/ultrasonic synced 2025-02-11 17:20:39 +01:00

Add getArtist request.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-08-20 19:43:56 +02:00
parent c27bed2422
commit f4680ffeac
6 changed files with 123 additions and 1 deletions

View File

@ -0,0 +1,54 @@
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.Album
/**
* Integration test for [SubsonicAPIClient] for getArtist call.
*/
class SubsonicApiGetArtistTest : SubsonicAPIClientTest() {
@Test
fun `Should parse error call`() {
checkErrorCallParsed(mockWebServerRule, {
client.api.getArtist(101L).execute()
})
}
@Test
fun `Should pass id param in request`() {
val id = 929L
mockWebServerRule.enqueueResponse("get_artist_ok.json")
client.api.getArtist(id).execute()
val request = mockWebServerRule.mockWebServer.takeRequest()
request.requestLine `should contain` "id=$id"
}
@Test
fun `Should parse ok response`() {
mockWebServerRule.enqueueResponse("get_artist_ok.json")
val response = client.api.getArtist(100L).execute()
assertResponseSuccessful(response)
with(response.body().artist) {
id `should equal to` 362L
name `should equal to` "AC/DC"
coverArt `should equal to` "ar-362"
albumCount `should equal to` 2
albumsList.size `should equal to` 2
albumsList[0] `should equal` Album(id = 618L, name = "Black Ice", artist = "AC/DC",
artistId = 362L, coverArt = "al-618", songCount = 15, duration = 3331,
created = parseDate("2016-10-23T15:31:22.000Z"),
year = 2008, genre = "Hard Rock")
albumsList[1] `should equal` Album(id = 617L, name = "Rock or Bust", artist = "AC/DC",
artistId = 362L, coverArt = "al-617", songCount = 11, duration = 2095,
created = parseDate("2016-10-23T15:31:23.000Z"),
year = 2014, genre = "Hard Rock")
}
}
}

View File

@ -0,0 +1,35 @@
{
"subsonic-response" : {
"status" : "ok",
"version" : "1.15.0",
"artist" : {
"id" : "362",
"name" : "AC/DC",
"coverArt" : "ar-362",
"albumCount" : 2,
"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"
}, {
"id" : "617",
"name" : "Rock or Bust",
"artist" : "AC/DC",
"artistId" : "362",
"coverArt" : "al-617",
"songCount" : 11,
"duration" : 2095,
"created" : "2016-10-23T15:31:23.000Z",
"year" : 2014,
"genre" : "Hard Rock"
} ]
}
}
}

View File

@ -1,5 +1,6 @@
package org.moire.ultrasonic.api.subsonic
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse
import org.moire.ultrasonic.api.subsonic.response.GetArtistsResponse
import org.moire.ultrasonic.api.subsonic.response.GetIndexesResponse
import org.moire.ultrasonic.api.subsonic.response.GetMusicDirectoryResponse
@ -44,4 +45,7 @@ interface SubsonicAPIDefinition {
fun unstar(@Query("id") id: Long? = null,
@Query("albumId") albumId: Long? = null,
@Query("artistId") artistId: Long? = null): Call<SubsonicResponse>
@GET("getArtist.view")
fun getArtist(@Query("id") id: Long): Call<GetArtistResponse>
}

View File

@ -0,0 +1,15 @@
package org.moire.ultrasonic.api.subsonic.models
import java.util.Calendar
data class Album(
val id: Long = -1L,
val name: String = "",
val coverArt: String = "",
val artist: String = "",
val artistId: Long = -1L,
val songCount: Int = 0,
val duration: Int = 0,
val created: Calendar? = null,
val year: Int = 0,
val genre: String = "")

View File

@ -1,9 +1,12 @@
package org.moire.ultrasonic.api.subsonic.models
import com.fasterxml.jackson.annotation.JsonProperty
import java.util.Calendar
data class Artist(val id: Long = -1,
val name: String = "",
val coverArt: String = "",
val albumCount: Int = 0,
val starred: Calendar? = null)
val starred: Calendar? = null,
@JsonProperty("album")
val albumsList: List<Album> = emptyList())

View File

@ -0,0 +1,11 @@
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.Artist
class GetArtistResponse(status: Status,
version: SubsonicAPIVersions,
error: SubsonicError?,
val artist: Artist = Artist())
: SubsonicResponse(status, version, error)