Merge pull request #27 from ultrasonic/add-star-request

Add star request
This commit is contained in:
Yahor Berdnikau 2017-08-17 22:42:56 +02:00 committed by GitHub
commit 0563c39cdc
4 changed files with 82 additions and 36 deletions

View File

@ -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
/**
* Integration test for [SubsonicAPIClient] for star request.
*/
class SubsonicApiStarTest : SubsonicAPIClientTest() {
@Test
fun `Should parse star ok response`() {
mockWebServerRule.enqueueResponse("ping_ok.json")
val response = client.api.star().execute()
assertResponseSuccessful(response)
response.body().status `should be` SubsonicResponse.Status.OK
}
@Test
fun `Should parse star error response`() {
checkErrorCallParsed(mockWebServerRule, {
client.api.star().execute()
})
}
@Test
fun `Should pass id param`() {
mockWebServerRule.enqueueResponse("ping_ok.json")
val id = 110L
client.api.star(id = id).execute()
val request = mockWebServerRule.mockWebServer.takeRequest()
request.requestLine `should contain` "id=$id"
}
@Test
fun `Should pass artist id param`() {
mockWebServerRule.enqueueResponse("ping_ok.json")
val artistId = 123L
client.api.star(artistId = artistId).execute()
val request = mockWebServerRule.mockWebServer.takeRequest()
request.requestLine `should contain` "artistId=$artistId"
}
@Test
fun `Should pass albom id param`() {
mockWebServerRule.enqueueResponse("ping_ok.json")
val albumId = 1001L
client.api.star(albumId = albumId).execute()
val request = mockWebServerRule.mockWebServer.takeRequest()
request.requestLine `should contain` "albumId=$albumId"
}
}

View File

@ -34,4 +34,9 @@ interface SubsonicAPIDefinition {
@GET("getArtists.view")
fun getArtists(@Query("musicFolderId") musicFolderId: Long?): Call<GetArtistsResponse>
@GET("star.view")
fun star(@Query("id") id: Long? = null,
@Query("albumId") albumId: Long? = null,
@Query("artistId") artistId: Long? = null): Call<SubsonicResponse>
}

View File

@ -294,6 +294,7 @@ public class RESTMusicService implements MusicService
return cachedArtists;
}
updateProgressListener(progressListener, R.string.parser_reading);
Response<GetArtistsResponse> response = subsonicAPIClient.getApi().getArtists(null).execute();
checkResponseSuccessful(response);
@ -317,42 +318,21 @@ public class RESTMusicService implements MusicService
return String.format(Locale.US, "indexes-%d.ser", Math.abs(s.hashCode()));
}
@Override
public void star(String id, String albumId, String artistId, Context context, ProgressListener progressListener) throws Exception
{
checkServerVersion(context, "1.8", "Starring not supported.");
@Override
public void star(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, "star", null, parameterNames, parameterValues);
try
{
new ErrorParser(context).parse(reader);
}
finally
{
Util.close(reader);
}
}
updateProgressListener(progressListener, R.string.parser_reading);
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
.star(apiId, apiAlbumId, apiArtistId).execute();
checkResponseSuccessful(response);
}
@Override
public void unstar(String id, String albumId, String artistId, Context context, ProgressListener progressListener) throws Exception

View File

@ -153,12 +153,12 @@ public class AlbumView extends UpdateView
album.setStarred(false);
}
final MusicService musicService = MusicServiceFactory.getMusicService(view.getContext());
new Thread(new Runnable()
{
@Override
public void run()
{
MusicService musicService = MusicServiceFactory.getMusicService(null);
boolean useId3 = Util.getShouldUseId3Tags(getContext());
try