@Override public void react(final Reaction reaction) throws IOException { final JsonStructure json = Json.createObjectBuilder() .add(RtIssue.CONTENT, reaction.type()) .build(); this.request.method(Request.POST) .body().set(json).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK); }
@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); }
@Override public void lock(final String reason) { final JsonStructure json = Json.createObjectBuilder() .add("lock_reason", reason) .build(); try { this.request.method(Request.PUT).uri().path("/lock").back() .body().set(json).back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_NO_CONTENT); } catch (final IOException error) { throw new IllegalStateException(error); } }
/** * Patch it. * @param json JSON to use for patching * @throws IOException If fails */ public void patch( final JsonObject json ) throws IOException { final StringWriter post = new StringWriter(); Json.createWriter(post).writeObject(json); this.request.body().set(post.toString()).back() .method(Request.PATCH) .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK); }
@Override public boolean lock(final String label) throws IOException { final long start = System.currentTimeMillis(); final Response rsp = this.front("lock") .body().formParam("label", label) .formParam("name", this.lck).back() .method(Request.POST) .fetch(); final boolean locked = rsp.status() == HttpURLConnection.HTTP_SEE_OTHER; Logger.info( this, "lock of \"%s\" is %B in %[ms]s: %s", this.lck, locked, System.currentTimeMillis() - start, rsp.body() ); return locked; }
@Override public Reference create( final String ref, final String sha ) throws IOException { final JsonObject json = Json.createObjectBuilder() .add("sha", sha).add(RtReferences.REF, ref).build(); return this.get( this.request.method(Request.POST) .body().set(json).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_CREATED) .as(JsonResponse.class) .json().readObject().getString(RtReferences.REF) ); }
@Override public Fork create( final String organization) throws IOException { final JsonStructure json = Json.createObjectBuilder() .add("organization", organization) .build(); return this.get( this.request.method(Request.POST) .body().set(json).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_ACCEPTED) .as(JsonResponse.class) .json().readObject().getInt(ID) ); }
@Override public Comment post(final String text) throws IOException { final JsonStructure json = Json.createObjectBuilder() .add("body", text) .build(); return this.get( this.request.method(Request.POST) .body().set(json).back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_CREATED) .as(JsonResponse.class) // @checkstyle MultipleStringLiterals (1 line) .json().readObject().getInt("id") ); }
@Override public Release create( final String tag ) throws IOException { final JsonStructure json = Json.createObjectBuilder() .add("tag_name", tag) .build(); return this.get( this.request.method(Request.POST) .body().set(json).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_CREATED) .as(JsonResponse.class) .json().readObject().getInt("id") ); }
/** * 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 void remove(final Iterable<String> emails) throws IOException { final JsonArrayBuilder json = Json.createArrayBuilder(); for (final String email : emails) { json.add(email); } this.request.method(Request.DELETE) .body().set(json.build()).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_NO_CONTENT); }
@Override public void post(final String text) throws IOException { this.request.fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(XmlResponse.class) .rel("/page/links/link[@rel='post']/@href") .method(Request.POST) .body().formParam("text", text).back() .fetch(); Logger.info(this, "message posted"); }
@Override public Commit create( final JsonObject params ) throws IOException { return this.get( this.request.method(Request.POST) .body().set(params).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_CREATED) .as(JsonResponse.class) .json().readObject().getString("sha") ); }
@Override public Tree create( final JsonObject params ) throws IOException { return this.get( this.request.method(Request.POST) .body().set(params).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_CREATED) .as(JsonResponse.class) .json().readObject().getString("sha") ); } }
@Override public void add(final Iterable<String> labels) throws IOException { JsonArrayBuilder builder = Json.createArrayBuilder(); for (final String label : labels) { builder = builder.add(label); } final JsonStructure json = builder.build(); this.request.method(Request.POST) .body().set(json).back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(JsonResponse.class) .json().readArray(); }
@Override public void create(final String name) throws IOException { this.request.fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(XmlResponse.class) .rel("/page/links/link[@rel='create']/@href") .method(Request.POST) .body().formParam("name", name).back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_SEE_OTHER); Logger.info(this, "attachment '%s' created", name); }
@Override public void rename(final String text) throws IOException { this.request.fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(XmlResponse.class) .rel("/page/links/link[@rel='rename']/@href") .method(Request.POST) .body().formParam("title", text).back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_SEE_OTHER); Logger.info(this, "bout #%d renamed", this.num); }
@Override public void replace(final Iterable<String> labels) throws IOException { JsonArrayBuilder builder = Json.createArrayBuilder(); for (final String label : labels) { builder = builder.add(label); } final JsonStructure json = builder.build(); this.request.method(Request.PUT) .body().set(json).back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(JsonResponse.class) .json().readArray(); }
@Override public void email(final String email) throws IOException { this.request.fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(XmlResponse.class) .rel("/page/links/link[@rel='account']/@href") .fetch() .as(XmlResponse.class) .rel("/page/links/link[@rel='save-email']/@href") .method(Request.POST) .body().formParam("email", email).back() .fetch(); Logger.info(this, "email changed"); }
@Override public Repo create(final RepoCreate settings) throws IOException { return this.get( new Coordinates.Simple( this.entry.uri().path("user/repos") .back().method(Request.POST) .body().set(settings.json()).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_CREATED) .as(JsonResponse.class) // @checkstyle MultipleStringLiterals (1 line) .json().readObject().getString("full_name") ) ); }