mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-18 04:30:48 +01:00
Add getGenres app call.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
1907668c64
commit
1502c4c9c8
@ -0,0 +1,37 @@
|
||||
package org.moire.ultrasonic.api.subsonic
|
||||
|
||||
import org.amshove.kluent.`should equal to`
|
||||
import org.amshove.kluent.`should equal`
|
||||
import org.junit.Test
|
||||
import org.moire.ultrasonic.api.subsonic.models.Genre
|
||||
|
||||
/**
|
||||
* Integration test for [SubsonicAPIDefinition.getGenres] call.
|
||||
*/
|
||||
class SubsonicApiGetGenresTest : SubsonicAPIClientTest() {
|
||||
@Test
|
||||
fun `Should handle error response`() {
|
||||
val response = checkErrorCallParsed(mockWebServerRule) {
|
||||
client.api.getGenres().execute()
|
||||
}
|
||||
|
||||
response.genresList `should equal` emptyList()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should handle ok response`() {
|
||||
mockWebServerRule.enqueueResponse("get_genres_ok.json")
|
||||
|
||||
val response = client.api.getGenres().execute()
|
||||
|
||||
assertResponseSuccessful(response)
|
||||
with(response.body().genresList) {
|
||||
size `should equal to` 5
|
||||
this[0] `should equal` Genre(1186, 103, "Rock")
|
||||
this[1] `should equal` Genre(896, 72, "Electronic")
|
||||
this[2] `should equal` Genre(790, 59, "Alternative Rock")
|
||||
this[3] `should equal` Genre(622, 97, "Trance")
|
||||
this[4] `should equal` Genre(476, 36, "Hard Rock")
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
{
|
||||
"subsonic-response" : {
|
||||
"status" : "ok",
|
||||
"version" : "1.15.0",
|
||||
"genres" : {
|
||||
"genre" : [ {
|
||||
"songCount" : 1186,
|
||||
"albumCount" : 103,
|
||||
"value" : "Rock"
|
||||
}, {
|
||||
"songCount" : 896,
|
||||
"albumCount" : 72,
|
||||
"value" : "Electronic"
|
||||
}, {
|
||||
"songCount" : 790,
|
||||
"albumCount" : 59,
|
||||
"value" : "Alternative Rock"
|
||||
}, {
|
||||
"songCount" : 622,
|
||||
"albumCount" : 97,
|
||||
"value" : "Trance"
|
||||
}, {
|
||||
"songCount" : 476,
|
||||
"albumCount" : 36,
|
||||
"value" : "Hard Rock"
|
||||
} ]
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package org.moire.ultrasonic.api.subsonic
|
||||
import okhttp3.ResponseBody
|
||||
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
|
||||
import org.moire.ultrasonic.api.subsonic.models.JukeboxAction
|
||||
import org.moire.ultrasonic.api.subsonic.response.GenresResponse
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumList2Response
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse
|
||||
@ -197,4 +198,7 @@ interface SubsonicAPIDefinition {
|
||||
fun createShare(@Query("id") idsToShare: List<String>,
|
||||
@Query("description") description: String? = null,
|
||||
@Query("expires") expires: Long? = null): Call<SharesResponse>
|
||||
|
||||
@GET("getGenres.view")
|
||||
fun getGenres(): Call<GenresResponse>
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package org.moire.ultrasonic.api.subsonic.models
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
|
||||
data class Genre(val songCount: Int = 0,
|
||||
val albumCount: Int = 0,
|
||||
@JsonProperty("value") val name: String)
|
@ -0,0 +1,15 @@
|
||||
package org.moire.ultrasonic.api.subsonic.response
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError
|
||||
import org.moire.ultrasonic.api.subsonic.models.Genre
|
||||
|
||||
class GenresResponse(status: Status,
|
||||
version: SubsonicAPIVersions,
|
||||
error: SubsonicError?) : SubsonicResponse(status, version, error) {
|
||||
@JsonProperty("genres") private val genresWrapper = GenresWrapper()
|
||||
val genresList: List<Genre> get() = genresWrapper.genresList
|
||||
}
|
||||
|
||||
internal class GenresWrapper(@JsonProperty("genre") val genresList: List<Genre> = emptyList())
|
Loading…
x
Reference in New Issue
Block a user