/** * Verifies HTTP response body content against provided matcher, * and throws {@link AssertionError} in case of mismatch. * @param matcher The matcher to use * @return This object */ public RestResponse assertBody(final Matcher<String> matcher) { MatcherAssert.assertThat( String.format( "HTTP response body content is not valid:%n%s", this ), this.body(), matcher ); return this; }
public void trades(String tradesURL, String exchangeTitle) throws IOException { String trades = new JdkRequest(tradesURL).method(Request.GET).fetch().as(RestResponse.class).body(); LOGGER.debug(exchangeTitle + " [Jcabi] trades: " + trades); } }
public void orderBook(String orderBookURL, String exchangeTitle) throws IOException { String orderBook = new JdkRequest(orderBookURL).method(Request.GET).fetch().as(RestResponse.class).body(); LOGGER.debug(exchangeTitle + " [Jcabi] orderBook: " + orderBook); }
public void ticker(String tickerURL, String exchangeTitle) throws IOException { String ticker = new JdkRequest(tickerURL).method(Request.GET).fetch().as(RestResponse.class).body(); LOGGER.debug(exchangeTitle + " [Jcabi] ticker: " + ticker); }
.fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body(); final String[] sectors = response.split("&"); String token = null;
@Override public long incrementAndGet(final long delta) throws IOException { final long start = System.currentTimeMillis(); final long value = Long.parseLong( this.front("increment").method(Request.GET) .uri().queryParam("value", delta).back() .header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN) .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body() ); Logger.info( this, "counter \"%s\" incremented by %d to %d in %[ms]s", this.label, delta, value, System.currentTimeMillis() - start ); return value; }
.fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK).body(); final String[] sectors = response.split("&"); for (final String sector : sectors) {
.fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK).body(); final String[] sectors = response.split("&"); for (final String sector : sectors) {
@Override public String diff( final String base, final String head) throws IOException { return this.comp.reset(HttpHeaders.ACCEPT) .header(HttpHeaders.ACCEPT, "application/vnd.github.v3.diff") .uri() .path(String.format("%s...%s", base, head)) .back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body(); }
@Override public String patch( final String base, final String head) throws IOException { return this.comp.reset(HttpHeaders.ACCEPT) .header(HttpHeaders.ACCEPT, "application/vnd.github.v3.patch") .uri() .path(String.format("%s...%s", base, head)) .back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body(); }
@Override public String template( final String name) throws IOException { return this.request.reset(HttpHeaders.ACCEPT) .header(HttpHeaders.ACCEPT, "application/vnd.github.v3.raw") .uri().path(name).back().fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .body(); } }
@Override public String render( final JsonObject json) throws IOException { final StringWriter output = new StringWriter(); Json.createWriter(output).writeObject(json); return this.request .body() .set(output.toString()) .back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .assertHeader( HttpHeaders.CONTENT_TYPE, Matchers.everyItem( Matchers.startsWith(MediaType.TEXT_HTML) ) ) .body(); }
@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(); }
@Override public String raw( final String text) throws IOException { return this.request .body() .set(text) .back() .uri().path("raw").back() .reset(HttpHeaders.CONTENT_TYPE) .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN) .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .assertHeader( HttpHeaders.CONTENT_TYPE, Matchers.everyItem( Matchers.startsWith(MediaType.TEXT_HTML) ) ) .body(); }