cn.com.believer.songyuanframework.openapi.storage.box.impl.simple
Class SimpleBoxImpl

java.lang.Object
  extended by cn.com.believer.songyuanframework.openapi.storage.box.impl.simple.SimpleBoxImpl
All Implemented Interfaces:
BoxExternalAPI

public class SimpleBoxImpl
extends java.lang.Object
implements BoxExternalAPI

Author:
Jimmy

Field Summary
protected static Logger LOGGER
          log4j logger.
 
Constructor Summary
SimpleBoxImpl()
           
 
Method Summary
 AddToMyBoxResponse addToMyBox(AddToMyBoxRequest addToMyBoxRequest)
          This method copies a file publicly shared by someone to a user's mybox.
 AddToTagResponse addToTag(AddToTagRequest addToTagRequest)
          This method adds file or folder to tags list.
 CreateFolderResponse createFolder(CreateFolderRequest createFolderRequest)
          This method creates a new folder.
 DeleteResponse delete(DeleteRequest deleteRequest)
          This method deletes a file or folder.
 DownloadResponse download(DownloadRequest downloadRequest)
          download a file.
 ExportTagsResponse exportTags(ExportTagsRequest exportTagsRequest)
          This method returns all the user's tags.
 GetAccountTreeResponse getAccountTree(GetAccountTreeRequest getAccountTreeRequest)
          This method is used to get a user's files and folders tree.
 GetAuthTokenResponse getAuthToken(GetAuthTokenRequest getAuthTokenRequest)
          This method is used in the authorization process.
 GetFileInfoResponse getFileInfo(GetFileInfoRequest getFileInfoRequest)
          This method gets file info.
 GetFriendsResponse getFriends(GetFriendsRequest getFriendsRequest)
          This method is used to retrieve a list of freinds.
 GetTicketResponse getTicket(GetTicketRequest getTicketRequest)
          This method is used in the authorization process.
 LogoutResponse logout(LogoutRequest logoutRequest)
          This method is used to logout a user.
 MoveResponse move(MoveRequest moveRequest)
          This method moves a file or folder to another folder.
 PrivateShareResponse privateShare(PrivateShareRequest privateShareRequest)
          This method privately shares a file or folder with another user(s).
 PublicShareResponse publicShare(PublicShareRequest publicShareRequest)
          This method publicly shares a file or folder.
 PublicUnshareResponse publicUnshare(PublicUnshareRequest publicUnshareRequest)
          This method unshares a shared file or folder.
 RegisterNewUserResponse registerNewUser(RegisterNewUserRequest registerNewUserRequest)
          This method is used to register a user.
 RenameResponse rename(RenameRequest renameRequest)
          This method renames a file or folder.
 RequestFriendsResponse requestFriends(RequestFriendsRequest requestFriendsRequest)
          This method requests new friends to be added to your network.
 SetDescriptionResponse setDescription(SetDescriptionRequest setDescriptionRequest)
          This method sets a description to a file or folder.
 UploadResponse upload(UploadRequest uploadRequest)
          upload files.
 VerifyRegistrationEmailResponse verifyRegistrationEmail(VerifyRegistrationEmailRequest verifyRegistrationEmailRequest)
          This method is used to verify user registration email .
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

protected static final Logger LOGGER
log4j logger.

Constructor Detail

SimpleBoxImpl

public SimpleBoxImpl()
Method Detail

upload

public UploadResponse upload(UploadRequest uploadRequest)
                      throws java.io.IOException,
                             BoxException
Description copied from interface: BoxExternalAPI
upload files.

Specified by:
upload in interface BoxExternalAPI
Parameters:
uploadRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

download

public DownloadResponse download(DownloadRequest downloadRequest)
                          throws java.io.IOException
Description copied from interface: BoxExternalAPI
download a file.

Specified by:
download in interface BoxExternalAPI
Parameters:
downloadRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception

requestFriends

public RequestFriendsResponse requestFriends(RequestFriendsRequest requestFriendsRequest)
                                      throws java.io.IOException,
                                             BoxException
This method requests new friends to be added to your network. 'emails' - array of emails. 'message' - text message that you want to send to freinds. 'params' is an array of string where you can set additional parameters, which are: box_auto_subscribe - subscribe to public boxes of inveted users. no_email - don't send emails to invited users. On a successful result, you will receive status 's_request_friends'. If the result wasn't successful, status field can be: e_request_friends.

Specified by:
requestFriends in interface BoxExternalAPI
Parameters:
requestFriendsRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

getFriends

public GetFriendsResponse getFriends(GetFriendsRequest getFriendsRequest)
                              throws java.io.IOException,
                                     BoxException
This method is used to retrieve a list of freinds. 'params' is an array of the string where you can set additional parameters, which are: nozip - do not zip tree xml. On a successful result you will receive 's_get_friends' as the status and base64 encoded (and zipped) friends xml. Friends xml looks like this: ......

Specified by:
getFriends in interface BoxExternalAPI
Parameters:
getFriendsRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

setDescription

public SetDescriptionResponse setDescription(SetDescriptionRequest setDescriptionRequest)
                                      throws java.io.IOException,
                                             BoxException
This method sets a description to a file or folder. 'target' can be a 'file' or 'folder', 'target_id' - id of file or folder, description - string that should be set as description. On successful a result, you will receive status 's_set_description'. If the result wasn't successful, status field can be: e_set_description.

Specified by:
setDescription in interface BoxExternalAPI
Parameters:
setDescriptionRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

getFileInfo

public GetFileInfoResponse getFileInfo(GetFileInfoRequest getFileInfoRequest)
                                throws java.io.IOException,
                                       BoxException
This method gets file info. 'file_id' param should contain valid if of user file. On successful a result, you will receive status 's_get_file_info' and file info in 'info'. If the result wasn't successful, status field can be: e_access_denied.

Specified by:
getFileInfo in interface BoxExternalAPI
Parameters:
getFileInfoRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

addToTag

public AddToTagResponse addToTag(AddToTagRequest addToTagRequest)
                          throws java.io.IOException,
                                 BoxException
This method adds file or folder to tags list. 'target' param can be either 'file' or 'folder' depending on what do you want to add, 'target_id' is the id of a file or folder to be added, 'tags' array of tags where target will be added. On successful a result, you will receive 'addtotag_ok'. If the result wasn't successful, status field can be: addtotag_error.

Specified by:
addToTag in interface BoxExternalAPI
Parameters:
addToTagRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

addToMyBox

public AddToMyBoxResponse addToMyBox(AddToMyBoxRequest addToMyBoxRequest)
                              throws java.io.IOException,
                                     BoxException
This method copies a file publicly shared by someone to a user's mybox. 'file_id' and 'public_name' params identify a publicly shared file, you should provide either file_id or public name (like '31nhke0ahp') as a parameter. 'folder_id' is the id of a user's folder, where files are to be copied. On a successful result, the status will be 'addtomybox_ok'. If the result wasn't successful, the status field can be: 'addtomybox_error', 'not_logged_id', 'application_restricted', 's_link_exists'.

Specified by:
addToMyBox in interface BoxExternalAPI
Parameters:
addToMyBoxRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

privateShare

public PrivateShareResponse privateShare(PrivateShareRequest privateShareRequest)
                                  throws java.io.IOException,
                                         BoxException
This method privately shares a file or folder with another user(s). 'target' param should be either 'file' or 'folder', 'target_id' is the id of the file or folder to be shared. 'emails' params is an array of emails of users' to share files with. if 'notify' param is true, then a notification email will be sent to users, 'message' param is a message to be included in the notification email. Note: currently only files can be shared privately. On a successful result, the status will be 'private_share_ok'. If the result wasn't successful, the status field can be: 'private_share_error', 'wrong_node', 'not_logged_in', 'application_restricted'.

Specified by:
privateShare in interface BoxExternalAPI
Parameters:
privateShareRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

publicUnshare

public PublicUnshareResponse publicUnshare(PublicUnshareRequest publicUnshareRequest)
                                    throws java.io.IOException,
                                           BoxException
This method unshares a shared file or folder. 'target' param shoud be either 'file' or 'folder', 'target_id' is id of a file or folder to be unshared. 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'.

Specified by:
publicUnshare in interface BoxExternalAPI
Parameters:
publicUnshareRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

publicShare

public PublicShareResponse publicShare(PublicShareRequest publicShareRequest)
                                throws java.io.IOException,
                                       BoxException
This method publicly shares a file or folder. 'target' param should be either 'file' or 'folder', 'target_id' is id of the file or folder to be shared. 'password' param is to protect sharing with a password, 'emails' params is array of emails to notify about a new share, 'message' param is some message to be included in a notification email. On a successful result, the status will be 'share_ok' and 'public_name' param will be a unique identifier of a publicly shared file or folder. If the result wasn't successful, the status field can be: 'share_error', 'wrong_node', 'not_logged_in', 'application_restricted'.

Specified by:
publicShare in interface BoxExternalAPI
Parameters:
publicShareRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

delete

public DeleteResponse delete(DeleteRequest deleteRequest)
                      throws java.io.IOException,
                             BoxException
This method deletes a file or folder. 'target' param can be either 'file' or 'folder' depending on what you want to delete, 'target_id' is id of a file or folder to be deleted. On a successful result, the status will be 's_delete_node'. If the result wasn't successful, status field can be: 'e_delete_node', 'not_logged_in', 'application_restricted'.

Specified by:
delete in interface BoxExternalAPI
Parameters:
deleteRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

rename

public RenameResponse rename(RenameRequest renameRequest)
                      throws java.io.IOException,
                             BoxException
