mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-18 04:30:48 +01:00
Merge pull request #28 from ultrasonic/add-unstar-request
#9: Add unstar request
This commit is contained in:
commit
decf680076
@ -0,0 +1,61 @@
|
||||
package org.moire.ultrasonic.api.subsonic
|
||||
|
||||
import org.amshove.kluent.`should be`
|
||||
import org.amshove.kluent.`should contain`
|
||||
import org.junit.Test
|
||||
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse
|
||||
|
||||
/**
|
||||
* Intergration test for [SubsonicAPIClient] for unstar call.
|
||||
*/
|
||||
class SubsonicApiUnstarTest : SubsonicAPIClientTest() {
|
||||
@Test
|
||||
fun `Should parse ok response`() {
|
||||
mockWebServerRule.enqueueResponse("ping_ok.json")
|
||||
|
||||
val response = client.api.unstar().execute()
|
||||
|
||||
assertResponseSuccessful(response)
|
||||
response.body().status `should be` SubsonicResponse.Status.OK
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should parse error response`() {
|
||||
checkErrorCallParsed(mockWebServerRule, {
|
||||
client.api.unstar().execute()
|
||||
})
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass id param`() {
|
||||
mockWebServerRule.enqueueResponse("ping_ok.json")
|
||||
val id = 545L
|
||||
client.api.unstar(id = id).execute()
|
||||
|
||||
val request = mockWebServerRule.mockWebServer.takeRequest()
|
||||
|
||||
request.requestLine `should contain` "id=$id"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass artistId param`() {
|
||||
mockWebServerRule.enqueueResponse("ping_ok.json")
|
||||
val artistId = 644L
|
||||
client.api.unstar(artistId = artistId).execute()
|
||||
|
||||
val request = mockWebServerRule.mockWebServer.takeRequest()
|
||||
|
||||
request.requestLine `should contain` "artistId=$artistId"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass albumId param`() {
|
||||
mockWebServerRule.enqueueResponse("ping_ok.json")
|
||||
val albumId = 3344L
|
||||
client.api.unstar(albumId = albumId).execute()
|
||||
|
||||
val request = mockWebServerRule.mockWebServer.takeRequest()
|
||||
|
||||
request.requestLine `should contain` "albumId=$albumId"
|
||||
}
|
||||
}
|
@ -39,4 +39,9 @@ interface SubsonicAPIDefinition {
|
||||
fun star(@Query("id") id: Long? = null,
|
||||
@Query("albumId") albumId: Long? = null,
|
||||
@Query("artistId") artistId: Long? = null): Call<SubsonicResponse>
|
||||
|
||||
@GET("unstar.view")
|
||||
fun unstar(@Query("id") id: Long? = null,
|
||||
@Query("albumId") albumId: Long? = null,
|
||||
@Query("artistId") artistId: Long? = null): Call<SubsonicResponse>
|
||||
}
|
||||
|
@ -334,43 +334,21 @@ public class RESTMusicService implements MusicService
|
||||
checkResponseSuccessful(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unstar(String id, String albumId, String artistId, Context context, ProgressListener progressListener) throws Exception
|
||||
{
|
||||
checkServerVersion(context, "1.8", "Unstarring not supported.");
|
||||
@Override
|
||||
public void unstar(String id,
|
||||
String albumId,
|
||||
String artistId,
|
||||
Context context,
|
||||
ProgressListener progressListener) throws Exception {
|
||||
Long apiId = id == null ? null : Long.valueOf(id);
|
||||
Long apiAlbumId = albumId == null ? null : Long.valueOf(albumId);
|
||||
Long apiArtistId = artistId == null ? null : Long.valueOf(artistId);
|
||||
|
||||
List<String> parameterNames = new LinkedList<String>();
|
||||
List<Object> parameterValues = new LinkedList<Object>();
|
||||
|
||||
if (id != null)
|
||||
{
|
||||
parameterNames.add("id");
|
||||
parameterValues.add(id);
|
||||
}
|
||||
|
||||
if (albumId != null)
|
||||
{
|
||||
parameterNames.add("albumId");
|
||||
parameterValues.add(albumId);
|
||||
}
|
||||
|
||||
if (artistId != null)
|
||||
{
|
||||
parameterNames.add("artistId");
|
||||
parameterValues.add(artistId);
|
||||
}
|
||||
|
||||
|
||||
Reader reader = getReader(context, progressListener, "unstar", null, parameterNames, parameterValues);
|
||||
try
|
||||
{
|
||||
new ErrorParser(context).parse(reader);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Util.close(reader);
|
||||
}
|
||||
}
|
||||
updateProgressListener(progressListener, R.string.parser_reading);
|
||||
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
|
||||
.unstar(apiId, apiAlbumId, apiArtistId).execute();
|
||||
checkResponseSuccessful(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MusicDirectory getMusicDirectory(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception
|
||||
|
Loading…
x
Reference in New Issue
Block a user