use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxZipConflictItem method parseJSONMember.
@Override
void parseJSONMember(JsonObject.Member member) {
JsonValue value = member.getValue();
String memberName = member.getName();
if (memberName.equals("id")) {
this.id = value.asString();
} else if (memberName.equals("type")) {
this.type = value.asString();
} else if (memberName.equals("original_name")) {
this.originalName = value.asString();
} else if (memberName.equals("download_name")) {
this.downloadName = value.asString();
}
}
use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxZipInfo method parseJSONMember.
@Override
void parseJSONMember(JsonObject.Member member) {
JsonValue value = member.getValue();
String memberName = member.getName();
try {
if (memberName.equals("download_url")) {
try {
String urlString = value.asString();
this.downloadURL = new URL(urlString);
} catch (MalformedURLException e) {
throw new BoxAPIException("Couldn't parse download url for zip", e);
}
} else if (memberName.equals("status_url")) {
try {
String urlString = value.asString();
this.statusURL = new URL(urlString);
} catch (MalformedURLException e) {
throw new BoxAPIException("Couldn't parse status url for zip", e);
}
} else if (memberName.equals("expires_at")) {
this.expiresAt = BoxDateFormat.parse(value.asString());
} else if (memberName.equals("name_conflicts")) {
this.nameConflicts = this.parseNameConflicts(value.asArray());
}
} catch (Exception e) {
throw new BoxDeserializationException(memberName, value.toString(), e);
}
}
use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxZipInfo method parseNameConflicts.
private List<BoxZipConflict> parseNameConflicts(JsonArray jsonArray) {
List<BoxZipConflict> nameConflicts = new ArrayList<BoxZipConflict>(jsonArray.size());
for (JsonValue conflict : jsonArray) {
// We create a "conflictObj" with the arbitrary key name "conflict" in order to allow BoxZipConflict
// to later parse the object to create `List<BoxZipConflictItem> items` (since it can't take in an array)
JsonObject conflictObj = new JsonObject().add("conflict", conflict);
nameConflicts.add(new BoxZipConflict(conflictObj));
}
return nameConflicts;
}
use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BatchAPIRequestTest method testThatBodyHasAllRequiredFieldsInEachResponse.
@Test
public void testThatBodyHasAllRequiredFieldsInEachResponse() {
final String anyClientID = "";
final String anyClientSecret = "";
final String anyAccessToken = "";
final String anyRefreshToken = "";
BoxAPIConnection api = new BoxAPIConnection(anyClientID, anyClientSecret, anyAccessToken, anyRefreshToken);
List<BoxAPIRequest> requests = new ArrayList<>();
// Get current user request
URL getMeURL = BoxUser.GET_ME_URL.build(api.getBaseURL());
BoxAPIRequest getMeRequest = new BoxAPIRequest(getMeURL, HttpMethod.GET);
requests.add(getMeRequest);
// Create App User Request
URL createUserURL = BoxUser.USERS_URL_TEMPLATE.build(api.getBaseURL());
BoxJSONRequest createAppUserRequest = new BoxJSONRequest(createUserURL, HttpMethod.POST);
createAppUserRequest.setBody("{\"name\":\"some-name\"," + "\"is_platform_access_only\":true}");
requests.add(createAppUserRequest);
// Get Root Folder Request
URL getRootFolderURL = BoxFolder.FOLDER_INFO_URL_TEMPLATE.build(api.getBaseURL(), 0);
BoxAPIRequest getRootFolderRequest = new BoxAPIRequest(getRootFolderURL, HttpMethod.GET);
requests.add(getRootFolderRequest);
BatchAPIRequest batchRequest = new BatchAPIRequest(api);
batchRequest.prepareRequest(requests);
assertTrue("requests field should be an array", (batchRequest.getBodyAsJsonObject().get("requests").isArray()));
JsonArray requestsArray = batchRequest.getBodyAsJsonObject().get("requests").asArray();
for (JsonValue request : requestsArray) {
assertTrue("each request should be an object", (request.isObject()));
assertTrue("each request should have a relative_url that is string", (((JsonObject) request).get("relative_url").isString()));
assertTrue("each request should have a method that is string", (((JsonObject) request).get("method").isString()));
assertTrue("each request should have headers as object", (((JsonObject) request).get("headers").isObject()));
if (((JsonObject) request).get("method").asString().equals(HttpMethod.POST)) {
assertTrue("request should have body when method is POST", (((JsonObject) request).get("body").isObject()));
}
}
}
use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxZipConflict method parseJSONMember.
@Override
void parseJSONMember(JsonObject.Member member) {
JsonArray value = member.getValue().asArray();
List<BoxZipConflictItem> conflictItems = new ArrayList<BoxZipConflictItem>(value.size());
for (JsonValue item : value) {
conflictItems.add(new BoxZipConflictItem(item.asObject()));
}
this.items = conflictItems;
}
Aggregations