Merge pull request #71 from ultrasonic/add-create-bookmark

Add create bookmark
This commit is contained in:
Yahor Berdnikau 2017-11-18 22:04:42 +01:00 committed by GitHub
commit c6ad07f56f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 27 deletions

View File

@ -0,0 +1,51 @@
package org.moire.ultrasonic.api.subsonic
import org.junit.Test
/**
* Integration test for [SubsonicAPIDefinition.createBookmark] call.
*/
class SubsonicApiCreateBookmarkTest : SubsonicAPIClientTest() {
@Test
fun `Should handle error response`() {
checkErrorCallParsed(mockWebServerRule) {
client.api.createBookmark(1, 1).execute()
}
}
@Test
fun `Should handle ok response`() {
mockWebServerRule.enqueueResponse("ping_ok.json")
val response = client.api.createBookmark(213, 123213L).execute()
assertResponseSuccessful(response)
}
@Test
fun `Should pass id in request params`() {
val id = 544
mockWebServerRule.assertRequestParam(expectedParam = "id=$id") {
client.api.createBookmark(id = id, position = 123).execute()
}
}
@Test
fun `Should pass position in request params`() {
val position = 4412333L
mockWebServerRule.assertRequestParam(expectedParam = "position=$position") {
client.api.createBookmark(id = 12, position = position).execute()
}
}
@Test
fun `Should pass comment in request params`() {
val comment = "some-comment"
mockWebServerRule.assertRequestParam(expectedParam = "comment=$comment") {
client.api.createBookmark(id = 1, position = 1, comment = comment).execute()
}
}
}

View File

@ -224,4 +224,10 @@ interface SubsonicAPIDefinition {
@GET("getBookmarks.view")
fun getBookmarks(): Call<BookmarksResponse>
@GET("createBookmark.view")
fun createBookmark(
@Query("id") id: Int,
@Query("position") position: Long,
@Query("comment") comment: String? = null): Call<SubsonicResponse>
}

View File

@ -1284,33 +1284,20 @@ public class RESTMusicService implements MusicService
return APIBookmarkConverter.toDomainEntitiesList(response.body().getBookmarkList());
}
@Override
public void createBookmark(String id, int position, Context context, ProgressListener progressListener) throws Exception
{
checkServerVersion(context, "1.9", "Bookmarks not supported.");
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS);
List<String> parameterNames = new ArrayList<String>();
List<Object> parameterValues = new ArrayList<Object>();
parameterNames.add("id");
parameterValues.add(id);
parameterNames.add("position");
parameterValues.add(position);
Reader reader = getReader(context, progressListener, "createBookmark", params, parameterNames, parameterValues);
try
{
new ErrorParser(context).parse(reader);
}
finally
{
Util.close(reader);
}
}
@Override
public void createBookmark(String id,
int position,
Context context,
ProgressListener progressListener) throws Exception {
if (id == null) {
throw new IllegalArgumentException("Item id should not be null");
}
Integer itemId = Integer.valueOf(id);
updateProgressListener(progressListener, R.string.parser_reading);
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
.createBookmark(itemId, position, null).execute();
checkResponseSuccessful(response);
}
@Override
public void deleteBookmark(String id, Context context, ProgressListener progressListener) throws Exception