This method renames a file or folder. 'target' param can be either 'file' or 'folder' depending on what you want to rename, 'target_id' is the id of a file or folder to be renamed, 'new_name' is the new name for a file or folder. On a successful result, status will be 's_rename_node'. If result wasn't successful, stat's field can be: 'e_rename_node', 'not_logged_in', 'application_restricted'.

Specified by:
rename in interface BoxExternalAPI
Parameters:
renameRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

move

public MoveResponse move(MoveRequest moveRequest)
                  throws java.io.IOException,
                         BoxException
This method moves a file or folder to another folder. 'target' param can be either 'file' or 'folder' depending on what do you want to move, 'target_id' is the id of a file or folder to be moved, 'destination_id' is the destination folder id. 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'.

Specified by:
move in interface BoxExternalAPI
Parameters:
moveRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

createFolder

public CreateFolderResponse createFolder(CreateFolderRequest createFolderRequest)
                                  throws java.io.IOException,
                                         BoxException
This method creates a new folder. 'parent_id' param is the id of a folder in which a new folder will be created, 'name' param is the name of a new folder. Set 'share' to 1 if you want to share a folder publicly. On a successful result, the status will be 'create_ok'. If the result wasn't successful, status field can be: 'e_no_parent_folder', 'not_logged_in', 'application_r'stricted'.

Specified by:
createFolder in interface BoxExternalAPI
Parameters:
createFolderRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

exportTags

public ExportTagsResponse exportTags(ExportTagsRequest exportTagsRequest)
                              throws java.io.IOException,
                                     BoxException
This method returns all the user's tags. On successful a result, you will receive 'export_tags_ok' and tag_xml will be base64 encoded tags xml. After decoding tag_xml you will get xml like this: music mp3 If the result wasn't successful, status field can be: not_logged_id, application_restricted.

Specified by:
exportTags in interface BoxExternalAPI
Parameters:
exportTagsRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

getAccountTree

public GetAccountTreeResponse getAccountTree(GetAccountTreeRequest getAccountTreeRequest)
                                      throws java.io.IOException,
                                             BoxException
This method is used to get a user's files and folders tree. 'folder_id' param defines root folder from which the tree begins. 'params' is array of string 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 base64 encoded zipped tree xml. So you have to decode the received tree, then unzip it (if you haven't set 'nozip' param) and you will get xml like this: (note that updatedand createdare UNIX timestamps in PST).

Specified by:
getAccountTree in interface BoxExternalAPI
Parameters:
getAccountTreeRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

verifyRegistrationEmail

public VerifyRegistrationEmailResponse verifyRegistrationEmail(VerifyRegistrationEmailRequest verifyRegistrationEmailRequest)
                                                        throws java.io.IOException,
                                                               BoxException
This method is used to verify user registration email . Upon a not used and right registration email, the status param will be 'email_ok'. Else status field can be: 'email_invalid', 'email_already_registered', 'application_restricted'.

Specified by:
verifyRegistrationEmail in interface BoxExternalAPI
Parameters:
verifyRegistrationEmailRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

registerNewUser

public RegisterNewUserResponse registerNewUser(RegisterNewUserRequest registerNewUserRequest)
                                        throws java.io.IOException,
                                               BoxException
This method is used to register a user. Upon a successful registration, the status param will be 'successful_register'. If registration wasn't successful, status field can be: 'e_register', 'email_invalid', 'email_already_registered', 'application_restricted'.

Specified by:
registerNewUser in interface BoxExternalAPI
Parameters:
registerNewUserRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

logout

public LogoutResponse logout(LogoutRequest logoutRequest)
                      throws java.io.IOException,
                             BoxException
This method is used to logout a user. On successful logout method will return 'logout_ok' as status. If logout wasn't successful, then status filed can be: 'invalid_auth_token' when auth_token is invalid.

Specified by:
logout in interface BoxExternalAPI
Parameters:
logoutRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

getAuthToken

public GetAuthTokenResponse getAuthToken(GetAuthTokenRequest getAuthTokenRequest)
                                  throws java.io.IOException,
                                         BoxException
This method is used in the authorization process. You should call this method after the user has authorized themself on box.net site. Pass ticket that you get when called get_ticket method. On a successful result, method will return 'get_auth_token_ok' as status, auth_token to use in other method calls, and user struct which describes logged user. Request.

Specified by:
getAuthToken in interface BoxExternalAPI
Parameters:
getAuthTokenRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception

getTicket

public GetTicketResponse getTicket(GetTicketRequest getTicketRequest)
                            throws java.io.IOException,
                                   BoxException
Description copied from interface: BoxExternalAPI
This method is used in the authorization process.

Specified by:
getTicket in interface BoxExternalAPI
Parameters:
getTicketRequest - request
Returns:
response
Throws:
java.io.IOException - IO exception
BoxException - box exception