Search in sources :

Example 11 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Request in project android-oss by kickstarter.

the class ProjectUpdatesViewModelTest method testProjectUpdatesViewModel_StartUpdateActivity.

@Test
public void testProjectUpdatesViewModel_StartUpdateActivity() {
    final ProjectUpdatesViewModel.ViewModel vm = new ProjectUpdatesViewModel.ViewModel(environment());
    final Project project = ProjectFactory.project();
    final Request updateRequest = new Request.Builder().url("https://kck.str/projects/param/param/posts/id").build();
    final TestSubscriber<Pair<Project, Update>> startUpdateActivity = new TestSubscriber<>();
    vm.outputs.startUpdateActivity().subscribe(startUpdateActivity);
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    vm.inputs.goToUpdateRequest(updateRequest);
    startUpdateActivity.assertValueCount(1);
    koalaTest.assertValues(KoalaEvent.VIEWED_UPDATES, KoalaEvent.VIEWED_UPDATE);
}
Also used : Project(com.kickstarter.models.Project) Request(okhttp3.Request) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Pair(android.util.Pair) Test(org.junit.Test)

Example 12 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Request in project android-oss by kickstarter.

the class ProjectUpdatesViewModelTest method testProjectUpdatesViewModel_LoadsWebViewUrl.

@Test
public void testProjectUpdatesViewModel_LoadsWebViewUrl() {
    final ProjectUpdatesViewModel.ViewModel vm = new ProjectUpdatesViewModel.ViewModel(environment());
    final Project project = ProjectFactory.project();
    final String anotherIndexUrl = "https://kck.str/projects/param/param/posts?page=another";
    final Request anotherIndexRequest = new Request.Builder().url(anotherIndexUrl).build();
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    // Start the intent with a project.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    // Initial project updates index emits.
    webViewUrl.assertValues(project.updatesUrl());
    koalaTest.assertValues(KoalaEvent.VIEWED_UPDATES);
    // Make a request for another update index.
    vm.inputs.goToUpdatesRequest(anotherIndexRequest);
    // New updates index url emits. Event is not tracked again.
    webViewUrl.assertValues(project.updatesUrl(), anotherIndexUrl);
    koalaTest.assertValues(KoalaEvent.VIEWED_UPDATES);
}
Also used : Project(com.kickstarter.models.Project) Request(okhttp3.Request) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Test(org.junit.Test)

Example 13 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Request in project feign by OpenFeign.

the class OkHttpClient method execute.

@Override
public feign.Response execute(feign.Request input, feign.Request.Options options) throws IOException {
    okhttp3.OkHttpClient requestScoped;
    if (delegate.connectTimeoutMillis() != options.connectTimeoutMillis() || delegate.readTimeoutMillis() != options.readTimeoutMillis()) {
        requestScoped = delegate.newBuilder().connectTimeout(options.connectTimeoutMillis(), TimeUnit.MILLISECONDS).readTimeout(options.readTimeoutMillis(), TimeUnit.MILLISECONDS).build();
    } else {
        requestScoped = delegate;
    }
    Request request = toOkHttpRequest(input);
    Response response = requestScoped.newCall(request).execute();
    return toFeignResponse(response).toBuilder().request(input).build();
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request)

Example 14 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Request in project Signal-Android by WhisperSystems.

the class GiphyLoader method loadPage.

@NonNull
public List<GiphyImage> loadPage(int offset) {
    try {
        String url;
        if (TextUtils.isEmpty(searchString))
            url = String.format(getTrendingUrl(), offset);
        else
            url = String.format(getSearchUrl(), offset, Uri.encode(searchString));
        Request request = new Request.Builder().url(url).build();
        Response response = client.newCall(request).execute();
        if (!response.isSuccessful()) {
            throw new IOException("Unexpected code " + response);
        }
        GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
        List<GiphyImage> results = giphyResponse.getData();
        if (results == null)
            return new LinkedList<>();
        else
            return results;
    } catch (IOException e) {
        Log.w(TAG, e);
        return new LinkedList<>();
    }
}
Also used : GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) Response(okhttp3.Response) GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) GiphyImage(org.thoughtcrime.securesms.giph.model.GiphyImage) Request(okhttp3.Request) IOException(java.io.IOException) NonNull(android.support.annotation.NonNull)

Example 15 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Request in project Signal-Android by WhisperSystems.

the class OkHttpStreamFetcher method loadData.

@Override
public InputStream loadData(Priority priority) throws Exception {
    Request.Builder requestBuilder = new Request.Builder().url(url.toStringUrl());
    for (Map.Entry<String, String> headerEntry : url.getHeaders().entrySet()) {
        String key = headerEntry.getKey();
        requestBuilder.addHeader(key, headerEntry.getValue());
    }
    Request request = requestBuilder.build();
    Response response = client.newCall(request).execute();
    responseBody = response.body();
    if (!response.isSuccessful()) {
        throw new IOException("Request failed with code: " + response.code());
    }
    long contentLength = responseBody.contentLength();
    stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength);
    return stream;
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException) Map(java.util.Map)

Aggregations

Request (okhttp3.Request)3768 Response (okhttp3.Response)2288 IOException (java.io.IOException)1180 OkHttpClient (okhttp3.OkHttpClient)896 Test (org.junit.Test)754 RequestBody (okhttp3.RequestBody)665 Call (okhttp3.Call)537 HttpUrl (okhttp3.HttpUrl)528 ResponseBody (okhttp3.ResponseBody)421 Callback (okhttp3.Callback)290 InputStream (java.io.InputStream)207 Map (java.util.Map)207 JSONObject (org.json.JSONObject)205 MediaType (okhttp3.MediaType)193 HashMap (java.util.HashMap)178 List (java.util.List)176 ArrayList (java.util.ArrayList)157 File (java.io.File)152 Test (org.junit.jupiter.api.Test)147 Headers (okhttp3.Headers)134