Merge pull request #74 from ultrasonic/add-delete-share

Add delete share
This commit is contained in:
Yahor Berdnikau 2017-11-19 15:04:34 +01:00 committed by GitHub
commit 81bb21c841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 24 deletions

View File

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

View File

@ -204,6 +204,9 @@ interface SubsonicAPIDefinition {
@Query("description") description: String? = null,
@Query("expires") expires: Long? = null): Call<SharesResponse>
@GET("deleteShare.view")
fun deleteShare(@Query("id") id: Long): Call<SubsonicResponse>
@GET("getGenres.view")
fun getGenres(): Call<GenresResponse>

View File

@ -1343,31 +1343,20 @@ public class RESTMusicService implements MusicService
return APIShareConverter.toDomainEntitiesList(response.body().getShares());
}
@Override
public void deleteShare(String id, Context context, ProgressListener progressListener) throws Exception
{
checkServerVersion(context, "1.6", "Shares not supported.");
@Override
public void deleteShare(String id,
Context context,
ProgressListener progressListener) throws Exception {
if (id == null) {
throw new IllegalArgumentException("Id is null!");
}
Long shareId = Long.valueOf(id);
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);
Reader reader = getReader(context, progressListener, "deleteShare", params, parameterNames, parameterValues);
try
{
new ErrorParser(context).parse(reader);
}
finally
{
Util.close(reader);
}
}
updateProgressListener(progressListener, R.string.parser_reading);
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
.deleteShare(shareId).execute();
checkResponseSuccessful(response);
}
@Override
public void updateShare(String id, String description, Long expires, Context context, ProgressListener progressListener) throws Exception