Search in sources :

Example 6 with Response

use of retrofit.client.Response in project Varis-Android by dkhmelenko.

the class TestBuildDetailsPresenter method testStartLoadingDataSingleJob.

@Test
public void testStartLoadingDataSingleJob() {
    final long buildId = 1L;
    final String slug = "test";
    final Build build = new Build();
    final Commit commit = new Commit();
    final List<Job> jobs = new ArrayList<>();
    final Job job = new Job();
    jobs.add(job);
    BuildDetails buildDetails = new BuildDetails();
    buildDetails.setBuild(build);
    buildDetails.setCommit(commit);
    buildDetails.setJobs(jobs);
    final String expectedUrl = "https://sample.org";
    Response response = new Response(expectedUrl, 200, "", Collections.<Header>emptyList(), null);
    final String accessToken = "test";
    final String authToken = "token " + accessToken;
    AppSettings.putAccessToken("test");
    when(mRawClient.getApiService().getLog(authToken, String.valueOf(job.getId()))).thenReturn(response);
    when(mTravisRestClient.getApiService().getBuild(slug, buildId)).thenReturn(buildDetails);
    mBuildsDetailsPresenter.startLoadingData(null, slug, buildId);
    verify(mTaskManager).getBuildDetails(slug, buildId);
    verify(mBuildDetailsView).showProgress();
    verify(mBuildDetailsView).hideProgress();
    verify(mBuildDetailsView).updateBuildDetails(buildDetails);
    verify(mBuildDetailsView).showBuildLogs();
    verify(mBuildDetailsView).showAdditionalActionsForBuild(buildDetails);
}
Also used : Response(retrofit.client.Response) Commit(com.khmelenko.lab.varis.network.response.Commit) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) Build(com.khmelenko.lab.varis.network.response.Build) ArrayList(java.util.ArrayList) Job(com.khmelenko.lab.varis.network.response.Job) Test(org.junit.Test)

Example 7 with Response

use of retrofit.client.Response in project Varis-Android by dkhmelenko.

the class TestBuildDetailsPresenter method testStartLoadingLogWithToken.

@Test
public void testStartLoadingLogWithToken() {
    final long jobId = 1L;
    final String expectedUrl = "https://sample.org";
    Response response = new Response(expectedUrl, 200, "", Collections.<Header>emptyList(), null);
    final String accessToken = "test";
    final String authToken = "token " + accessToken;
    when(mRawClient.getApiService().getLog(authToken, String.valueOf(jobId))).thenReturn(response);
    AppSettings.putAccessToken(accessToken);
    mBuildsDetailsPresenter.startLoadingLog(jobId);
    verify(mTaskManager).getLogUrl(authToken, jobId);
    verify(mBuildDetailsView).setLogUrl(expectedUrl);
}
Also used : Response(retrofit.client.Response) Test(org.junit.Test)

Example 8 with Response

use of retrofit.client.Response in project glasquare by davidvavra.

the class CheckInActivity method checkIn.

private void checkIn() {
    final String venueId = getIntent().getStringExtra(EXTRA_VENUE_ID);
    final Location location = LocationUtils.getLastLocation();
    final String ll = LocationUtils.getLatLon(location);
    int accuracy = (int) location.getAccuracy();
    int altitude = (int) location.getAltitude();
    showProgress(R.string.checking_in);
    showCheckInInfo();
    String broadcast = getBroadcast();
    Api.get().create(CheckIns.class).add(venueId, ll, mShout, broadcast, accuracy, altitude, new Callback<CheckIns.CheckInResponse>() {

        @Override
        public void success(final CheckIns.CheckInResponse checkInResponse, Response response) {
            mCheckInResponse = checkInResponse;
            if (mAddingPhoto) {
                ImageUtils.processPictureWhenReady(CheckInActivity.this, mPhoto, new ImageUtils.OnPictureReadyListener() {

                    @Override
                    public void onPictureReady() {
                        new BaseAsyncTask() {

                            @Override
                            public void inBackground() {
                                ImageUtils.resize(mPhoto);
                            }

                            @Override
                            public void postExecute() {
                                addPhoto();
                            }
                        }.start();
                    }
                });
            } else {
                showCheckInComplete();
            }
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            if (!Auth.handle(CheckInActivity.this, retrofitError)) {
                showError(R.string.error_please_try_again);
            }
        }
    });
}
Also used : Response(retrofit.client.Response) CheckIns(cz.destil.glasquare.api.CheckIns) BaseAsyncTask(cz.destil.glasquare.util.BaseAsyncTask) Location(android.location.Location) RetrofitError(retrofit.RetrofitError)

