Skip to content

Commit dccd067

Browse files
committed
Merge branch 'dev'
Release v0.4
2 parents dde7c5f + ce47951 commit dccd067

23 files changed

+719
-176
lines changed

README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Project Status](http://opensource.box.com/badges/active.svg)](http://opensource.box.com/badges)
2+
13
Box Java SDK
24
============
35

@@ -9,18 +11,45 @@ to this SDK.
911
Quickstart
1012
----------
1113

14+
The SDK can be obtained by either cloning the source into your project, or by
15+
downloading one of the precompiled JARs from the [releases page on GitHub]
16+
(https://gitenterprise.inside-box.net/Box/box-java-sdk/releases).
17+
18+
If you use the JAR, you'll also need to include [minimal-json v0.9.1]
19+
(https://github.com/ralfstx/minimal-json) - which is the SDK's only dependency.
20+
You can get minimal-json from maven with `com.eclipsesource.minimal-json:minimal-json:0.9.1`.
21+
1222
Here is a simple example of how to authenticate with the API using a developer
1323
token and then print the ID and name of each item in your root folder.
1424

1525
```java
1626
BoxAPIConnection api = new BoxAPIConnection("developer-token");
1727
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
18-
for (BoxItem item : rootFolder) {
19-
BoxItem.Info info = item.getInfo();
20-
System.out.format("[%d] %s\n", item.getID(), info.getName());
28+
for (BoxItem.Info itemInfo : rootFolder) {
29+
System.out.format("[%d] %s\n", itemInfo.getID(), itemInfo.getName());
2130
}
2231
```
2332

33+
### Sample Project
34+
35+
A sample project can be found in `src/example`. This project will output your
36+
name and a list of the files and folders in your root directory.
37+
38+
To run the project, first provide a developer token in
39+
`src/example/java/com/box/sdk/example/Main.java`. You can obtain a developer
40+
token from your application's [developer
41+
console](https://cloud.app.box.com/developers/services).
42+
43+
```java
44+
public final class Main {
45+
private static final String DEVELOPER_TOKEN = "<YOUR_DEVELOPER_TOKEN>";
46+
47+
// ...
48+
}
49+
```
50+
51+
Then just invoke `gradle runExample` to run the example!
52+
2453
Building
2554
--------
2655

@@ -55,3 +84,20 @@ Javadoc reference documentation is [available here][1]. Javadocs are also
5584
generated when `gradle javadoc` is run and can be found in `build/doc/javadoc`.
5685

5786
[1]:https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/package-summary.html
87+
88+
Copyright and License
89+
---------------------
90+
91+
Copyright 2014 Box, Inc. All rights reserved.
92+
93+
Licensed under the Apache License, Version 2.0 (the "License");
94+
you may not use this file except in compliance with the License.
95+
You may obtain a copy of the License at
96+
97+
http://www.apache.org/licenses/LICENSE-2.0
98+
99+
Unless required by applicable law or agreed to in writing, software
100+
distributed under the License is distributed on an "AS IS" BASIS,
101+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102+
See the License for the specific language governing permissions and
103+
limitations under the License.

build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ javadoc {
3333
options.links 'http://docs.oracle.com/javase/8/docs/api/'
3434
}
3535

36+
sourceSets {
37+
example {
38+
java {
39+
compileClasspath += main.output
40+
runtimeClasspath += main.runtimeClasspath
41+
}
42+
}
43+
}
44+
45+
task runExample(type: JavaExec, dependsOn: 'exampleClasses') {
46+
classpath = sourceSets.example.runtimeClasspath
47+
main = 'com.box.sdk.example.Main'
48+
}
49+
3650
task javadocJar(type: Jar) {
3751
classifier = 'javadoc'
3852
from javadoc

doc/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ BoxUser creator = info.getCreatedBy();
5454
### Resource Docs
5555

5656
* [Files](types/files.md)
57+
* [Folders](types/folders.md)
5758

5859
Requests and Responses
5960
----------------------

doc/types/files.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ File objects represent individual files in Box. They can be used to download a
55
file's contents, upload new versions, and perform other common file operations
66
(move, copy, delete, etc.).
77

8-
* [Javadoc Documentation](https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFile.html)
9-
* [REST API Documentation](https://developers.box.com/docs/#files)
8+
* [Get a File's Information](#get-a-files-information)
9+
* [Update a File's Information](#update-a-files-information)
10+
* [Download a File](#download-a-file)
11+
* [Upload a File](#upload-a-file)
12+
* [Copy a File](#copy-a-file)
13+
* [Delete a File](#delete-a-file)
14+
* [Get Previous Versions of a File](#get-previous-versions-of-a-file)
15+
* [Upload a New Version of a File](#upload-a-new-version-of-a-file)
16+
* [Download a Previous Version of a File](#download-a-previous-version-of-a-file)
17+
* [Promote a Previous Version of a File](#promote-a-previous-version-of-a-file)
18+
* [Delete a Previous Version of a File](#delete-a-previous-version-of-a-file)
1019

1120
Get a File's Information
1221
------------------------

doc/types/folders.md

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
Folders
2+
=======
3+
4+
Folder objects represent a folder from a user's account. They can be used to
5+
iterate through a folder's contents, collaborate a folder with another user or
6+
group, and perform other common folder operations (move, copy, delete, etc.).
7+
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+
--------------------------
23+
24+
The user's root folder can be accessed with the static
25+
[`getRootFolder(BoxAPIConnection)`][get-root-folder] method.
26+
27+
```java
28+
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
29+
```
30+
31+
[get-root-folder]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#getRootFolder(com.box.sdk.BoxAPIConnection)
32+
33+
Get a Folder's Items
34+
--------------------
35+
36+
Every `BoxFolder` implements [`Iterable<BoxItem>`][iterator] which allows you to
37+
iterate over the folder's contents. The iterator automatically handles paging
38+
and will make additional network calls to load more data from Box when
39+
necessary.
40+
41+
```java
42+
BoxFolder folder = new BoxFolder(api, "id");
43+
for (BoxItem.Info itemInfo : folder) {
44+
if (itemInfo instanceof BoxFile.Info) {
45+
BoxFile.Info fileInfo = (BoxFile.Info) itemInfo;
46+
// Do something with the file.
47+
} else if (itemInfo instanceof BoxFolder) {
48+
BoxFolder.Info folderInfo = (BoxFolder.Info) itemInfo;
49+
// Do something with the folder.
50+
}
51+
}
52+
```
53+
54+
`BoxFolder` purposely doesn't provide a way of getting a collection of
55+
`BoxItems`. Getting the entire contents of a folder is usually unnecessary and
56+
can be extremely inefficient for folders with a large number of items. If you
57+
really require a collection instead of an iterable, you can create the
58+
collection manually.
59+
60+
```java
61+
Collection<BoxItem> folderItems = new ArrayList<BoxItem>();
62+
BoxFolder folder = new BoxFolder(api, "id");
63+
for (BoxItem.Info itemInfo : folder) {
64+
folderItems.add(itemInfo.getResource());
65+
}
66+
```
67+
68+
[iterator]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#iterator()
69+
70+
Get a Folder's Information
71+
--------------------------
72+
73+
Calling [`getInfo()`][get-info] on a folder returns a snapshot of the folder's
74+
info.
75+
76+
```java
77+
BoxFolder folder = new BoxFolder(api, "id");
78+
BoxFolder.Info info = folder.getInfo();
79+
```
80+
81+
Requesting information for only the fields you need can improve performance and
82+
reduce the size of the network request. The [`getInfo(String...)`][get-info2]
83+
method lets you specify which fields are retrieved.
84+
85+
```java
86+
BoxFolder folder = new BoxFolder(api, "id");
87+
// Only get information about a few specific fields.
88+
BoxFolder.Info info = folder.getInfo("size", "owned_by");
89+
```
90+
91+
[get-info]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#getInfo()
92+
[get-info2]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#getInfo(java.lang.String...)
93+
94+
Update a Folder's Information
95+
-----------------------------
96+
97+
Updating a folder's information is done by creating a new `BoxFolder.Info`
98+
object or updating an existing one, and then calling
99+
[`updateInfo(BoxFolder.Info)`][update-info].
100+
101+
```java
102+
BoxFolder folder = new BoxFolder(api, "id");
103+
BoxFolder.Info info = folder.new Info();
104+
info.setName("New Name");
105+
folder.updateInfo(info);
106+
```
107+
108+
[update-info]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#updateInfo(com.box.sdk.BoxFolder.Info)
109+
110+
Create a Folder
111+
---------------
112+
113+
Create a child folder by calling [`createFolder(String)`][create-folder] on the
114+
parent folder.
115+
116+
```java
117+
BoxFolder parentFolder = new BoxFolder(api, "id");
118+
BoxFolder.Info childFolderInfo = parentFolder.createFolder("Child Folder Name");
119+
```
120+
121+
[create-folder]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#createFolder(java.lang.String)
122+
123+
Copy a Folder
124+
-------------
125+
126+
Call the [`copy(BoxFolder)`][copy] method to copy a folder to another folder.
127+
128+
```java
129+
BoxFolder folder = new BoxFolder(api, "id1");
130+
BoxFolder destination = new BoxFolder(api, "id2");
131+
folder.copy(destination);
132+
```
133+
134+
You can also use the [`copy(BoxFolder, String)`][copy2] method to rename the
135+
folder while copying it. This allows you to make a copy of the folder in the
136+
same parent folder, but with a different name.
137+
138+
```java
139+
BoxFolder folder = new BoxFolder(api, "id1");
140+
BoxFolder.Info parentFolderInfo = folder.getInfo().getParent();
141+
BoxFolder parentFolder = parentFolderInfo.getResource();
142+
folder.copy(parentFolder, "New Name");
143+
```
144+
145+
[copy]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#copy(com.box.sdk.BoxFolder)
146+
[copy2]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#copy(com.box.sdk.BoxFolder,%20java.lang.String)
147+
148+
Move a Folder
149+
-------------
150+
151+
Call the [`move(BoxFolder)`][move] method with the destination you want the folder moved
152+
to.
153+
154+
```java
155+
BoxFolder folder = new BoxFolder(api, "id1");
156+
BoxFolder destination = new BoxFolder(api, "id2");
157+
folder.move(destination);
158+
```
159+
160+
[move]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#move(com.box.sdk.BoxFolder)
161+
162+
Rename a Folder
163+
---------------
164+
165+
Call the [`rename(String)`][rename] method with a new name for the folder.
166+
167+
```java
168+
BoxFolder folder = new BoxFolder(api, "id");
169+
folder.rename("New Name");
170+
```
171+
172+
A folder can also be renamed by updating the folder's information. This is
173+
useful if you want to perform more than one change to the folder in a single API
174+
request.
175+
176+
```java
177+
BoxFolder folder = new BoxFolder(api, "id");
178+
BoxFolder.Info info = folder.new Info();
179+
info.setName("New Name");
180+
folder.updateInfo(info);
181+
```
182+
183+
[rename]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#rename(java.lang.String)
184+
185+
Delete a Folder
186+
---------------
187+
188+
A folder can be deleted with the [`delete(boolean)`][delete] method. Passing
189+
true to this method indicates that the folder and its contents should be
190+
recursively deleted.
191+
192+
```java
193+
BoxFolder folder = new BoxFolder(api, "id");
194+
folder.delete(true);
195+
```
196+
197+
[delete]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#delete(boolean)
198+
199+
Created a Shared Link for a Folder
200+
----------------------------------
201+
202+
You can get a shared link for a folder by calling the
203+
[`createSharedLink(BoxSharedLink.Access, Date, BoxSharedLink.Permissions)`]
204+
[create-shared-link] method.
205+
206+
```java
207+
BoxFolder folder = new BoxFolder(api, "id");
208+
SharedLink link = folder.createSharedLink(BoxSharedLink.Access.OPEN, null,
209+
permissions);
210+
```
211+
212+
A shared link can also be created by updating the folder's information. This is
213+
useful if you want to perform more than one change to the folder in a single API
214+
request.
215+
216+
```java
217+
BoxSharedLink sharedLink = new BoxSharedLink();
218+
sharedLink.setAccess(BoxSharedLink.Access.OPEN);
219+
220+
BoxFolder folder = new BoxFolder(api, "id");
221+
BoxFolder.Info info = folder.new Info();
222+
info.setSharedLink(sharedLink);
223+
folder.updateInfo(info);
224+
```
225+
226+
[create-shared-link]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#createSharedLink(com.box.sdk.BoxSharedLink.Access,%20java.util.Date,%20com.box.sdk.BoxSharedLink.Permissions)
227+
228+
Share a Folder
229+
--------------
230+
231+
You can invite another person to collaborate on a folder with the
232+
[`collaborate(String, BoxCollaboration.Role)`][collaborate] method.
233+
234+
```java
235+
BoxFolder folder = new BoxFolder(api, "id");
236+
BoxCollaboration.Info collabInfo = folder.collaborate("[email protected]",
237+
BoxCollaboration.Role.EDITOR);
238+
```
239+
240+
If you already know the user's ID, you can invite them directly without needing
241+
to know their email address with the
242+
[`collaborate(BoxCollaborator, BoxCollaboration.Role)`][collaborate2] method.
243+
244+
```java
245+
BoxUser collaborator = new User(api, "user-id");
246+
BoxFolder folder = new BoxFolder(api, "folder-id");
247+
BoxCollaboration.Info collabInfo = folder.collaborate(collaborator,
248+
BoxCollaboration.Role.EDITOR);
249+
```
250+
251+
[collaborate]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#collaborate(java.lang.String,%20com.box.sdk.BoxCollaboration.Role)
252+
[collaborate2]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#collaborate(com.box.sdk.BoxCollaborator,%20com.box.sdk.BoxCollaboration.Role)
253+
254+
Get All Collaborations for a Folder
255+
-----------------------------------
256+
257+
The [`getCollaborations()`][get-collaborations] method will return a collection
258+
of `BoxCollaboration.Info` objects for a folder.
259+
260+
```java
261+
BoxFolder folder = new BoxFolder(api, "id");
262+
Collection<BoxCollaboration.Info> collaborations = folder.getCollaborations();
263+
```
264+
265+
[get-collaborations]: https://gitenterprise.inside-box.net/pages/Box/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#getCollaborations()

0 commit comments

Comments
 (0)