private static JsonObject readMinimizeProfile(PackrConfig config) throws IOException { JsonObject json = null; if (new File(config.minimizeJre).exists()) { json = JsonObject.readFrom(FileUtils.readFileToString(new File(config.minimizeJre))); } else { InputStream in = Packr.class.getResourceAsStream("/minimize/" + config.minimizeJre); if (in != null) { json = JsonObject.readFrom(new InputStreamReader(in)); } } if (json == null && config.verbose) { System.out.println(" # No minimize profile '" + config.minimizeJre + "' found"); } return json; }
private void readConfigJson(File configJson) throws IOException { JsonObject json = JsonObject.readFrom(FileUtils.readFileToString(configJson));
/** * Constructs a BoxJSONObject by decoding it from a JSON string. * @param json the JSON string to decode. */ public BoxJSONObject(String json) { this(JsonObject.readFrom(json)); }
/** * * @return a copy of the json object backing this object. */ public JsonObject toJsonObject() { return JsonObject.readFrom(toJson()); }
/** * Serializes a json blob into a BoxJsonObject. * * @param json json blob to deserialize. */ public void createFromJson(String json) { createFromJson(JsonObject.readFrom(json)); }
public void setSkypeToken(String skypeToken) { this.skypeToken = skypeToken; String[] data = skypeToken.split("\\."); JsonObject object = JsonObject.readFrom( new String(Base64.getDecoder().decode(data[1]), StandardCharsets.UTF_8)); this.skypeTokenExpiryTime = object.get("exp").asLong() * 1000; }
/** * Gets information about this group membership. * @return info about this group membership. */ public Info getInfo() { BoxAPIConnection api = this.getAPI(); URL url = INVITE_URL_TEMPLATE.build(api.getBaseURL(), this.getID()); BoxAPIRequest request = new BoxAPIRequest(api, url, "GET"); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); return new Info(jsonObject); }
@Test public void testTrashFileRequest() throws Exception { { final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID + "/trash"; BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); BoxRequestsFile.GetTrashedFile trashedFileRequest = fileApi.getTrashedFileRequest(FILE_ID); mockSuccessResponseWithJson(SAMPLE_FILE_JSON); BoxFile boxFile = trashedFileRequest.send(); Assert.assertEquals(expectedRequestUrl, trashedFileRequest.mRequestUrlString); Assert.assertEquals(JsonObject.readFrom(SAMPLE_FILE_JSON), boxFile.toJsonObject()); } }
@Test public void testMockCreateEnterpriseUserRequest() throws Exception { final String expectedRequestUrl = "https://api.box.com/2.0/users"; BoxApiUser userApi = new BoxApiUser(SessionUtil.newMockBoxSession(mMockContext)); BoxRequestsUser.CreateEnterpriseUser userInfoRequest = userApi.getCreateEnterpriseUserRequest("ariellefrey@box.com", "Arielle Frey"); mockSuccessResponseWithJson(SAMPLE_USER_JSON); BoxUser boxUser = userInfoRequest.send(); Assert.assertEquals(expectedRequestUrl, userInfoRequest.mRequestUrlString); Assert.assertEquals(JsonObject.readFrom(SAMPLE_USER_JSON), boxUser.toJsonObject()); }
@Test public void testFolderInfoRequest() throws Exception { final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID; BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); BoxRequestsFolder.GetFolderInfo folderInfo = folderApi.getInfoRequest(FOLDER_ID); mockSuccessResponseWithJson(SAMPLE_FOLDER_JSON); BoxFolder boxFolder = folderInfo.send(); Assert.assertEquals(expectedRequestUrl, folderInfo.mRequestUrlString); Assert.assertEquals(JsonObject.readFrom(SAMPLE_FOLDER_JSON), boxFolder.toJsonObject()); }
/** * @return information about this {@link BoxCollaborationWhitelist}. */ public BoxCollaborationWhitelist.Info getInfo() { URL url = COLLABORATION_WHITELIST_ENTRY_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, HttpMethod.GET); BoxJSONResponse response = (BoxJSONResponse) request.send(); return new Info(JsonObject.readFrom(response.getJSON())); }
/** * @return Gets information about this {@link BoxTermsOfService}. */ public BoxTermsOfService.Info getInfo() { URL url = TERMS_OF_SERVICE_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); BoxJSONResponse response = (BoxJSONResponse) request.send(); return new Info(JsonObject.readFrom(response.getJSON())); }
/** * Gets information about this task assignment. * @return info about this task assignment. */ public Info getInfo() { URL url = TASK_ASSIGNMENT_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); return new Info(responseJSON); }
@Test public void testGetEnterpriseUsersRequest() throws Exception { final String expectedRequestUrl = "https://api.box.com/2.0/users"; final String enterpriseUsersJson = "{ \"total_count\": 1, \"entries\": [ { \"type\": \"user\", \"id\": \"181216415\", \"name\": \"sean rose\", \"login\": \"sean+awesome@box.com\", \"created_at\": \"2012-05-03T21:39:11-07:00\", \"modified_at\": \"2012-08-23T14:57:48-07:00\", \"language\": \"en\", \"space_amount\": 5368709120, \"space_used\": 52947, \"max_upload_size\": 104857600, \"status\": \"active\", \"job_title\": \"\", \"phone\": \"5555551374\", \"address\": \"10 Cloud Way Los Altos CA\", \"avatar_url\": \"https://app.box.com/api/avatar/large/181216415\" } ] }"; BoxApiUser userApi = new BoxApiUser(SessionUtil.newMockBoxSession(mMockContext)); BoxRequestsUser.GetEnterpriseUsers enterpriseUsersRequest = userApi.getEnterpriseUsersRequest(); mockSuccessResponseWithJson(enterpriseUsersJson); BoxIteratorUsers boxUsers = enterpriseUsersRequest.send(); Assert.assertEquals(expectedRequestUrl, enterpriseUsersRequest.mRequestUrlString); Assert.assertEquals(JsonObject.readFrom(enterpriseUsersJson), boxUsers.toJsonObject()); }
@Test public void testCopyFolderRequest() throws Exception { final String expectedRequestUrl = "https://api.box.com/2.0/folders/" + FOLDER_ID + "/copy" ; BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); BoxRequestsFolder.CopyFolder copyRequest = folderApi.getCopyRequest( FOLDER_ID, "0"); mockSuccessResponseWithJson(SAMPLE_FOLDER_JSON); BoxFolder boxFolder = copyRequest.send(); Assert.assertEquals(expectedRequestUrl, copyRequest.mRequestUrlString); Assert.assertEquals(JsonObject.readFrom(SAMPLE_FOLDER_JSON), boxFolder.toJsonObject()); }
@Test public void testGetTrashedItems() throws Exception { final String expectedRequestUrl = "https://api.box.com/2.0/folders/trash/items" ; final String trashedItemsJson = "{ \"total_count\": 49542, \"entries\": [ { \"type\": \"file\", \"id\": \"2701979016\", \"sequence_id\": \"1\", \"etag\": \"1\", \"sha1\": \"9d976863fc849f6061ecf9736710bd9c2bce488c\", \"name\": \"file Tue Jul 24 145436 2012KWPX5S.csv\" }, { \"type\": \"file\", \"id\": \"2698211586\", \"sequence_id\": \"1\", \"etag\": \"1\", \"sha1\": \"09b0e2e9760caf7448c702db34ea001f356f1197\", \"name\": \"file Tue Jul 24 010055 20129Z6GS3.csv\" } ], \"offset\": 0, \"limit\": 2 }"; BoxApiFolder folderApi = new BoxApiFolder(SessionUtil.newMockBoxSession(mMockContext)); BoxRequestsFolder.GetTrashedItems trashedItemsRequest = folderApi.getTrashedItemsRequest( ); mockSuccessResponseWithJson(trashedItemsJson); BoxIteratorItems boxItems = trashedItemsRequest.send(); Assert.assertEquals(expectedRequestUrl, trashedItemsRequest.mRequestUrlString); Assert.assertEquals(JsonObject.readFrom(trashedItemsJson), boxItems.toJsonObject()); }
@Test public void testUserInfoRequest() throws Exception { final String expectedRequestUrl = "https://api.box.com/2.0/users/" + USER_ID; BoxApiUser userApi = new BoxApiUser(SessionUtil.newMockBoxSession(mMockContext)); BoxRequestsUser.GetUserInfo userInfoRequest = userApi.getUserInfoRequest(USER_ID); mockSuccessResponseWithJson(SAMPLE_USER_JSON); BoxUser boxUser = userInfoRequest.send(); Assert.assertEquals(expectedRequestUrl, userInfoRequest.mRequestUrlString); Assert.assertEquals(JsonObject.readFrom(SAMPLE_USER_JSON), boxUser.toJsonObject()); }
@Test public void testFileInfoRequest() throws Exception { final String expectedRequestUrl = "https://api.box.com/2.0/files/" + FILE_ID; BoxApiFile fileApi = new BoxApiFile(SessionUtil.newMockBoxSession(mMockContext)); BoxRequestsFile.GetFileInfo fileInfoRequest = fileApi.getInfoRequest(FILE_ID); fileInfoRequest.setFields(BoxFile.ALL_FIELDS); mockSuccessResponseWithJson(SAMPLE_FILE_JSON); BoxFile boxFile = fileInfoRequest.send(); Assert.assertEquals(expectedRequestUrl, fileInfoRequest.mRequestUrlString); Assert.assertEquals(JsonObject.readFrom(SAMPLE_FILE_JSON), boxFile.toJsonObject()); }
/** * Updates the information about this group with any info fields that have been modified locally. * @param info the updated info. */ public void updateInfo(BoxGroup.Info info) { URL url = GROUP_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT"); request.setBody(info.getPendingChanges()); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); info.update(jsonObject); }
private BoxFileUploadSession.Info createUploadSession(BoxAPIConnection boxApi, URL url, long fileSize) { BoxJSONRequest request = new BoxJSONRequest(boxApi, url, HttpMethod.POST); //Creates the body of the request JsonObject body = new JsonObject(); body.add("file_size", fileSize); request.setBody(body.toString()); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); String sessionId = jsonObject.get("id").asString(); BoxFileUploadSession session = new BoxFileUploadSession(boxApi, sessionId); return session.new Info(jsonObject); }