Merge pull request #69 from ultrasonic/add-chat-message
Add chat message
This commit is contained in:
commit
b4e18f9bfb
|
@ -0,0 +1,33 @@
|
||||||
|
package org.moire.ultrasonic.api.subsonic
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration test for [SubsonicAPIDefinition.addChatMessage] call.
|
||||||
|
*/
|
||||||
|
class SubsonicApiAddChatMessageTest : SubsonicAPIClientTest() {
|
||||||
|
@Test
|
||||||
|
fun `Should handle error response`() {
|
||||||
|
checkErrorCallParsed(mockWebServerRule) {
|
||||||
|
client.api.addChatMessage("some").execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should handle ok response`() {
|
||||||
|
mockWebServerRule.enqueueResponse("ping_ok.json")
|
||||||
|
|
||||||
|
val response = client.api.addChatMessage("some").execute()
|
||||||
|
|
||||||
|
assertResponseSuccessful(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass message in request param`() {
|
||||||
|
val message = "Youuhuuu"
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(expectedParam = "message=$message") {
|
||||||
|
client.api.addChatMessage(message = message).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -217,4 +217,7 @@ interface SubsonicAPIDefinition {
|
||||||
|
|
||||||
@GET("getChatMessages.view")
|
@GET("getChatMessages.view")
|
||||||
fun getChatMessages(@Query("since") since: Long? = null): Call<ChatMessagesResponse>
|
fun getChatMessages(@Query("since") since: Long? = null): Call<ChatMessagesResponse>
|
||||||
|
|
||||||
|
@GET("addChatMessage.view")
|
||||||
|
fun addChatMessage(@Query("message") message: String): Call<SubsonicResponse>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1259,29 +1259,17 @@ public class RESTMusicService implements MusicService
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addChatMessage(String message, Context context, ProgressListener progressListener) throws Exception
|
public void addChatMessage(String message,
|
||||||
{
|
Context context,
|
||||||
checkServerVersion(context, "1.2", "Chat not supported.");
|
ProgressListener progressListener) throws Exception {
|
||||||
|
if (message == null) {
|
||||||
HttpParams params = new BasicHttpParams();
|
throw new IllegalArgumentException("Message is null");
|
||||||
HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS);
|
|
||||||
|
|
||||||
List<String> parameterNames = new ArrayList<String>();
|
|
||||||
List<Object> parameterValues = new ArrayList<Object>();
|
|
||||||
|
|
||||||
parameterNames.add("message");
|
|
||||||
parameterValues.add(message);
|
|
||||||
|
|
||||||
Reader reader = getReader(context, progressListener, "addChatMessage", params, parameterNames, parameterValues);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
new ErrorParser(context).parse(reader);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Util.close(reader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateProgressListener(progressListener, R.string.parser_reading);
|
||||||
|
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
|
||||||
|
.addChatMessage(message).execute();
|
||||||
|
checkResponseSuccessful(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue