Search in sources :

Example 66 with Response

use of com.apollographql.apollo.api.Response in project apollo-android by apollographql.

the class RxApollo method from.

@Nonnull
public static <T> Observable<Response<T>> from(@Nonnull final ApolloSubscriptionCall<T> call, Emitter.BackpressureMode backpressureMode) {
    checkNotNull(call, "call == null");
    return Observable.create(new Action1<Emitter<Response<T>>>() {

        @Override
        public void call(final Emitter<Response<T>> emitter) {
            final AtomicBoolean canceled = new AtomicBoolean();
            emitter.setCancellation(new Cancellable() {

                @Override
                public void cancel() throws Exception {
                    canceled.set(true);
                    call.cancel();
                }
            });
            call.execute(new ApolloSubscriptionCall.Callback<T>() {

                @Override
                public void onResponse(@Nonnull Response<T> response) {
                    if (!canceled.get()) {
                        emitter.onNext(response);
                    }
                }

                @Override
                public void onFailure(@Nonnull ApolloException e) {
                    Exceptions.throwIfFatal(e);
                    if (!canceled.get()) {
                        emitter.onError(e);
                    }
                }

                @Override
                public void onCompleted() {
                    if (!canceled.get()) {
                        emitter.onCompleted();
                    }
                }
            });
        }
    }, backpressureMode);
}
Also used : Response(com.apollographql.apollo.api.Response) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Emitter(rx.Emitter) Nonnull(javax.annotation.Nonnull) ApolloException(com.apollographql.apollo.exception.ApolloException) Cancellable(rx.functions.Cancellable) Nonnull(javax.annotation.Nonnull)

Example 67 with Response

use of com.apollographql.apollo.api.Response in project RandomWebm by alkocher.

the class ToggleVotesUtil method toggleDislike.

public void toggleDislike(String webmId, boolean hasLike, boolean hasDislike) {
    ApolloMutationCall<ToggleDislikeMutation.Data> dislikeMutationCall = WebmApolloClient.getWebmApolloClient().mutate(new ToggleDislikeMutation(webmId, hasLike, hasDislike));
    mDisposable.add(Rx2Apollo.from(dislikeMutationCall).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribeWith(new DisposableObserver<Response<ToggleDislikeMutation.Data>>() {

        @Override
        public void onNext(Response<ToggleDislikeMutation.Data> dataResponse) {
        }

        @Override
        public void onError(Throwable e) {
            webmData.showErrorSnackbar();
        }

        @Override
        public void onComplete() {
            webmData.showSuccessSnackbar();
        }
    }));
}
Also used : Response(com.apollographql.apollo.api.Response) DisposableObserver(io.reactivex.observers.DisposableObserver) WebmData(com.example.aleksejkocergin.randomwebm.interfaces.WebmData) ToggleDislikeMutation(com.example.aleksejkocergin.myapplication.ToggleDislikeMutation)

Aggregations

Response (com.apollographql.apollo.api.Response)67 Test (org.junit.Test)55 ApolloException (com.apollographql.apollo.exception.ApolloException)34 Utils.enqueueAndAssertResponse (com.apollographql.apollo.Utils.enqueueAndAssertResponse)29 Utils.assertResponse (com.apollographql.apollo.Utils.assertResponse)26 Utils.mockResponse (com.apollographql.apollo.Utils.mockResponse)26 IOException (java.io.IOException)23 MockResponse (okhttp3.mockwebserver.MockResponse)22 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)18 ParseException (java.text.ParseException)17 ApolloHttpException (com.apollographql.apollo.exception.ApolloHttpException)12 AllPlanetsQuery (com.apollographql.apollo.integration.httpcache.AllPlanetsQuery)12 HeroAndFriendsNamesWithIDsQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesWithIDsQuery)11 Utils.cacheAndAssertCachedResponse (com.apollographql.apollo.Utils.cacheAndAssertCachedResponse)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Nonnull (javax.annotation.Nonnull)7 TestObserver (io.reactivex.observers.TestObserver)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 TestSubscriber (rx.observers.TestSubscriber)5 Handler (android.os.Handler)4