Merge pull request #75 from ultrasonic/add-update-share
Add update share
This commit is contained in:
commit
3e5159a1a2
|
@ -0,0 +1,51 @@
|
|||
package org.moire.ultrasonic.api.subsonic
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Integration test for [SubsonicAPIDefinition.updateShare] call.
|
||||
*/
|
||||
class SubsonicApiUpdateShareTest : SubsonicAPIClientTest() {
|
||||
@Test
|
||||
fun `Should handle error response`() {
|
||||
checkErrorCallParsed(mockWebServerRule) {
|
||||
client.api.updateShare(11).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should handle ok response`() {
|
||||
mockWebServerRule.enqueueResponse("ping_ok.json")
|
||||
|
||||
val response = client.api.updateShare(12).execute()
|
||||
|
||||
assertResponseSuccessful(response)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass id in request params`() {
|
||||
val id = 4432L
|
||||
|
||||
mockWebServerRule.assertRequestParam(expectedParam = "id=$id") {
|
||||
client.api.updateShare(id = id).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass description in request params`() {
|
||||
val description = "some-description"
|
||||
|
||||
mockWebServerRule.assertRequestParam(expectedParam = "description=$description") {
|
||||
client.api.updateShare(123, description = description).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass expires in request params`() {
|
||||
val expires = 223123123L
|
||||
|
||||
mockWebServerRule.assertRequestParam(expectedParam = "expires=$expires") {
|
||||
client.api.updateShare(12, expires = expires).execute()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -207,6 +207,11 @@ interface SubsonicAPIDefinition {
|
|||
@GET("deleteShare.view")
|
||||
fun deleteShare(@Query("id") id: Long): Call<SubsonicResponse>
|
||||
|
||||
@GET("updateShare.view")
|
||||
fun updateShare(@Query("id") id: Long,
|
||||
@Query("description") description: String? = null,
|
||||
@Query("expires") expires: Long? = null): Call<SubsonicResponse>
|
||||
|
||||
@GET("getGenres.view")
|
||||
fun getGenres(): Call<GenresResponse>
|
||||
|
||||
|
|
|
@ -158,8 +158,6 @@ public class RESTMusicService implements MusicService
|
|||
private static final int SOCKET_CONNECT_TIMEOUT = 10 * 1000;
|
||||
private static final int SOCKET_READ_TIMEOUT_DEFAULT = 10 * 1000;
|
||||
|
||||
private static final int SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS = 60 * 1000;
|
||||
|
||||
/**
|
||||
* URL from which to fetch latest versions.
|
||||
*/
|
||||
|
@ -963,11 +961,6 @@ public class RESTMusicService implements MusicService
|
|||
return APIShareConverter.toDomainEntitiesList(response.body().getShares());
|
||||
}
|
||||
|
||||
private Reader getReader(Context context, ProgressListener progressListener, String method, HttpParams requestParams) throws Exception
|
||||
{
|
||||
return getReader(context, progressListener, method, requestParams, Collections.<String>emptyList(), Collections.emptyList());
|
||||
}
|
||||
|
||||
private Reader getReader(Context context, ProgressListener progressListener, String method, HttpParams requestParams, List<String> parameterNames, List<Object> parameterValues) throws Exception
|
||||
{
|
||||
|
||||
|
@ -1358,42 +1351,27 @@ public class RESTMusicService implements MusicService
|
|||
checkResponseSuccessful(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateShare(String id, String description, Long expires, Context context, ProgressListener progressListener) throws Exception
|
||||
{
|
||||
checkServerVersion(context, "1.6", "Updating share not supported.");
|
||||
@Override
|
||||
public void updateShare(String id,
|
||||
String description,
|
||||
Long expires,
|
||||
Context context,
|
||||
ProgressListener progressListener) throws Exception {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("Id is null");
|
||||
}
|
||||
if (expires != null &&
|
||||
expires == 0) {
|
||||
expires = null;
|
||||
}
|
||||
|
||||
HttpParams params = new BasicHttpParams();
|
||||
HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS);
|
||||
Long shareId = Long.valueOf(id);
|
||||
|
||||
List<String> parameterNames = new ArrayList<String>();
|
||||
List<Object> parameterValues = new ArrayList<Object>();
|
||||
|
||||
parameterNames.add("id");
|
||||
parameterValues.add(id);
|
||||
|
||||
if (description != null)
|
||||
{
|
||||
parameterNames.add("description");
|
||||
parameterValues.add(description);
|
||||
}
|
||||
|
||||
if (expires > 0)
|
||||
{
|
||||
parameterNames.add("expires");
|
||||
parameterValues.add(expires);
|
||||
}
|
||||
|
||||
Reader reader = getReader(context, progressListener, "updateShare", params, parameterNames, parameterValues);
|
||||
try
|
||||
{
|
||||
new ErrorParser(context).parse(reader);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Util.close(reader);
|
||||
}
|
||||
}
|
||||
updateProgressListener(progressListener, R.string.parser_reading);
|
||||
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
|
||||
.updateShare(shareId, description, expires).execute();
|
||||
checkResponseSuccessful(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getAvatar(Context context, String username, int size, boolean saveToFile, boolean highQuality, ProgressListener progressListener) throws Exception
|
||||
|
|
Loading…
Reference in New Issue