Skip to content

Commit 5a90713

Browse files
authored
Merge pull request #70 from dp3000/add-support-for-bookmarks
Add support for bookmarks
2 parents b6d5952 + cbfb57f commit 5a90713

18 files changed

+949
-76
lines changed

doc/files.md

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
Files
2-
=====
1+
# Files
32

43
File objects represent individual files in Box. They can be used to download a
54
file's contents, upload new versions, and perform other common file operations
65
(move, copy, delete, etc.).
76

8-
* [Get a File's Information](#get-a-files-information)
9-
* [Update a File's Information](#update-a-files-information)
10-
* [Upload a File](#upload-a-file)
11-
* [Copy a File](#copy-a-file)
12-
* [Delete a File](#delete-a-file)
13-
* [Get Previous Versions of a File](#get-previous-versions-of-a-file)
14-
* [Promote a Previous Version of a File](#promote-a-previous-version-of-a-file)
15-
* [Delete a Previous Version of a File](#delete-a-previous-version-of-a-file)
7+
- [Get a File's Information](#get-a-files-information)
8+
- [Update a File's Information](#update-a-files-information)
9+
- [Upload a File](#upload-a-file)
10+
- [Copy a File](#copy-a-file)
11+
- [Delete a File](#delete-a-file)
12+
- [Get Previous Versions of a File](#get-previous-versions-of-a-file)
13+
- [Promote a Previous Version of a File](#promote-a-previous-version-of-a-file)
14+
- [Delete a Previous Version of a File](#delete-a-previous-version-of-a-file)
1615

17-
Get a File's Information
18-
------------------------
16+
## Get a File's Information
1917

2018
Calling `getFileInfo()` on a file returns a snapshot of the file's info.
2119

@@ -24,24 +22,22 @@ BoxFile file = new BoxFile(api, 'file-id');
2422
BoxFile.Info info = file.getFileInfo();
2523
```
2624

27-
Update a File's Information
28-
---------------------------
25+
## Update a File's Information
2926

3027
Updating a file's information is done by creating a new `BoxFile.Info`
3128
object or updating an existing one, and then calling `updateFileInfo(BoxFile.Info)`.
3229

3330
```java
3431
BoxFile file = new BoxFile(api, 'file-id');
35-
BoxFile.Info info = new BoxFile.Info();
32+
BoxFile.Info info = file.getFileInfo();
3633
info.addValue('name', 'New_File_Name.jpg');
3734
BoxFile.Info newFileInfo = file.updateFileInfo(info);
3835
```
3936

40-
Upload a File
41-
-------------
37+
## Upload a File
4238

4339
Files are uploaded to a folder by calling either the `uploadFile(Attachment, String)`
44-
or `uploadFile(Document, String)` method. If the `newName` String parameter is blank,
40+
or `uploadFile(Document, String)` method. If the `newName` String parameter is blank,
4541
the name of the Attachment or Document is used.
4642

4743
```java
@@ -54,8 +50,7 @@ Upload progress can be tracked by providing the size of the file and a
5450
[`uploadFile(InputStream, String, long, ProgressListener)`][upload2]. The
5551
`ProgressListener` will then receive progress updates as the upload completes.
5652

57-
Copy a File
58-
-----------
53+
## Copy a File
5954

6055
A file can be copied to a new folder and optionally be renamed with the
6156
`copy(BoxFolder)` and `copy(BoxFolder, String)` methods.
@@ -66,8 +61,7 @@ BoxFile file = new BoxFile(api, 'file-id');
6661
BoxFile.Info copiedFileInfo = file.copy(rootFolder, 'New Name');
6762
```
6863

69-
Delete a File
70-
-------------
64+
## Delete a File
7165

7266
Calling the `deleteFile()` method will move the file to the user's trash.
7367

@@ -76,8 +70,7 @@ BoxFile file = new BoxFile(api, 'file-id');
7670
file.deleteFile();
7771
```
7872

79-
Get a trashed File
80-
------------------
73+
## Get a trashed File
8174

8275
Calling the `getTrashedFile()` method will retrieve a trashed file to the user including
8376
information about when the file was moved to the trash.
@@ -87,8 +80,7 @@ BoxFile file = new BoxFile(api, 'file-id');
8780
file.getTrashedFile();
8881
```
8982

90-
Get Previous Versions of a File
91-
-------------------------------
83+
## Get Previous Versions of a File
9284

9385
For users with premium accounts, versions of a file can be retrieved with the
9486
`getVersions()` method.
@@ -98,11 +90,10 @@ BoxFile file = new BoxFile(api, 'file-id');
9890
list<BoxFileVersion.Info> versions = file.getVersions();
9991
```
10092

101-
Promote a Previous Version of a File
102-
------------------------------------
93+
## Promote a Previous Version of a File
10394

10495
A previous version of a file can be promoted with the `promoteFileVersion()`
105-
method to become the current version of the file. Since the `file_version` object returned
96+
method to become the current version of the file. Since the `file_version` object returned
10697
from the Box API doesn't include the File Id, you must set it manually before promoting a
10798
file version.
10899

@@ -114,8 +105,7 @@ firstVersion.setFileId('file-id');
114105
firstVersion.promoteFileVersion();
115106
```
116107

117-
Delete a Previous Version of a File
118-
-----------------------------------
108+
## Delete a Previous Version of a File
119109

120110
A version of a file can be deleted and moved to the trash by calling
121111
`deleteFileVersion()`. Since the `file_version` object returned

doc/folders.md

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
Folders
2-
=======
1+
# Folders
32

43
Folder objects represent a folder from a user's account. They can be used to
54
iterate through a folder's contents, collaborate a folder with another user or
65
group, and perform other common folder operations (move, copy, delete, etc.).
76

8-
* [Get the User's Root Folder](#get-the-users-root-folder)
9-
* [Get a Folder's Items](#get-a-folders-items)
10-
* [Get a Folder's Information](#get-a-folders-information)
11-
* [Update a Folder's Information](#update-a-folders-information)
12-
* [Create a Folder](#create-a-folder)
13-
* [Copy a Folder](#copy-a-folder)
14-
* [Move a Folder](#move-a-folder)
15-
* [Rename a Folder](#rename-a-folder)
16-
* [Delete a Folder](#delete-a-folder)
17-
* [Created a Shared Link for a Folder](#created-a-shared-link-for-a-folder)
18-
* [Share a Folder](#share-a-folder)
19-
* [Get All Collaborations for a Folder](#get-all-collaborations-for-a-folder)
20-
21-
Get the User's Root Folder
22-
--------------------------
7+
- [Get the User's Root Folder](#get-the-users-root-folder)
8+
- [Get a Folder's Items](#get-a-folders-items)
9+
- [Get a Folder's Information](#get-a-folders-information)
10+
- [Update a Folder's Information](#update-a-folders-information)
11+
- [Create a Folder](#create-a-folder)
12+
- [Copy a Folder](#copy-a-folder)
13+
- [Move a Folder](#move-a-folder)
14+
- [Rename a Folder](#rename-a-folder)
15+
- [Delete a Folder](#delete-a-folder)
16+
- [Created a Shared Link for a Folder](#created-a-shared-link-for-a-folder)
17+
- [Share a Folder](#share-a-folder)
18+
- [Get All Collaborations for a Folder](#get-all-collaborations-for-a-folder)
19+
20+
## Get the User's Root Folder
2321

2422
The user's root folder can be accessed with the static
2523
`getRootFolder(BoxAPIConnection)` method.
@@ -28,12 +26,11 @@ The user's root folder can be accessed with the static
2826
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
2927
```
3028

31-
Get a Folder's Items
32-
--------------------
29+
## Get a Folder's Items
3330

34-
A call to `getChildren()` will return the contents of a `BoxFolder`. Optionally, an offset and limit
31+
A call to `getChildren()` will return the contents of a `BoxFolder`. Optionally, an offset and limit
3532
can be set to iterate over a large folder. Large folder operations will likely
36-
fail due to governor limits on callouts or heap size. This method could be detrimental depending
33+
fail due to governor limits on callouts or heap size. This method could be detrimental depending
3734
on your use case.
3835

3936
```java
@@ -48,8 +45,7 @@ for (BoxItem.Info itemInfo : children) {
4845
}
4946
```
5047

51-
Get a Folder's Information
52-
--------------------------
48+
## Get a Folder's Information
5349

5450
Calling `getFolderInfo()` on a folder returns a snapshot of the folder's
5551
info.
@@ -59,22 +55,20 @@ BoxFolder folder = new BoxFolder(api, 'folder-id');
5955
BoxFolder.Info info = folder.getFolderInfo();
6056
```
6157

62-
Update a Folder's Information
63-
-----------------------------
58+
## Update a Folder's Information
6459

6560
Updating a folder's information is done by creating a new `BoxFolder.Info`
6661
object or updating an existing one, and then calling
6762
`updateFolderInfo(BoxFolder.Info)`.
6863

6964
```java
7065
BoxFolder folder = new BoxFolder(api, 'folder-id');
71-
BoxFolder.Info info = folder.new Info();
66+
BoxFolder.Info info = folder.getFolderInfo();
7267
info.addValue('description', 'Some folder I made');
7368
folder.updateFolderInfo(info);
7469
```
7570

76-
Create a Folder
77-
---------------
71+
## Create a Folder
7872

7973
Create a child folder by calling `createFolder(String)` on the
8074
parent folder.
@@ -84,8 +78,7 @@ BoxFolder parentFolder = new BoxFolder(api, 'parent-folder-id');
8478
BoxFolder.Info childFolderInfo = parentFolder.createFolder('Child Folder Name');
8579
```
8680

87-
Copy a Folder
88-
-------------
81+
## Copy a Folder
8982

9083
Call the `copy(BoxFolder)` method to copy a folder to another folder.
9184

@@ -105,8 +98,7 @@ BoxFolder destination = new BoxFolder(api, 'destination-folder-id');
10598
folder.copy(destination, 'New Folder Name');
10699
```
107100

108-
Move a Folder
109-
-------------
101+
## Move a Folder
110102

111103
Call the `move(BoxFolder)` method with the destination you want the folder moved
112104
to.
@@ -119,8 +111,7 @@ folder.move(destination);
119111

120112
Similar to the `copy` method, the folder can be renamed by calling `move(BoxFolder, String)`.
121113

122-
Rename a Folder
123-
---------------
114+
## Rename a Folder
124115

125116
Call the `rename(String)` method with a new name for the folder.
126117

@@ -141,8 +132,7 @@ info.addValue('name', 'New Folder Name');
141132
folder.updateFolderInfo(info);
142133
```
143134

144-
Delete a Folder
145-
---------------
135+
## Delete a Folder
146136

147137
A folder can be deleted with the `deleteFolder(boolean)` method. Passing
148138
true to this method indicates that the folder and its contents should be
@@ -153,8 +143,7 @@ BoxFolder folder = new BoxFolder(api, 'folder-id');
153143
folder.deleteFolder(true);
154144
```
155145

156-
Created a Shared Link for a Folder
157-
----------------------------------
146+
## Created a Shared Link for a Folder
158147

159148
You can get a shared link for a folder by calling the
160149
`createSharedLink(BoxSharedLink.Access, DateTime, BoxSharedLink.Permissions)` method.
@@ -165,12 +154,11 @@ BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();
165154
BoxSharedLink.Info linkInfo = folder.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions);
166155
```
167156

168-
Share a Folder
169-
--------------
157+
## Share a Folder
170158

171159
You can invite another person to collaborate on a folder with the
172160
[collaborate(String, BoxCollaboration.Role)` method. The Box user with the email address
173-
specified will receive a collaboration request. If the email is not associated with a Box
161+
specified will receive a collaboration request. If the email is not associated with a Box
174162
account, an invitation to create a Box account will be sent.
175163

176164
```java
@@ -188,8 +176,7 @@ BoxFolder folder = new BoxFolder(api, 'folder-id');
188176
BoxCollaboration.Info collabInfo = folder.collaborate(collaborator, BoxCollaboration.Role.EDITOR);
189177
```
190178

191-
Get All Collaborations for a Folder
192-
-----------------------------------
179+
## Get All Collaborations for a Folder
193180

194181
The `getCollaborations()` method will return a list
195182
of `BoxCollaboration.Info` objects for a folder.

doc/web-links.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Web Links
2+
3+
Represents a web link (bookmark) on Box
4+
5+
## Get a Web Link's Information
6+
7+
```java
8+
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
9+
BoxWebLink.Info info = webLink.getWebLinkInfo();
10+
```
11+
12+
## Create a Web Link
13+
14+
```java
15+
BoxWebLink webLink = new BoxWebLink(api, null);
16+
BoxWebLink.Info info = new BoxWebLink.Info('{"url":"https://www.salesforce.com/", "parent": {"id": "0"}, "name": "Salesforce", "description": "Link to Salesforce"}');
17+
BoxWebLink.Info created = webLink.createWebLink(info);
18+
```
19+
20+
## Update a Web Link's Information
21+
22+
```java
23+
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
24+
BoxWebLink.Info info = webLink.getWebLinkInfo();
25+
info.addValue('description', 'a descriptive description');
26+
BoxWebLink.Info updated = webLink.updateWebLinkInfo(info);
27+
```
28+
29+
## Delete a Web Link
30+
31+
```java
32+
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
33+
webLink.deleteWebLink();
34+
```
35+
36+
## Get a Trashed Web Link's Information
37+
38+
```java
39+
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
40+
BoxWebLink.Info info = webLink.getTrashedWebLinkInfo();
41+
```
42+
43+
## Restore a Trashed Web Link
44+
45+
```java
46+
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
47+
BoxWebLink.Info info = webLink.restoreTrashedWebLink();
48+
```
49+
50+
## Permanently Delete a Web Link
51+
52+
```java
53+
BoxWebLink webLink = new BoxWebLink(api, 'web-link-id');
54+
webLink.permanentlyDeleteWebLink();
55+
```

src/classes/BoxFolderTests.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ public class BoxFolderTests {
101101

102102
public static testMethod void testGetObjectType() {
103103
BoxApiConnection api = new BoxApiConnection('accesstoken');
104-
BoxFolder folder = new BoxFolder(api, 'folderid');
104+
BoxFolder folder = new BoxFolder(api, '11446498');
105105
System.assertEquals('folder', folder.getObjectType());
106106
}
107107

108108
public static testMethod void testSetInfo() {
109109
String mockResponseBody = '{"type":"folder","id":"11446498","sequence_id":"1","etag":"1","name":"Pictures","created_at":"2012-12-12T10:53:43-08:00","modified_at":"2012-12-12T11:15:04-08:00","description":"Some pictures I took","size":629644,"path_collection":{"total_count":1,"entries":[{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"}]},"created_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"modified_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"owned_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"shared_link":{"url":"https://www.box.com/s/vspke7y05sb214wjokpk","download_url":null,"vanity_url":null,"is_password_enabled":false,"unshared_at":null,"download_count":0,"preview_count":0,"access":"open","permissions":{"can_download":true,"can_preview":true}},"folder_upload_email":{"access":"open","email":"[email protected]"},"parent":{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"},"item_status":"active","item_collection":{"total_count":1,"entries":[{"type":"file","id":"5000948880","sequence_id":"3","etag":"3","sha1":"134b65991ed521fcfe4724b7d814ab8ded5185dc","name":"tigers.jpeg"}],"offset":0,"limit":100}}';
110110
BoxApiConnection api = new BoxApiConnection('accesstoken');
111-
BoxFolder folder = new BoxFolder(api, 'All Files');
111+
BoxFolder folder = new BoxFolder(api, '11446498');
112112
BoxFolder.Info subfolderInfo = new BoxFolder.Info(mockResponseBody);
113113
BoxFolder.Info parentFolderInfo = new BoxFolder.Info(
114114
subfolderInfo.getValue('parent')

src/classes/BoxResource.cls

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public abstract class BoxResource {
2121
*/
2222
public BoxResource(BoxApiConnection api, String id) {
2323
this.api = api;
24+
validateId(id);
2425
this.id = id;
2526
}
2627

@@ -96,6 +97,20 @@ public abstract class BoxResource {
9697
return (BoxResource.Info) information;
9798
}
9899

100+
/**
101+
* Validates the ID of this resource.
102+
*
103+
* @return void
104+
*/
105+
private void validateId(String id) {
106+
if (String.isNotEmpty(id)) {
107+
System.assert(
108+
id.isNumeric(),
109+
'Expect resource to be constructed with a numeric ID'
110+
);
111+
}
112+
}
113+
99114
public abstract void setInfo(BoxJsonObject jsonObject);
100115

101116
public abstract String getObjectType();

0 commit comments

Comments
 (0)