Example 9 with Response

use of retrofit.client.Response in project glasquare by davidvavra.

the class CheckInSearchActivity method loadData.

@Override
protected void loadData() {
    showProgress(R.string.loading);
    LocationUtils.getRecentLocation(new LocationUtils.LocationListener() {

        @Override
        public void onLocationAcquired(Location location) {
            String ll = LocationUtils.getLatLon(location);
            Api.get().create(SearchVenues.class).searchForCheckIn(ll, new Callback<SearchVenues.SearchResponse>() {

                @Override
                public void success(SearchVenues.SearchResponse venuesResponse, Response response) {
                    showContent(new CheckInSearchAdapter(venuesResponse.getVenues()), new CardSelectedListener() {

                        @Override
                        public void onCardSelected(Object item) {
                            SearchVenues.Venue venue = (SearchVenues.Venue) item;
                            CheckInActivity.call(CheckInSearchActivity.this, venue.id, venue.name);
                        }
                    });
                }

                @Override
                public void failure(RetrofitError retrofitError) {
                    showError(R.string.error_please_try_again);
                }
            });
        }

        @Override
        public void onLocationFailed() {
            showError(R.string.no_location);
        }
    });
}
Also used : LocationUtils(cz.destil.glasquare.util.LocationUtils) SearchVenues(cz.destil.glasquare.api.SearchVenues) Response(retrofit.client.Response) CheckInSearchAdapter(cz.destil.glasquare.adapter.CheckInSearchAdapter) Callback(retrofit.Callback) Location(android.location.Location) RetrofitError(retrofit.RetrofitError)

Example 10 with Response

use of retrofit.client.Response in project retrofit-examples by kdubb1337.

the class AsynchronousClient method main.

public static void main(String[] args) {
    // Build the Retrofit REST adaptor pointing to the URL specified
    // with a ThrottlingInterceptor allowing only 1 request per second
    RestAdapter restAdapter = new RestAdapter.Builder().setRequestInterceptor(new ThrottlingInterceptor(1000L)).setServer(API_URL).build();
    // Create an instance of our InterestingApi interface.
    InterestingApi synchronousApi = restAdapter.create(InterestingApi.class);
    // Create an instance of our AsynchronousApi interface.
    AsynchronousApi asyncApi = restAdapter.create(AsynchronousApi.class);
    for (int i = 0; i < 10; i++) LOG.info("synchronousApi " + synchronousApi.getWithPath(Integer.toString(i)));
    for (int i = 0; i < 10; i++) asyncApi.getWithPath(Integer.toString(i), new Callback<String>() {

        @Override
        public void success(String t, Response response) {
            LOG.info("asynchronousApi (" + t + ")");
        }

        @Override
        public void failure(RetrofitError error) {
            LOG.info("Epic fail!");
        }
    });
}
Also used : Response(retrofit.client.Response) Callback(retrofit.Callback) AsynchronousApi(com.kdubb.retrofitexamples.api.AsynchronousApi) RestAdapter(retrofit.RestAdapter) InterestingApi(com.kdubb.retrofitexamples.api.InterestingApi) RetrofitError(retrofit.RetrofitError)

Aggregations

Response (retrofit.client.Response)15 Test (org.junit.Test)7 RetrofitError (retrofit.RetrofitError)7 TaskError (com.khmelenko.lab.varis.task.TaskError)3 TaskException (com.khmelenko.lab.varis.task.TaskException)3 ArrayList (java.util.ArrayList)3 Callback (retrofit.Callback)3 Location (android.location.Location)2 RestAdapter (retrofit.RestAdapter)2 Header (retrofit.client.Header)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 MenuItem (android.view.MenuItem)1 AsynchronousApi (com.kdubb.retrofitexamples.api.AsynchronousApi)1 InterestingApi (com.kdubb.retrofitexamples.api.InterestingApi)1 AccessTokenRequest (com.khmelenko.lab.varis.network.request.AccessTokenRequest)1 AuthorizationRequest (com.khmelenko.lab.varis.network.request.AuthorizationRequest)1 AccessToken (com.khmelenko.lab.varis.network.response.AccessToken)1 Authorization (com.khmelenko.lab.varis.network.response.Authorization)1 Build (com.khmelenko.lab.varis.network.response.Build)1 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)1