Package com.logicaldoc.sharefile
Class ShareFileClient
- java.lang.Object
-
- com.logicaldoc.sharefile.ShareFileClient
-
public class ShareFileClient extends Object
The functions in this file will make use of the ShareFile API v3 to show some of the basic operations using GET, POST, PATCH, DELETE HTTP verbs. See api.sharefile.com for more information. Requirements: 1. JSON library - google gson, https://code.google.com/p/google-gson/ Authentication: OAuth2 password grant is used for authentication. After the token is acquired it is sent an an authorization header with subsequent API requests.
-
-
Constructor Summary
Constructors Constructor Description ShareFileClient(String accountHost)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addAuthorizationHeader(HttpURLConnection connection, com.logicaldoc.sharefile.ShareFileClient.OAuth2Token token)
void
authenticate(String username, String password)
Authenticate via username/passwordString
createFolder(String parentId, String name, String description)
Create a new folder in the given parent folder.String
createPath(String parentId, String path)
Creates a pathvoid
deleteItem(String id)
Delete an Item by Id.void
downloadItem(String id, File file)
Download a single Item.String
getAccountHost()
static String
getHostname(com.logicaldoc.sharefile.ShareFileClient.OAuth2Token token)
SFile
getItemById(String id)
Gets a single Item by Id.SFile
getItemByPath(String parentId, String path)
Retrieves an item from its path.String
getItemPath(String parentId, String itemId)
Constructs the path of a given element, optionally relative to a given parent folder.List<SFile>
getRoot()
Get the root level Item for the provided user.List<SFile>
list(String folderId)
Get a folder using some of the common query parameters that are available.List<SFile>
listFilesInTree(String folderId)
void
setAccountHost(String accountHost)
void
updateItem(String id, String name, String description)
Update the name and description of an Item.void
uploadFile(String parentId, File file, String filename)
Uploads a File using the Standard upload method with a multipart/form mime encoded POST.void
uploadFileIntoPath(String parentId, String path, File file)
Uploads a File using the Standard upload method with a multipart/form mime encoded POST.
-
-
-
Constructor Detail
-
ShareFileClient
public ShareFileClient(String accountHost)
-
-
Method Detail
-
authenticate
public void authenticate(String username, String password) throws IOException
Authenticate via username/password- Parameters:
username
- - my@user.namepassword
- - mypassword- Throws:
IOException
- the authentication was not successfull
-
addAuthorizationHeader
public static void addAuthorizationHeader(HttpURLConnection connection, com.logicaldoc.sharefile.ShareFileClient.OAuth2Token token)
-
getHostname
public static String getHostname(com.logicaldoc.sharefile.ShareFileClient.OAuth2Token token)
-
getRoot
public List<SFile> getRoot() throws IOException, ParseException
Get the root level Item for the provided user. To retrieve Children the $expand=Children parameter can be added- Returns:
- list of files
- Throws:
org.apache.http.client.ClientProtocolException
- error in the communication with the FileShare serverIOException
- error in the communication with the FileShare serverParseException
- bad communication format
-
getItemById
public SFile getItemById(String id) throws IOException, ParseException
Gets a single Item by Id.- Parameters:
id
- - an Item Id- Returns:
- the file
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
getItemByPath
public SFile getItemByPath(String parentId, String path) throws IOException, ParseException
Retrieves an item from its path. The path is of format /foldername/foldername/filename- Parameters:
parentId
- - optional ID of the parent pathpath
- - an Item path- Returns:
- the file
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
getItemPath
public String getItemPath(String parentId, String itemId) throws IOException, ParseException
Constructs the path of a given element, optionally relative to a given parent folder.- Parameters:
parentId
- ID of the parent folder (leave null for getting the absolute pathitemId
- ID of the item to process- Returns:
- The path of the given element
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
listFilesInTree
public List<SFile> listFilesInTree(String folderId) throws IOException, ParseException
- Throws:
IOException
ParseException
-
list
public List<SFile> list(String folderId) throws IOException, ParseException
Get a folder using some of the common query parameters that are available. This will add the expand, select parameters. The following are used: expand=Children to get any Children of the folder select=Id,Name,Children/Id,Children/Name to get the Id, Name of the folder and the Id, Name of any Children- Parameters:
folderId
- - a Folder Id- Returns:
- list of files
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
createPath
public String createPath(String parentId, String path) throws IOException, ParseException
Creates a path- Parameters:
parentId
- If specified identifies the parent folderpath
- The path to create /folder1/folder2- Returns:
- identifier of the created folder
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
createFolder
public String createFolder(String parentId, String name, String description) throws IOException, ParseException
Create a new folder in the given parent folder.- Parameters:
parentId
- - the parent Folder in which to create the new Foldername
- - the Folder namedescription
- - the Folder description- Returns:
- The new Folder's ID
- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
updateItem
public void updateItem(String id, String name, String description) throws IOException, ParseException
Update the name and description of an Item.- Parameters:
id
- - the id of the Item to updatename
- - the new name of the Itemdescription
- - the new description of the Item- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
deleteItem
public void deleteItem(String id) throws IOException, ParseException
Delete an Item by Id.- Parameters:
id
- - the Id of the Item to delete- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
downloadItem
public void downloadItem(String id, File file) throws IOException, ParseException
Download a single Item.- Parameters:
id
- - the Id of the Item to downloadfile
- - full path including file name of download destination.- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
uploadFileIntoPath
public void uploadFileIntoPath(String parentId, String path, File file) throws IOException, ParseException
Uploads a File using the Standard upload method with a multipart/form mime encoded POST.- Parameters:
parentId
- - Id of the parent folderpath
- - Relative path of the file /folder/folder/filenamefile
- - the path of the file to upload- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
uploadFile
public void uploadFile(String parentId, File file, String filename) throws IOException, ParseException
Uploads a File using the Standard upload method with a multipart/form mime encoded POST.- Parameters:
parentId
- - where to upload the Filefile
- - the path of the file to uploadfilename
- - the name of the file to create- Throws:
IOException
- error in the FileShare serverParseException
- bad communication protocol
-
getAccountHost
public String getAccountHost()
-
setAccountHost
public void setAccountHost(String accountHost)
-
-