Search in sources :

Example 1 with Response

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

the class ToggleVotesUtil method toggleLike.

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

        @Override
        public void onNext(Response<ToggleLikeMutation.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) ToggleLikeMutation(com.example.aleksejkocergin.myapplication.ToggleLikeMutation)

Example 2 with Response

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

the class WebmDetailsFetcher method fetchWebmDetails.

public void fetchWebmDetails() {
    ApolloCall<WebmQuery.Data> webmQuery = WebmApolloClient.getWebmApolloClient().query(new WebmQuery(webmId));
    disposable.add(Rx2Apollo.from(webmQuery).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribeWith(new DisposableObserver<Response<WebmQuery.Data>>() {

        @Override
        public void onNext(Response<WebmQuery.Data> dataResponse) {
            webmData.render(dataResponse.data());
        }

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

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

Example 3 with Response

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

the class WebmListFragment method fetchWebmList.

private void fetchWebmList() {
    errorCheckConnection.setVisibility(View.GONE);
    errorNoResults.setVisibility(View.GONE);
    bottomLayout.setVisibility(View.VISIBLE);
    ApolloCall<WebmListQuery.Data> webmListQuery = WebmApolloClient.getWebmApolloClient().query(new WebmListQuery(PAGE_SIZE, Order.valueOf(order), ++currentPage, tagName, likedWebms));
    disposables.add(Rx2Apollo.from(webmListQuery).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableObserver<Response<WebmListQuery.Data>>() {

        @Override
        public void onNext(Response<WebmListQuery.Data> dataResponse) {
            setWebmData(dataResponse.data());
        }

        @Override
        public void onError(Throwable e) {
            swipeContainer.setRefreshing(false);
            errorCheckConnection.setVisibility(View.VISIBLE);
            Log.e(TAG, e.getMessage(), e);
        }

        @Override
        public void onComplete() {
            swipeContainer.setRefreshing(false);
            bottomLayout.setVisibility(View.GONE);
        }
    }));
}
Also used : Response(com.apollographql.apollo.api.Response) DisposableObserver(io.reactivex.observers.DisposableObserver) WebmListQuery(com.example.aleksejkocergin.myapplication.WebmListQuery)

Example 4 with Response

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

the class ApolloInterceptorTest method applicationInterceptorCanMakeMultipleRequestsToServer.

@Test
public void applicationInterceptorCanMakeMultipleRequestsToServer() throws Exception {
    server.enqueue(mockResponse(FILE_EPISODE_HERO_NAME_CHANGE));
    EpisodeHeroNameQuery query = createHeroNameQuery();
    ApolloInterceptor interceptor = createChainInterceptor();
    client = createApolloClient(interceptor);
    enqueueAndAssertResponse(server, FILE_EPISODE_HERO_NAME_WITH_ID, client.query(query), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {

        @Override
        public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
            assertThat(response.data().hero().name()).isEqualTo("Artoo");
            return true;
        }
    });
}
Also used : Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Utils.assertResponse(com.apollographql.apollo.Utils.assertResponse) Response(com.apollographql.apollo.api.Response) InterceptorResponse(com.apollographql.apollo.interceptor.ApolloInterceptor.InterceptorResponse) MockResponse(okhttp3.mockwebserver.MockResponse) EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) ApolloInterceptor(com.apollographql.apollo.interceptor.ApolloInterceptor) ApolloParseException(com.apollographql.apollo.exception.ApolloParseException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ApolloException(com.apollographql.apollo.exception.ApolloException) Test(org.junit.Test)

Example 5 with Response

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

the class ApolloInterceptorTest method onShortCircuitingResponseSubsequentInterceptorsAreNotCalled.

@Test
public void onShortCircuitingResponseSubsequentInterceptorsAreNotCalled() throws IOException, ApolloException {
    EpisodeHeroNameQuery query = createHeroNameQuery();
    final InterceptorResponse expectedResponse = prepareInterceptorResponse(query);
    ApolloInterceptor firstInterceptor = createShortcutInterceptor(expectedResponse);
    ApolloInterceptor secondInterceptor = createChainInterceptor();
    client = ApolloClient.builder().serverUrl(server.url("/")).okHttpClient(okHttpClient).addApplicationInterceptor(firstInterceptor).addApplicationInterceptor(secondInterceptor).build();
    assertResponse(client.query(query), new Predicate<Response<EpisodeHeroNameQuery.Data>>() {

        @Override
        public boolean test(Response<EpisodeHeroNameQuery.Data> response) throws Exception {
            assertThat(expectedResponse.parsedResponse.get()).isEqualTo(response);
            return true;
        }
    });
}
Also used : Utils.enqueueAndAssertResponse(com.apollographql.apollo.Utils.enqueueAndAssertResponse) Utils.assertResponse(com.apollographql.apollo.Utils.assertResponse) Response(com.apollographql.apollo.api.Response) InterceptorResponse(com.apollographql.apollo.interceptor.ApolloInterceptor.InterceptorResponse) MockResponse(okhttp3.mockwebserver.MockResponse) EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) InterceptorResponse(com.apollographql.apollo.interceptor.ApolloInterceptor.InterceptorResponse) ApolloInterceptor(com.apollographql.apollo.interceptor.ApolloInterceptor) ApolloParseException(com.apollographql.apollo.exception.ApolloParseException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ApolloException(com.apollographql.apollo.exception.ApolloException) Test(org.junit.Test)

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