commit
a5d7e47dfa
|
@ -0,0 +1,55 @@
|
|||
package org.moire.ultrasonic.api.subsonic
|
||||
|
||||
import org.junit.Test
|
||||
import java.util.Calendar
|
||||
|
||||
/**
|
||||
* Integration test for [SubsonicAPIClient] for scrobble call.
|
||||
*/
|
||||
class SubsonicApiScrobbleTest : SubsonicAPIClientTest() {
|
||||
@Test
|
||||
fun `Should handle error response`() {
|
||||
checkErrorCallParsed(mockWebServerRule) {
|
||||
client.api.scrobble("id").execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should handle ok response`() {
|
||||
mockWebServerRule.enqueueResponse("ping_ok.json")
|
||||
|
||||
val response = client.api.scrobble("id").execute()
|
||||
|
||||
assertResponseSuccessful(response)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass id param in request`() {
|
||||
val id = "some-id"
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json",
|
||||
expectedParam = "id=$id") {
|
||||
client.api.scrobble(id = id).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass time param in request`() {
|
||||
val time = Calendar.getInstance().timeInMillis
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json",
|
||||
expectedParam = "time=$time") {
|
||||
client.api.scrobble(id = "some-id", time = time).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass submission param in request`() {
|
||||
val submission = false
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json",
|
||||
expectedParam = "submission=$submission") {
|
||||
client.api.scrobble(id = "some-id", submission = submission).execute()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -118,4 +118,9 @@ interface SubsonicAPIDefinition {
|
|||
@GET("getLyrics.view")
|
||||
fun getLyrics(@Query("artist") artist: String? = null,
|
||||
@Query("title") title: String? = null): Call<GetLyricsResponse>
|
||||
|
||||
@GET("scrobble.view")
|
||||
fun scrobble(@Query("id") id: String,
|
||||
@Query("time") time: Long? = null,
|
||||
@Query("submission") submission: Boolean? = null): Call<SubsonicResponse>
|
||||
}
|
||||
|
|
|
@ -638,21 +638,20 @@ public class RESTMusicService implements MusicService
|
|||
return APILyricsConverter.toDomainEntity(response.body().getLyrics());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrobble(String id, boolean submission, Context context, ProgressListener progressListener) throws Exception
|
||||
{
|
||||
checkServerVersion(context, "1.5", "Scrobbling not supported.");
|
||||
@Override
|
||||
public void scrobble(String id,
|
||||
boolean submission,
|
||||
Context context,
|
||||
ProgressListener progressListener) throws Exception {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("Scrobble id is null");
|
||||
}
|
||||
|
||||
Reader reader = getReader(context, progressListener, "scrobble", null, asList("id", "submission"), Arrays.<Object>asList(id, submission));
|
||||
try
|
||||
{
|
||||
new ErrorParser(context).parse(reader);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Util.close(reader);
|
||||
}
|
||||
}
|
||||
updateProgressListener(progressListener, R.string.parser_reading);
|
||||
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
|
||||
.scrobble(id, null, submission).execute();
|
||||
checkResponseSuccessful(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MusicDirectory getAlbumList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception
|
||||
|
|
Loading…
Reference in New Issue