Skip to content

Commit

Permalink
Merge pull request square#1714 from square/jw/adapter-docs
Browse files Browse the repository at this point in the history
Adapter Javadoc details.
  • Loading branch information
swankjesse committed Apr 3, 2016
2 parents b50cf58 + aa7a795 commit eb8dd88
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.ListenableFuture;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand All @@ -26,6 +27,27 @@
import retrofit2.Response;
import retrofit2.Retrofit;

/**
* A {@linkplain CallAdapter.Factory call adapter} which creates Guava futures.
* <p>
* Adding this class to {@link Retrofit} allows you to return {@link ListenableFuture} from service
* methods.
* <pre>{@code
* interface MyService {
* &#64;GET("user/me")
* ListenableFuture<User> getUser()
* }
* }</pre>
* There are two configurations supported for the {@code ListenableFuture} type parameter:
* <ul>
* <li>Direct body (e.g., {@code ListenableFuture<User>}) returns the deserialized body for 2XX
* responses, sets {@link HttpException} errors for non-2XX responses, and sets {@link IOException}
* for network errors.</li>
* <li>Response wrapped body (e.g., {@code ListenableFuture<Response<User>>}) returns a
* {@link Response} object for all HTTP responses and sets {@link IOException} for network
* errors</li>
* </ul>
*/
public final class GuavaCallAdapterFactory extends CallAdapter.Factory {
public static GuavaCallAdapterFactory create() {
return new GuavaCallAdapterFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package retrofit2.adapter.java8;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand All @@ -25,6 +26,27 @@
import retrofit2.Response;
import retrofit2.Retrofit;

/**
* A {@linkplain CallAdapter.Factory call adapter} which creates Java 8 futures.
* <p>
* Adding this class to {@link Retrofit} allows you to return {@link CompletableFuture} from
* service methods.
* <pre>{@code
* interface MyService {
* &#64;GET("user/me")
* CompletableFuture<User> getUser()
* }
* }</pre>
* There are two configurations supported for the {@code CompletableFuture} type parameter:
* <ul>
* <li>Direct body (e.g., {@code CompletableFuture<User>}) returns the deserialized body for 2XX
* responses, sets {@link HttpException} errors for non-2XX responses, and sets {@link IOException}
* for network errors.</li>
* <li>Response wrapped body (e.g., {@code CompletableFuture<Response<User>>}) returns a
* {@link Response} object for all HTTP responses and sets {@link IOException} for network
* errors</li>
* </ul>
*/
public final class Java8CallAdapterFactory extends CallAdapter.Factory {
public static Java8CallAdapterFactory create() {
return new Java8CallAdapterFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package retrofit2.adapter.rxjava;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -43,6 +44,17 @@
* Observable<User> getUser()
* }
* }</pre>
* There are three configurations supported for the {@code Observable} type parameter:
* <ul>
* <li>Direct body (e.g., {@code Observable<User>}) calls {@code onNext} with the deserialized body
* for 2XX responses and calls {@code onError} with {@link HttpException} for non-2XX responses and
* {@link IOException} for network errors.</li>
* <li>Response wrapped body (e.g., {@code Observable<Response<User>>}) calls {@code onNext}
* with a {@link Response} object for all HTTP responses and calls {@code onError} with
* {@link IOException} for network errors</li>
* <li>Result wrapped body (e.g., {@code Observable<Result<User>>}) calls {@code onNext} with a
* {@link Result} object for all HTTP responses and errors.</li>
* </ul>
*/
public final class RxJavaCallAdapterFactory extends CallAdapter.Factory {
/**
Expand Down

0 comments on commit eb8dd88

Please sign in to comment.