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();
}
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!"));
}
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;
}
Aggregations