Merge pull request #42 from ultrasonic/add-create-playlist
Add create playlist
This commit is contained in:
commit
77833bf4d9
|
@ -0,0 +1,54 @@
|
|||
package org.moire.ultrasonic.api.subsonic
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Integration test for [SubsonicAPIClient] for createPlaylist call.
|
||||
*/
|
||||
class SubsonicApiCreatePlaylistTest : SubsonicAPIClientTest() {
|
||||
@Test
|
||||
fun `Should handle error response`() {
|
||||
checkErrorCallParsed(mockWebServerRule) {
|
||||
client.api.createPlaylist().execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should hanlde ok response`() {
|
||||
mockWebServerRule.enqueueResponse("ping_ok.json")
|
||||
|
||||
val response = client.api.createPlaylist().execute()
|
||||
|
||||
assertResponseSuccessful(response)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass id param in request`() {
|
||||
val id = 56L
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json",
|
||||
expectedParam = "playlistId=$id") {
|
||||
client.api.createPlaylist(id = id).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass name param in request`() {
|
||||
val name = "some-name"
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json",
|
||||
expectedParam = "name=$name") {
|
||||
client.api.createPlaylist(name = name).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass song id param in request`() {
|
||||
val songId = listOf(4410L, 852L)
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json",
|
||||
expectedParam = "songId=${songId[0]}&songId=${songId[1]}") {
|
||||
client.api.createPlaylist(songIds = songId).execute()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -91,4 +91,9 @@ interface SubsonicAPIDefinition {
|
|||
|
||||
@GET("getPlaylists.view")
|
||||
fun getPlaylists(@Query("username") username: String? = null): Call<GetPlaylistsResponse>
|
||||
|
||||
@GET("createPlaylist.view")
|
||||
fun createPlaylist(@Query("playlistId") id: Long? = null,
|
||||
@Query("name") name: String? = null,
|
||||
@Query("songId") songIds: List<Long>? = null): Call<SubsonicResponse>
|
||||
}
|
||||
|
|
|
@ -573,38 +573,25 @@ public class RESTMusicService implements MusicService
|
|||
return APIPlaylistConverter.toDomainEntitiesList(response.body().getPlaylists());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPlaylist(String id, String name, List<MusicDirectory.Entry> entries, Context context, ProgressListener progressListener) throws Exception
|
||||
{
|
||||
List<String> parameterNames = new LinkedList<String>();
|
||||
List<Object> parameterValues = new LinkedList<Object>();
|
||||
@Override
|
||||
public void createPlaylist(String id,
|
||||
String name,
|
||||
List<MusicDirectory.Entry> entries,
|
||||
Context context,
|
||||
ProgressListener progressListener) throws Exception {
|
||||
Long pId = id == null ? null : Long.valueOf(id);
|
||||
List<Long> pSongIds = new ArrayList<>(entries.size());
|
||||
for (MusicDirectory.Entry entry : entries) {
|
||||
if (entry.getId() != null) {
|
||||
pSongIds.add(Long.valueOf(entry.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
if (id != null)
|
||||
{
|
||||
parameterNames.add("playlistId");
|
||||
parameterValues.add(id);
|
||||
}
|
||||
if (name != null)
|
||||
{
|
||||
parameterNames.add("name");
|
||||
parameterValues.add(name);
|
||||
}
|
||||
for (MusicDirectory.Entry entry : entries)
|
||||
{
|
||||
parameterNames.add("songId");
|
||||
parameterValues.add(entry.getId());
|
||||
}
|
||||
|
||||
Reader reader = getReader(context, progressListener, "createPlaylist", null, parameterNames, parameterValues);
|
||||
try
|
||||
{
|
||||
new ErrorParser(context).parse(reader);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Util.close(reader);
|
||||
}
|
||||
}
|
||||
updateProgressListener(progressListener, R.string.parser_reading);
|
||||
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
|
||||
.createPlaylist(pId, name, pSongIds).execute();
|
||||
checkResponseSuccessful(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePlaylist(String id, Context context, ProgressListener progressListener) throws Exception
|
||||
|
|
Loading…
Reference in New Issue