mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-16 01:10:36 +03:00
Add getChatMessages() call.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
f1639bab48
commit
9cecebb314
@ -0,0 +1,45 @@
|
||||
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.ChatMessage
|
||||
|
||||
/**
|
||||
* Integration test for [SubsonicAPIDefinition.getChatMessages] call.
|
||||
*/
|
||||
class SubsonicApiGetChatMessagesTest : SubsonicAPIClientTest() {
|
||||
@Test
|
||||
fun `Should handle error response`() {
|
||||
val response = checkErrorCallParsed(mockWebServerRule) {
|
||||
client.api.getChatMessages().execute()
|
||||
}
|
||||
|
||||
response.chatMessages `should equal` emptyList()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should handle ok response`() {
|
||||
mockWebServerRule.enqueueResponse("get_chat_messages_ok.json")
|
||||
|
||||
val response = client.api.getChatMessages().execute()
|
||||
|
||||
assertResponseSuccessful(response)
|
||||
with(response.body().chatMessages) {
|
||||
size `should equal to` 2
|
||||
this[0] `should equal` ChatMessage(username = "sindre", time = 1269771845310,
|
||||
message = "Sindre was here")
|
||||
this[1] `should equal` ChatMessage(username = "ben", time = 1269771842504,
|
||||
message = "Ben too")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass since in request param`() {
|
||||
val since = 21388L
|
||||
|
||||
mockWebServerRule.assertRequestParam(expectedParam = "since=$since") {
|
||||
client.api.getChatMessages(since = since).execute()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"subsonic-response" : {
|
||||
"status" : "ok",
|
||||
"version" : "1.15.0",
|
||||
"chatMessages" : {
|
||||
"chatMessage" : [ {
|
||||
"username" : "sindre",
|
||||
"time" : 1269771845310,
|
||||
"message" : "Sindre was here"
|
||||
}, {
|
||||
"username" : "ben",
|
||||
"time" : 1269771842504,
|
||||
"message" : "Ben too"
|
||||
} ]
|
||||
}
|
||||
}
|
||||
}
|
@ -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.ChatMessagesResponse
|
||||
import org.moire.ultrasonic.api.subsonic.response.GenresResponse
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumList2Response
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse
|
||||
@ -212,6 +213,8 @@ interface SubsonicAPIDefinition {
|
||||
@Query("musicFolderId") musicFolderId: Long? = null): Call<GetSongsByGenreResponse>
|
||||
|
||||
@GET("getUser.view")
|
||||
fun getUser(
|
||||
@Query("username") username: String): Call<GetUserResponse>
|
||||
fun getUser(@Query("username") username: String): Call<GetUserResponse>
|
||||
|
||||
@GET("getChatMessages.view")
|
||||
fun getChatMessages(@Query("since") since: Long? = null): Call<ChatMessagesResponse>
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package org.moire.ultrasonic.api.subsonic.models
|
||||
|
||||
data class ChatMessage(
|
||||
val username: String = "",
|
||||
val time: Long = 0,
|
||||
val message: String = "")
|
@ -0,0 +1,18 @@
|
||||
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.ChatMessage
|
||||
|
||||
class ChatMessagesResponse(
|
||||
status: Status,
|
||||
version: SubsonicAPIVersions,
|
||||
error: SubsonicError?) : SubsonicResponse(status, version, error) {
|
||||
@JsonProperty("chatMessages") private val wrapper = ChatMessagesWrapper()
|
||||
|
||||
val chatMessages: List<ChatMessage> get() = wrapper.messagesList
|
||||
}
|
||||
|
||||
internal class ChatMessagesWrapper(
|
||||
@JsonProperty("chatMessage") val messagesList: List<ChatMessage> = emptyList())
|
Loading…
x
Reference in New Issue
Block a user