public class

BoxNetModule

extends Object
implements MuleContextAware
java.lang.Object
   ↳ org.mule.modules.boxnet.BoxNetModule
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Box.net Cloud Connector Module.

Summary

Fields
private String apiKey The API key obtained when registering a project with the Box platform.
private AuthCallbackAdapter authCallback
private String callbackPath The url where box.net will direct the authentication callback.
private Integer callbackPort The port where the authentication callback will be listening on Defaults to 8080
private BoxExternalAPI client
private static final Logger logger
private MuleContext muleContext
private boolean usesCallback If true, an http inbound endpoint will be set in place to receive a callback from box.net with the authToken once the user has authenticated.
Public Constructors
BoxNetModule()
Public Methods
String addToTag(String csvTags, String target, String targetId)
This processor adds file or folder to tags list.
String authToken()
After the user authenticates the ticket obtained with the get-ticket processor, there're two ways to get the required auth token:
  1. You can configure box.net to make a callback returning the ticket and authToken, in which case you need to set the usesCallback and callbackPath config attributes accordingly
  2. You can use this processor to obtain the authentication token explicitly.
CreateFolderResponse createFolder(String parentFolderId, String folderName, Boolean share)
Create a new folder
DeleteResponse delete(String target, String targetId)
Deletes a file or folder
byte[] download(String fileId)
Downloads a file an returns its contents as a byte[]
String exportTags(String encoding)
This processor returns all the user's tags.
String getCallbackPath()
Integer getCallbackPort()
GetFileInfoResponse getFileInfo(String fileId)
Gets information about a file
String getTicket()
Get and access ticket using the configured apiKey.
GetAccountTreeResponse getTreeStructure(String folderId, String csvParams, String encoding)
This processor is used to get a user's files and folders tree.
boolean isUsesCallback()
LogoutResponse logout()
Logs out the user associated with the authorization token
String move(String target, String targetId, String destinationId)
This processor moves a file or folder to another folder.
String privateShare(String target, String targetId, String csvMails, Boolean notify, String message)
This processor privately shares a file or folder with another user(s).
PublicShareResponse publicShare(String target, String targetId, String password, String message)
Makes a public share of a file or folder
String publicUnshare(String target, String targetId)
This processor unshares a public shared file or folder
RegisterNewUserResponse registerNewUser(String email, String password)
Create a new user in box.net
String rename(String target, String targetId, String newName)
This processor renames a file or folder.
void setApiKey(String apiKey)
void setCallbackPath(String callbackPath)
void setCallbackPort(Integer callbackPort)
String setDescription(String target, String targetId, String description)
This processor sets a description to a file or folder.
void setMuleContext(MuleContext context)
void setUsesCallback(boolean usesCallback)
void start()
void stop()
UploadResponse uploadFiles(List<String> paths, String folderId)
Receives a comma separated list of paths and uploads the corresponding files.
UploadResponse uploadStream(String folderId, String filename, InputStream input)
Receives an input stream and uploads its content as a file
String verifyRegistrationEmail(String loginName)
This method is used to verify user registration email
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.mule.api.context.MuleContextAware

Fields

private String apiKey

The API key obtained when registering a project with the Box platform. For more information about this field please refer to http://developers.box.net/

private AuthCallbackAdapter authCallback

private String callbackPath

The url where box.net will direct the authentication callback. For more info look at http://developers.box.net/w/page/12923915/ApiAuthentication Defaults to box_auth_callback

private Integer callbackPort

The port where the authentication callback will be listening on Defaults to 8080

private BoxExternalAPI client

private static final Logger logger

private MuleContext muleContext

private boolean usesCallback

If true, an http inbound endpoint will be set in place to receive a callback from box.net with the authToken once the user has authenticated. If this callback is in place, there's no need for you to manually invoke the get-auth-token processor. For more info look at http://developers.box.net/w/page/12923915/ApiAuthentication Defaults to false

Public Constructors

public BoxNetModule ()

Public Methods

public String addToTag (String csvTags, String target, String targetId)

This processor adds file or folder to tags list.

Parameters
csvTags Comma separated list of tags
target Can be either 'file' or 'folder' depending on what do you want to add
targetId The id of a file or folder to be added
Returns
  • 'addtotag_ok' if successful. Otherwise addtotag_error.
