use of javax.json.JsonStructure in project jcabi-github by jcabi.
the class RtLabels method create.
@Override
public Label create(final String name, final String color) throws IOException {
final JsonStructure json = Json.createObjectBuilder().add("name", name).add("color", color).build();
this.request.method(Request.POST).body().set(json).back().fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_CREATED).as(JsonResponse.class).json();
return new RtLabel(this.entry, this.owner, name);
}
use of javax.json.JsonStructure in project jcabi-github by jcabi.
the class RtHooks method create.
@Override
public Hook create(final String name, final Map<String, String> config, final boolean active) throws IOException {
final JsonObjectBuilder builder = Json.createObjectBuilder();
for (final Map.Entry<String, String> entr : config.entrySet()) {
builder.add(entr.getKey(), entr.getValue());
}
final JsonStructure json = Json.createObjectBuilder().add("name", name).add("config", builder).add("active", active).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"));
}
use of javax.json.JsonStructure in project jcabi-github by jcabi.
the class RtContents method content.
/**
* Get the contents of a file or symbolic link in a repository.
* @param path The content path
* @param ref The name of the commit/branch/tag.
* @return Content fetched
* @throws IOException If there is any I/O problem
* @see <a href="http://developer.github.com/v3/repos/contents/#get-contents">Get contents</a>
*/
private Content content(final String path, final String ref) throws IOException {
final String name = "ref";
RtContent content = null;
final JsonStructure structure = this.request.method(Request.GET).uri().path(path).queryParam(name, ref).back().fetch().as(RestResponse.class).assertStatus(HttpURLConnection.HTTP_OK).as(JsonResponse.class).json().read();
if (JsonValue.ValueType.OBJECT.equals(structure.getValueType())) {
content = new RtContent(this.entry.uri().queryParam(name, ref).back(), this.owner, ((JsonObject) structure).getString("path"));
}
return content;
}
use of javax.json.JsonStructure in project jcabi-github by jcabi.
the class RtGists method create.
@Override
public Gist create(final Map<String, String> files, final boolean visible) throws IOException {
JsonObjectBuilder builder = Json.createObjectBuilder();
for (final Map.Entry<String, String> file : files.entrySet()) {
builder = builder.add(file.getKey(), Json.createObjectBuilder().add("content", file.getValue()));
}
final JsonStructure json = Json.createObjectBuilder().add("files", builder).add("public", visible).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("id"));
}
use of javax.json.JsonStructure in project java-driver by datastax.
the class Jsr353JsonColumn method selectJsonColumn.
// Retrieving JSON objects from a table column
private static void selectJsonColumn(Session session) {
Statement stmt = select().from("examples", "json_jsr353_column").where(in("id", 1, 2));
ResultSet rows = session.execute(stmt);
for (Row row : rows) {
int id = row.getInt("id");
// retrieve the JSON payload and convert it to a JsonObject instance
// note that the codec requires that the type passed to the get() method
// be always JsonStructure, and not a subclass of it, such as JsonObject,
// hence the need to downcast to JsonObject manually
JsonObject user = (JsonObject) row.get("json", JsonStructure.class);
// it is also possible to retrieve the raw JSON payload
String json = row.getString("json");
System.out.printf("Retrieved row:%n" + "id %d%n" + "user %s%n" + "user (raw) %s%n%n", id, user, json);
}
}
Aggregations