Skip to content

Commit

Permalink
Tag code samples for usage in developer docs (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristiano Betta authored and Cary Cheng committed May 13, 2019
1 parent 35b4ba6 commit dba85a7
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ console](https://cloud.app.box.com/developers/services).

The following example creates an API connection with a developer token:

<!-- sample get_authorize -->
```java
BoxAPIConnection api = new BoxAPIConnection("YOUR-DEVELOPER-TOKEN");
```
Expand Down Expand Up @@ -95,6 +96,7 @@ they will be redirected to your application's `redirect_uri` which will contain
an auth code. This auth code can then be used along with your client ID and
client secret to establish an API connection.

<!-- sample post_token -->
```java
BoxAPIConnection api = new BoxAPIConnection("YOUR-CLIENT-ID",
"YOUR-CLIENT-SECRET", "YOUR-AUTH-CODE");
Expand Down Expand Up @@ -183,6 +185,7 @@ Revoke Token

At any point if you wish to revoke your tokens you can do so by calling the following.

<!-- sample post_revoke -->
```java
BoxAPIConnection api = new BoxAPIConnection("YOUR-ACCESS-TOKEN");
api.revokeToken();
Expand Down
8 changes: 8 additions & 0 deletions doc/collaboration_whitelists.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ A collaboration whitelist can be created for a domain with
The `WhitelistDirection` parameter determines which way the whitelisting
applies. You can set the value to inbound, outbound, or both.

<!-- sample post_collaboration_whitelist_entries -->
```java
BoxCollaborationWhitelist.create(api, "test.com", BoxCollaborationWhitelist.WhitelistDirection.BOTH);
```
Expand All @@ -39,6 +40,7 @@ Get a Collaboration Whitelist's Information for a Domain
A specific collaboration whitelist for a domain can be retrieved with
[`getInfo()`][getWhitelistInfo]

<!-- sample get_collaboration_whitelist_entries_id -->
```java
BoxCollaborationWhitelist domainWhitelist = new BoxCollaborationWhitelist(api, "id");
domainWhitelist.getInfo();
Expand All @@ -52,6 +54,7 @@ Get all Collaboration Whitelist's Information for Domain
All domain collaboration whitelists associated with an enterprise can be
retrieved with [`getAll(BoxAPIConnection api)`][getAllWhitelists1]

<!-- sample get_collaboration_whitelist_entries -->
```java
BoxCollaborationWhitelist.getAll(api);
```
Expand All @@ -71,6 +74,7 @@ Remove a Collaboration Whitelist for a Domain

To remove a collaboration whitelist you can call [`delete()`][deleteWhitelist]

<!-- sample delete_collaboration_whitelist_entries_id -->
```java
BoxCollaborationWhitelist domainToBeDeleted = new BoxCollaborationWhitelist(api, "whitelist-id");
domainToBeDeleted.delete();
Expand All @@ -84,6 +88,7 @@ Add a Collaboration Whitelist for a User
A collaboration whitelist can be created for a user with
[`create(BoxAPIConnection api, String userID)`][createExempt]

<!-- sample post_collaboration_whitelist_exempt_targets -->
```java
String userID = "12345";
BoxCollaborationWhitelistExemptTarget.create(api, userID);
Expand All @@ -97,6 +102,7 @@ Get a Collaboration Whitelist's Information for a User
To retrieve information regarding a specific user collaboration whitelist use
[`getInfo()`][getInfoExempt]

<!-- sample get_collaboration_whitelist_exempt_targets_id -->
```java
BoxCollaborationWhitelistExemptTarget userWhitelist = new BoxCollaborationWhitelistExemptTarget(api, "whitelistID");
userWhitelist.getInfo();
Expand All @@ -110,6 +116,7 @@ Get all Collaboration Whitelist's Information for a User
To retrieve information regarding all user whitelists associated with an enterprise use
[`getAll(BoxAPIConnection api)`][getAllExempt1]

<!-- sample get_collaboration_whitelist_exempt_targets -->
```java
BoxCollaborationWhitelistExemptTarget.getAll(api);
```
Expand All @@ -131,6 +138,7 @@ Remove a Collaboration Whitelist for a User
To remove a user collaboration whitelist entry from an enterprise use
[`delete()`][deleteExempt]

<!-- sample delete_collaboration_whitelist_exempt_targets_id -->
```java
BoxCollaborationWhitelistExemptTarget userWhitelist = new BoxCollaborationWhitelistExemptTarget(api, "whitelist_id")
userWhitelist.delete();
Expand Down
8 changes: 8 additions & 0 deletions doc/collaborations.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ A collaboration can be added for an existing user or group with
`role` parameter determines what permissions the collaborator will have on the
folder.

<!-- sample post_collaborations -->
```java
BoxCollaborator user = new BoxUser(api, "user-id")
BoxFolder folder = new BoxFolder(api, "folder-id");
Expand All @@ -52,6 +53,7 @@ A collaboration can be edited by creating a new
[`BoxCollaboration.Info`][box-collaboration-info] object or updating an existing
one, and then passing it to [`updateInfo(BoxCollaboration.Info fieldsToUpdate)`][update-info]

<!-- sample put_collaborations_id -->
```java
BoxCollaboration collaboration = new BoxCollaboration(api, "id");
BoxCollaboration.Info info = collaboration.new Info();
Expand All @@ -67,6 +69,7 @@ Remove a Collaboration

A collaboration can be removed by calling [`delete()`][delete].

<!-- sample delete_collaborations_id -->
```java
BoxCollaboration collaboration = new BoxCollaboration(api, "id");
collaboration.delete();
Expand All @@ -80,6 +83,7 @@ Get a Collaboration's Information
Calling [`getInfo()`][get-info] on a collaboration returns a snapshot of the
collaboration's info.

<!-- sample get_collaborations_id -->
```java
BoxCollaboration collaboration = new BoxCollaboration(api, "id");
BoxCollaboration.Info info = collaboration.getInfo();
Expand All @@ -102,6 +106,7 @@ Get the Collaborations on a Folder
You can get all of the collaborations on a folder by calling
[`getCollaborations()`][get-collaborations] on the folder.

<!-- sample get_folders_id_collaborations -->
```java
BoxFolder folder = new BoxFolder(api, "id");
Collection<BoxCollaboration.Info> collaborations = folder.getCollaborations();
Expand All @@ -116,6 +121,7 @@ You can get an iterator over all of the collaborations on a file by calling
[`BoxFile#getAllFileCollaborations(String... fields)`][get-collaborations-file]
on the file.

<!-- sample get_files_id_collaborations -->
```java
BoxFile file = new BoxFile(api, "id");
Iterable<BoxCollaboration.Info> collaborations = file.getAllFileCollaborations();
Expand All @@ -129,6 +135,7 @@ Get Pending Collaborations
A collection of all the user's pending collaborations can be retrieved with
[`getPendingCollaborations(BoxAPIConnection api)`][get-pending-collaborations].

<!-- sample get_collaborations -->
```java
Collection<BoxCollaboration.Info> pendingCollaborations =
BoxCollaboration.getPendingCollaborations(api);
Expand All @@ -142,6 +149,7 @@ Accept or Decline a Pending Collaboration
To accept or decline a pending collaboration, update the info of the pending collaboration object
with the desired status.

<!-- sample put_collaborations_id -->
```java
// Accept all pending collaborations
Collection<BoxCollaboration.Info> pendingCollaborations = BoxCollaboration.getPendingCollaborations(api);
Expand Down
2 changes: 2 additions & 0 deletions doc/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Existing collections can be retrieved by calling the
[`getAllCollections(BoxAPIConnection)`][get-collections] method. Currently only
"Favorites" collection is supported.

<!-- sample get_collections -->
```java
Iterable<BoxCollection.Info> collections = BoxCollection.getAllCollections(api);
for (BoxCollection.Info collectionInfo : collections) {
Expand All @@ -41,6 +42,7 @@ you to iterate over the collection's contents. The iterator automatically
handles paging and will make additional network calls to load more data from Box
when necessary.

<!-- sample get_collections_id_items -->
```java
BoxFolder folder = new BoxFolder(api, "id");
for (BoxItem.Info itemInfo : folder) {
Expand Down
5 changes: 5 additions & 0 deletions doc/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Get a Comment's Information
Calling [`getInfo()`][get-info] on a comment returns a snapshot of the comment's
info.

<!-- sample get_comments_id -->
```java
BoxComment comment = new BoxComment(api, "id");
BoxComment.Info info = comment.getInfo();
Expand All @@ -36,6 +37,7 @@ Get the Comments on a File
You can get all of the comments on a file by calling the
[`getComments()`][get-comments] method.

<!-- sample get_files_id_comments -->
```java
BoxFile file = new BoxFile(api, "id");
List<BoxComment.Info> comments = file.getComments();
Expand All @@ -49,6 +51,7 @@ Add a Comment to a File
A comment can be added to a file with the [`addComment(String message)`][add-comment]
method.

<!-- sample post_comments -->
```java
BoxFile file = new BoxFile(api, "id");
file.addComment("This file is pretty cool.");
Expand Down Expand Up @@ -85,6 +88,7 @@ Change a Comment's Message
The message of a comment can be changed with the
[`changeMessage(String message)`][change-message] method.

<!-- sample put_comments_id -->
```java
BoxComment comment = new BoxComment(api, "id");
comment.changeMessage("An edited message.");
Expand All @@ -97,6 +101,7 @@ Delete a Comment

A comment can be deleted with the [`delete()`][delete] method.

<!-- sample delete_comments_id -->
```java
BoxComment comment = new BoxComment(api, "id");
comment.delete();
Expand Down
3 changes: 3 additions & 0 deletions doc/devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enterprise with given ID. It is possible to specify maximum number of retrieved
items per single response by passing the maxiumum number of records to retrieve to
[`getEnterpriceDevicePins(BoxAPIConnection api, String enterpriseID, int limit, String... fields)`][get-enterprise-device-pins-with-limit]

<!-- sample get_enterprises_id_device_pinners -->
```java
Iterable<BoxDevicePin.Info> enterpriseDevicePins = BoxDevicePin.getEnterpriceDevicePins(api, id);
for (BoxDevicePin.Info devicePin : enterpriseDevicePins) {
Expand All @@ -39,6 +40,7 @@ Get Device Pin
Existing collections can be retrieved by calling the [`getInfo(String... fields)`][get-device-pin] method.
Optional parameters can be used to retrieve specific fields of the Device Pin object.

<!-- sample get_device_pinners_id -->
```java
BoxDevicePin devicePin = new BoxDevicePin(api, id);
BoxDevicePin.Info devicePinInfo = devicePin.getInfo();
Expand All @@ -51,6 +53,7 @@ Delete Device Pin

A device pin can be deleted by calling the [`delete()`][delete] method.

<!-- sample delete_device_pinners_id -->
```java
BoxDevicePin devicePin = new BoxDevicePin(api, id);
devicePin.delete();
Expand Down
1 change: 1 addition & 0 deletions doc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ start from a known stream position, pass the stream position to the
[`EventStream(BoxAPIConnection api, long streamPosition)`][event-stream-position]
constructor.

<!-- sample get_events -->
```java
EventStream stream = new EventStream(api);
stream.addListener(new EventListener() {
Expand Down
17 changes: 17 additions & 0 deletions doc/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Get a File's Information

Calling [`getInfo()`][get-info] on a file returns a snapshot of the file's info.

<!-- sample get_files_id -->
```java
BoxFile file = new BoxFile(api, "id");
BoxFile.Info info = file.getInfo();
Expand All @@ -73,6 +74,7 @@ Updating a file's information is done by creating a new [`BoxFile.Info`][box-fil
object or updating an existing one, and then calling
[`updateInfo(BoxFile.Info fieldsToUpdate)`][update-info].

<!-- sample put_files_id -->
```java
BoxFile file = new BoxFile(api, "id");
BoxFile.Info info = file.new Info();
Expand All @@ -89,6 +91,7 @@ Download a File
A file can be downloaded by calling [`download(OutputStream stream)`][download]
and providing an `OutputStream` where the file's contents will be written.

<!-- sample get_files_id_content -->
```java
BoxFile file = new BoxFile(api, "id");
BoxFile.Info info = file.getInfo();
Expand Down Expand Up @@ -128,6 +131,7 @@ Files are uploaded to a folder by calling the
[`uploadFile(InputStream fileContents, String fileName)`][upload] method
on the [`BoxFolder`][box-folder] you want to upload the file into.

<!-- sample post_files_content -->
```java
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
FileInputStream stream = new FileInputStream("My File.txt");
Expand Down Expand Up @@ -176,6 +180,7 @@ the network if the upload would not have succeeded. Calling the
on the folder you want to upload a new file into will verify that there is no
name conflict and that the account has enough storage space for the file.

<!-- sample options_files_content -->
```java
String fileName = "My Doc.pdf";
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
Expand Down Expand Up @@ -389,6 +394,7 @@ A file can be copied to a new folder and optionally be renamed with the
[`copy(BoxFolder destination)`][copy] and
[`copy(BoxFolder destination, String newName)`][copy2] methods.

<!-- sample post_files_id_copy -->
```java
// Copy a file into the user's root folder
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
Expand All @@ -404,6 +410,7 @@ Delete a File

Calling the [`delete()`][delete] method will move the file to the user's trash.

<!-- sample delete_files_id -->
```java
BoxFile file = new BoxFile(api, "id");
file.delete();
Expand All @@ -417,6 +424,7 @@ Get Previous Versions of a File
For users with premium accounts, versions of a file can be retrieved with the
[`getVersions()`][get-versions] method.

<!-- sample get_files_id_versions -->
```java
BoxFile file = new BoxFile(api, "id");
List<BoxFileVersion> versions = file.getVersions();
Expand All @@ -434,6 +442,7 @@ New versions of a file can be uploaded with the
[`uploadVersion(InputStream fileContents)`][upload-version]
method.

<!-- sample post_files_id_content -->
```java
BoxFile file = new BoxFile(api, "id");
FileInputStream stream = new FileInputStream("My File.txt");
Expand All @@ -448,6 +457,7 @@ Download a Previous Version of a File
For users with premium accounts, previous versions of a file can be downloaded
by calling [`download(OutputStream output)`][download-version].

<!-- sample get_files_id_content -->
```java
BoxFile file = new BoxFile(api, "id");
List<BoxFileVersion> versions = file.getVersions();
Expand All @@ -466,6 +476,7 @@ Promote a Previous Version of a File
A previous version of a file can be promoted with the [`promote()`][promote]
method to become the current version of the file.

<!-- sample post_files_id_versions_current -->
```java
BoxFile file = new BoxFile(api, "id");
List<BoxFileVersion> versions = file.getVersions();
Expand All @@ -481,6 +492,7 @@ Delete a Previous Version of a File
A version of a file can be deleted and moved to the trash by calling
[`delete()`][delete-version].

<!-- sample delete_files_id_versions_id -->
```java
BoxFile file = new BoxFile(api, "id");
List<BoxFileVersion> versions = file.getVersions();
Expand Down Expand Up @@ -646,6 +658,7 @@ Metadata can be created on a file by calling
Note: This method will only succeed if the provided metadata template is not currently applied to the file, otherwise
it will fail with a Conflict error.

<!-- sample post_files_id_metadata_id_id -->
```java
// Add property "foo" with value "bar" to the default metadata properties
BoxFile file = new BoxFile(api, "id");
Expand All @@ -654,6 +667,7 @@ file.createMetadata(new Metadata().add("/foo", "bar"));

Update a files Metadata by calling [`updateMetadata(Metadata properties)`][update-metadata].

<!-- sample put_files_id_metadata_id_id -->
```java
BoxFile file = new BoxFile(api, "id");
file.updateMetadata(new Metadata().add("/foo", "bar"));
Expand All @@ -677,6 +691,7 @@ Retrieve a files Metadata by calling [`getMetadata()`][get-metadata],
[`getMetadata(String templateKey, String templateScope)`][get-metadata-3].
These methods return a [`Metadata`][metadata] object, which allows access to metadata values.

<!-- sample get_files_id_metadata_id_id -->
```java
// Get the default free-form metadata properties
BoxFile file = new BoxFile(api, "id");
Expand Down Expand Up @@ -723,6 +738,7 @@ A files Metadata can be deleted by calling
[`deleteMetadata(String templateKey)`][delete-metadata-2], or
[`deleteMetadata(String templateKey, String templateScope)`][delete-metadata-3].

<!-- sample delete_files_id_metadata_id_id -->
```java
BoxFile file = new BoxFile(api, "id");
file.deleteMetadata("myMetadataTemplate");
Expand All @@ -738,6 +754,7 @@ Get All Metadata on File
Calling the [`getAllMetadata()`][get-all-metadata] method on a file will return
an iterable that will page through all of the metadata associated with the file.

<!-- sample get_files_id_metadata -->
```java
BoxFile file = new BoxFile(api, "id");
Iterable<Metadata> metadataList = file.getAllMetadata();
Expand Down
Loading

0 comments on commit dba85a7

Please sign in to comment.