@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 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 Issue create( final String title, final String body) throws IOException { final JsonStructure json = Json.createObjectBuilder() .add("title", title) .add("body", body) .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("number") ); }
@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 Milestone create( final String title) throws IOException { final JsonStructure json = Json.createObjectBuilder() .add("title", title) .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("number") ); }
@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") ); }
@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 Iterable<String> add( final Iterable<String> emails ) throws IOException { final JsonArrayBuilder json = Json.createArrayBuilder(); for (final String email : emails) { json.add(email); } final List<JsonObject> array = this.request.method(Request.POST) .body().set(json.build()).back() .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_CREATED) .as(JsonResponse.class) .json().readArray().getValuesAs(JsonObject.class); final Collection<String> result = new ArrayList<String>(array.size()); for (final JsonObject obj : array) { result.add(obj.getString("email")); } return result; }
@Override public GistComment 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") ); }
/** * 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 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 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 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 RepoCommit update( final String path, final JsonObject json) throws IOException { return new RtRepoCommit( this.entry, this.owner, this.request.uri().path(path).back() .method(Request.PUT) .body().set(json).back() .fetch() .as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(JsonResponse.class).json() .readObject().getJsonObject("commit").getString("sha") ); }
@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") ) ); }