@Override public RequestBody body() { return this.request.body(); } @Override
/** * Ctor. * @param urn Owner URN * @param token Security token */ public RtSttc(final URN urn, final String token) { this.request = new JdkRequest("http://www.stateful.co") .through(OneMinuteWire.class) .through(RetryWire.class) .through(VerboseWire.class) .through(CachingWire.class, "((POST|PUT|PATCH) .*|.*\\?.*)") .header("X-Sttc-URN", urn.toString()) .header("X-Sttc-Token", token) .header(HttpHeaders.ACCEPT, MediaType.TEXT_XML) .header(HttpHeaders.USER_AGENT, "java-sdk.stateful.co"); }
@Override public void react(final Reaction reaction) throws IOException { final JsonStructure json = Json.createObjectBuilder() .add(RtComment.CONTENT, reaction.type()) .build(); this.request.method(Request.POST) .body().set(json).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK); }
/** * Helper method for merge operations. * @param payload The JSON payload for the merge * @return Response received from GitHub * @throws IOException If there is any I/O problem */ private RestResponse merge(final JsonStructure payload) throws IOException { return this.request.uri() .path("/merge").back() .body().set(payload).back() .method(Request.PUT) .fetch() .as(RestResponse.class); }
@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; }
/** * Get raw release asset content. * * @see <a href="http://developer.github.com/v3/repos/releases/">Releases API</a> * @return Stream with content * @throws IOException If some problem inside. */ @Override public InputStream raw() throws IOException { return new ByteArrayInputStream( this.request.method(Request.GET) .reset(HttpHeaders.ACCEPT).header( HttpHeaders.ACCEPT, "application/vnd.github.v3.raw" ) .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .binary() ); }
/** * Send request and return response. * @param entity The entity to POST * @return The response */ private Request request(final String entity) { return new JdkRequest(this.uri) .method(Request.POST) .body().set(entity).back() .header(HttpHeaders.USER_AGENT, AbstractBaseValidator.USER_AGENT) .header(HttpHeaders.ACCEPT, "application/soap+xml") .header( HttpHeaders.CONTENT_TYPE, Logger.format( "%s; boundary=%s", MediaType.MULTIPART_FORM_DATA, AbstractBaseValidator.BOUNDARY ) ); }
@Override public Request header(final String name, final Object value) { return this.base.header(name, value); }
@Override public String toString() { return this.request.uri().get().toString(); } }
/** * Hide everything from the body but items. * @return Response * @throws IOException If any I/O problem occurs */ @Override public Response fetch() throws IOException { return new RtSearchPagination.Hidden(this.request.fetch()); } @Override
@Override public Request method(final String method) { return new SearchRequest(this.request.method(method)); } @Override
@Override public <T extends Wire> Request through(final Class<T> type, final Object... args) { return this.base.through(type, args); }
@Override public Request reset(final String name) { return this.base.reset(name); }