Throws
IllegalArgumentException} if target is invalid or csvTags is empty

public String authToken ()

After the user authenticates the ticket obtained with the get-ticket processor, there're two ways to get the required auth token:

  1. You can configure box.net to make a callback returning the ticket and authToken, in which case you need to set the usesCallback and callbackPath config attributes accordingly
  2. You can use this processor to obtain the authentication token explicitly.
Either way, this connector will retain the authToken in memory and will use it in all operations. For more info look at http://developers.box.net/w/page/12923915/ApiAuthentication

Returns
  • the authentication token
Throws
IllegalArgumentException if the ticket does not match a logged user
IllegalStateException if you use this processor before getting a ticket

public CreateFolderResponse createFolder (String parentFolderId, String folderName, Boolean share)

Create a new folder

Parameters
parentFolderId The id of the parent folder
folderName The name of the folder you want to create
share Specifies if the folder is shared. This parameter is optional and defaults to false
Returns
  • an instance of CreateFolderResponse with data about the operation status and info about the newly created folder (if successful)

public DeleteResponse delete (String target, String targetId)

Deletes a file or folder

Parameters
target The type of item to be shared. This can be set as 'file' or 'folder'. Any other value will throw a IllegalArgumentException
targetId The id of the item you wish to delete. If the target is a folder, this will be the folder_id. If the target is a file, this will be the file_id.
Returns
Throws
IllegalArgumentException} if target is invalid

public byte[] download (String fileId)

Downloads a file an returns its contents as a byte[]

Parameters
fileId The id of the file we want to download
Returns
  • the file's contents as a byte array

public String exportTags (String encoding)

This processor returns all the user's tags. On successful you will get an xml representing the tags that looks like this: music mp3 If the result wasn't successful, status field can be: not_logged_id, application_restricted.

Parameters
encoding Encoding to use when decoding from BASE64. Optional, defaults to UTF-8
Returns
  • a String xml representing the tags

public String getCallbackPath ()

public Integer getCallbackPort ()

public GetFileInfoResponse getFileInfo (String fileId)

Gets information about a file

Parameters
fileId The id of the file you want info about
Returns

public String getTicket ()

Get and access ticket using the configured apiKey. With this ticket, the user needs to manually go to https://www.box.net/api/1.0/auth/ For more info look at http://developers.box.net/w/page/12923915/ApiAuthentication

Returns
  • the ticket key

public GetAccountTreeResponse getTreeStructure (String folderId, String csvParams, String encoding)

This processor is used to get a user's files and folders tree. 'folderId' param defines root folder from which the tree begins. 'csvParams' is comma separated list where you can set additional parameters, which are: onelevel - make a tree of one level depth, so you will get only files and folders stored in folder which folder_id you have provided. nofiles - include folders only in result tree, no files. nozip - do not zip tree xml. On successful result you will receive 'listing_ok' as status and the tree xml. if you haven't set 'nozip' as a parameter (it's set by default), then you have to unzip it. Then you will get xml like this: (note that updatedand createdare UNIX timestamps in PST).

Parameters
folderId The ID of the root folder from which the tree begins. If this value is "0", the user's full account tree is returned. Defaults to zero
csvParams Comma separated list of params. This is optional and defaults to 'nozip'
encoding Optional parameter to specify the encoding to use when decoding BASE64. Defaults to UTF-8
Returns
  • an instance of GetAccountTreeResponse with data about the operation status and info about the inspected folder (if successful)

public boolean isUsesCallback ()

public LogoutResponse logout ()

Logs out the user associated with the authorization token

Returns

public String move (String target, String targetId, String destinationId)

This processor moves a file or folder to another folder. On a successful result, status will be 's_move_node'. If the result wasn't successful, status field can be: 'e_move_node', 'not_logged_in', 'application_restricted'.

Parameters
target Can be either 'file' or 'folder' depending on what do you
targetId Is the id of a file or folder to be moved
destinationId Is the destination folder id.
Returns
  • if successful 's_move_node'. Otherwise it can be 'e_move_node', 'not_logged_in', 'application_restricted'.

public String privateShare (String target, String targetId, String csvMails, Boolean notify, String message)

This processor privately shares a file or folder with another user(s). 'target' param, 'target_id' is . 'emails' params is an array of emails of users' to share files with. if 'notify' param is , 'message' param . Note: currently only files can be shared privately.

Parameters
target Should be either 'file' or 'folder'
targetId The id of the file or folder to be shared
csvMails Comma separated list of email addresses of the users that will receive the share
notify If true, then a notification email will be sent to users. Optional parameter, defaults to true
message Is a message to be included in the notification email. Optional parameter, defaults to an empty string
Returns
  • if successful will be 'private_share_ok'. Otherwise can be: 'private_share_error', 'wrong_node', 'not_logged_in', 'application_restricted'.
Throws
IllegalArgumentException} if target is invalid or csvMails is null or empty

