Search in sources :

Example 1 with Response

use of com.jcabi.http.Response in project jcabi-github by jcabi.

the class RtGist method read.

@Override
public String read(final String file) throws IOException {
    final Response response = this.request.fetch();
    final String url = response.as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK).as(JsonResponse.class).json().readObject().getJsonObject("files").getJsonObject(file).getString("raw_url");
    return response.as(RestResponse.class).jump(URI.create(url)).fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK).body();
}
Also used : Response(com.jcabi.http.Response) JsonResponse(com.jcabi.http.response.JsonResponse) RestResponse(com.jcabi.http.response.RestResponse) RestResponse(com.jcabi.http.response.RestResponse) JsonResponse(com.jcabi.http.response.JsonResponse)

Example 2 with Response

use of com.jcabi.http.Response in project jcabi-github by jcabi.

the class RtSearchTest method readNonUnicode.

/**
 * RtSearch can read non-unicode.
 * @throws Exception if any problem inside
 */
@Test
public void readNonUnicode() throws Exception {
    final Response resp = new FakeRequest().withBody("{\"help\": \"\u001Fblah\u0001cwhoa\u0000!\"}").fetch();
    final JsonResponse response = new JsonResponse(resp);
    MatcherAssert.assertThat(response.json().readObject().getString("help"), Matchers.is("\u001Fblah\u0001cwhoa\u0000!"));
}
Also used : Response(com.jcabi.http.Response) JsonResponse(com.jcabi.http.response.JsonResponse) JsonResponse(com.jcabi.http.response.JsonResponse) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 3 with Response

use of com.jcabi.http.Response in project jcabi-github by jcabi.

the class CarefulWire method send.

@Override
public // @checkstyle ParameterNumber (8 lines)
Response send(final Request req, final String home, final String method, final Collection<Map.Entry<String, String>> headers, final InputStream content, final int connect, final int read) throws IOException {
    final Response resp = this.origin.send(req, home, method, headers, content, connect, read);
    final int remaining = this.remainingHeader(resp);
    if (remaining < this.threshold) {
        final long reset = this.resetHeader(resp);
        final long now = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
        if (reset > now) {
            final long length = reset - now;
            Logger.info(this, // @checkstyle LineLength (1 line)
            "Remaining number of requests per hour is less than %d. Waiting for %d seconds.", this.threshold, length);
            try {
                TimeUnit.SECONDS.sleep(length);
            } catch (final InterruptedException ex) {
                Thread.currentThread().interrupt();
                throw new IllegalStateException(ex);
            }
        }
    }
    return resp;
}
Also used : Response(com.jcabi.http.Response)

Aggregations

Response (com.jcabi.http.Response)3 JsonResponse (com.jcabi.http.response.JsonResponse)2 FakeRequest (com.jcabi.http.request.FakeRequest)1 RestResponse (com.jcabi.http.response.RestResponse)1 Test (org.junit.Test)1