Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ public interface API {
}
```

ℹ️ If your REST endpoint returns an empty body, you need to specify `Observable<EmptyResponse>` as return value rather than `Observable<Void>` because ["Nulls are not allowed in \[RxJava\] 2.x."](https://github.com/ReactiveX/RxJava/issues/5775#issuecomment-353544736).
ℹ️ If you are working with `Call`s you can safely use `Call<Void>` (or `Call<EmptyResponse>`) if you want.
ℹ️ If your REST endpoint returns an empty body, you need to specify `Observable<EmptyResponse>` / `Call<EmptyResponse>` as return value rather than `Observable<Void>` / `Call<Void>` because ["Nulls are not allowed in \[RxJava\] 2.x."](https://github.com/ReactiveX/RxJava/issues/5775#issuecomment-353544736).

You might instantiate your Retrofit `API` by using something like this:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public <T> T performRequestV2(final @NonNull Type type, NextcloudRequest request
}

public <T> T convertStreamToTargetEntity(InputStream inputStream, Type targetEntity) throws IOException {
ensureTypeNotVoid(targetEntity);

final T result;
try (InputStream os = inputStream;
Reader targetReader = new InputStreamReader(os)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private Retrofit2Helper() { }

public static <T> Call<T> WrapInCall(final NextcloudAPI nextcloudAPI, final NextcloudRequest nextcloudRequest,
final Type resType) {
return new Call<T>() {
return new Call<>() {

/**
* Execute synchronous
Expand Down Expand Up @@ -134,83 +134,4 @@ private Response<T> convertExceptionToResponse(int statusCode, String errorMessa
}
};
}

/**
*
* @param success if <code>true</code>, a Response.success will be returned, otherwise Response.error(520)
*/
public static Call<EmptyResponse> wrapEmptyResponseCall(final boolean success) {
return new Call<>() {
@NonNull
@Override
public Response<EmptyResponse> execute() {
if (success) {
return Response.success(null);
} else {
return Response.error(520, emptyResponseBody);
}
}

@Override
public void enqueue(@NonNull Callback<EmptyResponse> callback) {
if (success) {
callback.onResponse(this, Response.success(null));
} else {
callback.onResponse(this, Response.error(520, emptyResponseBody));
}
}

@Override
public boolean isExecuted() {
return true;
}

@Override
public void cancel() {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public boolean isCanceled() {
return false;
}

@NonNull
@Override
public Call<EmptyResponse> clone() {
throw new UnsupportedOperationException("Not implemented");
}

@NonNull
@Override
public Request request() {
throw new UnsupportedOperationException("Not implemented");
}

@NonNull
@Override
public Timeout timeout() {
throw new UnsupportedOperationException("Not implemented");
}
};

}

private final static ResponseBody emptyResponseBody = new ResponseBody() {
@Override
public MediaType contentType() {
return null;
}

@Override
public long contentLength() {
return 0;
}

@Override
public BufferedSource source() {
return null;
}
};

}