use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxCollaboration method getPendingCollaborations.
/**
* Gets all pending collaboration invites for the current user.
*
* @param api the API connection to use.
* @return a collection of pending collaboration infos.
*/
public static Collection<Info> getPendingCollaborations(BoxAPIConnection api) {
URL url = PENDING_COLLABORATIONS_URL.build(api.getBaseURL());
BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
int entriesCount = responseJSON.get("total_count").asInt();
Collection<BoxCollaboration.Info> collaborations = new ArrayList<>(entriesCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue entry : entries) {
JsonObject entryObject = entry.asObject();
BoxCollaboration collaboration = new BoxCollaboration(api, entryObject.get("id").asString());
BoxCollaboration.Info info = collaboration.new Info(entryObject);
collaborations.add(info);
}
return collaborations;
}
use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxTermsOfService method getAllTermsOfServices.
/**
* Retrieves a list of Terms of Service that belong to your Enterprise as an Iterable.
*
* @param api api the API connection to be used by the resource.
* @param termsOfServiceType the type of terms of service to be retrieved. Can be set to "managed" or "external"
* @return the Iterable of Terms of Service in an Enterprise that match the filter parameters.
*/
public static List<BoxTermsOfService.Info> getAllTermsOfServices(final BoxAPIConnection api, BoxTermsOfService.TermsOfServiceType termsOfServiceType) {
QueryStringBuilder builder = new QueryStringBuilder();
if (termsOfServiceType != null) {
builder.appendParam("tos_type", termsOfServiceType.toString());
}
URL url = ALL_TERMS_OF_SERVICES_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), builder.toString());
BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
int totalCount = responseJSON.get("total_count").asInt();
List<BoxTermsOfService.Info> termsOfServices = new ArrayList<>(totalCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue value : entries) {
JsonObject termsOfServiceJSON = value.asObject();
BoxTermsOfService termsOfService = new BoxTermsOfService(api, termsOfServiceJSON.get("id").asString());
BoxTermsOfService.Info info = termsOfService.new Info(termsOfServiceJSON);
termsOfServices.add(info);
}
return termsOfServices;
}
use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxTask method getAssignments.
/**
* Gets any assignments for this task.
*
* @return a list of assignments for this task.
*/
public List<BoxTaskAssignment.Info> getAssignments() {
URL url = GET_ASSIGNMENTS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
int totalCount = responseJSON.get("total_count").asInt();
List<BoxTaskAssignment.Info> assignments = new ArrayList<>(totalCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue value : entries) {
JsonObject assignmentJSON = value.asObject();
BoxTaskAssignment assignment = new BoxTaskAssignment(this.getAPI(), assignmentJSON.get("id").asString());
BoxTaskAssignment.Info info = assignment.new Info(assignmentJSON);
assignments.add(info);
}
return assignments;
}
use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxRecentItem method parseJSONMember.
@Override
protected void parseJSONMember(JsonObject.Member member) {
super.parseJSONMember(member);
String memberName = member.getName();
JsonValue value = member.getValue();
try {
if (memberName.equals("type")) {
this.type = value.asString();
} else if (memberName.equals("interaction_type")) {
this.interactionType = value.asString();
} else if (memberName.equals("item")) {
String id = value.asObject().get("id").asString();
this.item = new BoxFile(this.api, id).new Info(value.asObject());
} else if (memberName.equals("interacted_at")) {
this.interactedAt = BoxDateFormat.parse(value.asString());
} else if (memberName.equals("interaction_shared_link")) {
this.interactionSharedLink = new URL(value.asString());
}
} catch (ParseException e) {
assert false : "A ParseException indicates a bug in the SDK.";
} catch (MalformedURLException e) {
assert false : "A ParseException indicates a bug in the SDK.";
}
}
use of com.eclipsesource.json.JsonValue in project box-java-sdk by box.
the class BoxSearch method searchRangeIncludeSharedLinks.
/**
* Searches all descendant folders using a given query and query parameters.
*
* @param offset is the starting position.
* @param limit the maximum number of items to return. The default is 30 and the maximum is 200.
* @param bsp containing query and advanced search capabilities.
* @return a PartialCollection containing the search results.
*/
public PartialCollection<BoxSearchSharedLink> searchRangeIncludeSharedLinks(long offset, long limit, final BoxSearchParameters bsp) {
QueryStringBuilder builder = bsp.getQueryParameters().appendParam("include_recent_shared_links", "true").appendParam("limit", limit).appendParam("offset", offset);
URL url = SEARCH_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), builder.toString());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
String totalCountString = responseJSON.get("total_count").toString();
long fullSize = Double.valueOf(totalCountString).longValue();
PartialCollection<BoxSearchSharedLink> results = new PartialCollection<>(offset, limit, fullSize);
JsonArray jsonArray = responseJSON.get("entries").asArray();
for (JsonValue value : jsonArray) {
JsonObject jsonObject = value.asObject();
BoxSearchSharedLink parsedItem = new BoxSearchSharedLink(jsonObject, this.getAPI());
results.add(parsedItem);
}
return results;
}
Aggregations