public PublicShareResponse publicShare (String target, String targetId, String password, String message)

Makes a public share of a file or folder

Parameters
target The type of item to be shared. This can be set as 'file' or 'folder'. Any other value will throw a IllegalArgumentException
targetId The id of the item you wish to share. If the target is a folder, this will be the folder_id. If the target is a file, this will be the file_id.
password The password to protect the folder or file.
message An message to be included in a notification email.
Returns
  • an instance of PublicShareResponse with data about the operation status and info about the shared folder (if successful)
Throws
IllegalArgumentException} if target is invalid

public String publicUnshare (String target, String targetId)

This processor unshares a public shared file or folder

Parameters
target Shoud be either 'file' or 'folder'
targetId Is id of a file or folder to be unshared
Returns
  • On a successful result, the status will be 'unshare_ok'. If the result wasn't successful, the status field can be: 'unshare_error', 'wrong_node', 'not_logged_in', 'application_restricted'.
Throws
IllegalArgumentException} if target is invalid

public RegisterNewUserResponse registerNewUser (String email, String password)

Create a new user in box.net

Parameters
email The user's email
password The user's password
Returns
  • an instance of RegisterNewUserResponse with data about the operation status and info about the newly created user (if successful)

public String rename (String target, String targetId, String newName)

This processor renames a file or folder.

Parameters
target Can be either 'file' or 'folder' depending on what you want to rename
targetId Is the id of a file or folder to be renamed
newName Is the new name for a file or folder
Returns
  • if successful will be 's_rename_node'. Otherwise it can be: 'e_rename_node', 'not_logged_in', 'application_restricted'

public void setApiKey (String apiKey)

Parameters
apiKey

public void setCallbackPath (String callbackPath)

Parameters
callbackPath

public void setCallbackPort (Integer callbackPort)

Parameters
callbackPort

public String setDescription (String target, String targetId, String description)

This processor sets a description to a file or folder.

Parameters
target Can be either 'file' or 'folder'
targetId The id of the folder/file you want to modify
description The description you want to set
Returns
  • 's_set_description' if successful. 'e_set_description' otherwise.

public void setMuleContext (MuleContext context)

Parameters
context

public void setUsesCallback (boolean usesCallback)

Parameters
usesCallback

public void start ()

Throws
MuleException

public void stop ()

Throws
MuleException

public UploadResponse uploadFiles (List<String> paths, String folderId)

Receives a comma separated list of paths and uploads the corresponding files.

Parameters
paths A List of Strings with the paths where the files are. Defaults to payload
folderId The id of the parent folder. Defaults to 0 (the root folder)
Returns
  • an instance of UploadResponse with data about the operation status and info about the newly uploaded files (if successful)

public UploadResponse uploadStream (String folderId, String filename, InputStream input)

Receives an input stream and uploads its content as a file

Parameters
folderId The id of the parent folder. Defaults to 0 which is the root folder
filename The name we want the file to have on box.net
input InputStream with the contents of the file. It's taken from the message payload.
Returns
  • an instance of UploadResponse with data about the operation status and info about the newly uploaded file (if successful)

public String verifyRegistrationEmail (String loginName)

This method is used to verify user registration email

Parameters
loginName The login username of the user for which you would like to verify registration.
Returns
  • Upon a successful registration, the return value will be 'email_ok'. If registration was not successful, it can be: 'email_invalid' - The login provided is not a valid email address. 'email_already_registered' - The login provided is already registered by another user. 'application_restricted'- You provided an invalid api_key, or the api_key is restricted from calling this function.