com.smartfile.api
Class Client

java.lang.Object
  extended by com.smartfile.api.Client
Direct Known Subclasses:
BasicClient, OAuthClient

public abstract class Client
extends java.lang.Object

Superclass which provides all api calls.

Example of Usage:
First you need to create instance of one of Client subclasses. For example let's assume that we are using basic authentication:
BasicClient api = new BasicClient("client_key","client_secret");
If you API url is different from "https://app.smartfile.com", you should call
api.setApiUrl("yours url here");
Now we can call endpoints:
System.out.println(IOUtils.toString(api.get("/ping")));
We use Apache IOUtils to easily convert InputStream to string.
The default response format is json. If you want to change it, you can send "format" parameter:
System.out.println(IOUtils.toString(api.get("/ping","/","format=xml)));
If you need to send couple of different parameters, it is more convenient to use Map:
Map arg = new HashMap();
arg.put("param1","value1");
arg.put("param2","value2");
System.out.println(IOUtils.toString(api.get("/ping","/",arg)));

File upload.
File file = new File("file.txt");
api.post("/path/data","/",file);
You can also upload multiple files at once, just pass the array or List.

File download.
InputStream in = api.get("/path/data/","file.txt");
out = new FileOutputStream("file.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}


Method Summary
 void addHeader(java.lang.String name, java.lang.String value)
          Adds a header to request
 java.io.InputStream delete(java.lang.String endpoint)
          Executes delete request to the endpoint with no params.
 java.io.InputStream delete(java.lang.String endpoint, java.lang.String id)
          Executes delete request to the endpoint and id with no params.
 java.io.InputStream delete(java.lang.String endpoint, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> args)
          Executes delete request to the endpoint and id with params as Map<String, String>
 java.io.InputStream delete(java.lang.String endpoint, java.lang.String id, java.lang.String args)
          Executes delete request to the endpoint and id with params as String Use it when you need few params with same name, like when copying or moving objects
 java.io.InputStream get(java.lang.String endpoint)
          Executes get request to the endpoint with no params.
 java.io.InputStream get(java.lang.String endpoint, java.lang.String id)
          Executes get request to the endpoint and id with no params.
 java.io.InputStream get(java.lang.String endpoint, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> args)
          Executes get request to the endpoint and id with params as Map<String, String>
 java.io.InputStream get(java.lang.String endpoint, java.lang.String id, java.lang.String args)
          Executes get request to the endpoint and id with params as String Use it when you need few params with same name, like when copying or moving objects
 java.lang.String getApiUrl()
           
 java.io.InputStream post(java.lang.String endpoint, java.lang.String id, java.io.File file)
          Executes post request to the endpoint and id with file in request body.
 java.io.InputStream post(java.lang.String endpoint, java.lang.String id, java.io.File[] files)
          Executes post request to the endpoint and id with files in request body.
 java.io.InputStream post(java.lang.String endpoint, java.lang.String id, java.util.List<java.io.File> files)
          Executes post request to the endpoint and id with files in request body.
 java.io.InputStream post(java.lang.String endpoint, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> args)
          Executes post request to the endpoint and id with params as Map<String, String>
 java.io.InputStream post(java.lang.String endpoint, java.lang.String id, java.lang.String args)
          Executes post request to the endpoint and id with params as String Use it when you need few params with same name, like when copying or moving objects
 java.io.InputStream put(java.lang.String endpoint)
          Executes put request to the endpoint with no params.
 java.io.InputStream put(java.lang.String endpoint, java.lang.String id)
          Executes put request to the endpoint and id with no params.
 java.io.InputStream put(java.lang.String endpoint, java.lang.String id, java.util.Map<java.lang.String,java.lang.String> args)
          Executes put request to the endpoint and id with params as Map<String, String>
 java.io.InputStream put(java.lang.String endpoint, java.lang.String id, java.lang.String args)
          Executes put request to the endpoint and id with params as String Use it when you need few params with same name, like when copying or moving objects
 void setApiUrl()
          Use this method to set you own API url stored at environment variable SMARTFILE_API_URL instead of default "https://app.smartfile.com"
 void setApiUrl(java.lang.String url)
          Use this method to set you own API url instead of default "https://app.smartfile.com"
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setApiUrl

public void setApiUrl()
Use this method to set you own API url stored at environment variable SMARTFILE_API_URL instead of default "https://app.smartfile.com"


setApiUrl

public void setApiUrl(java.lang.String url)
Use this method to set you own API url instead of default "https://app.smartfile.com"

Parameters:
url - Yours API url

getApiUrl

public java.lang.String getApiUrl()
Returns:
String - the api url

addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
Adds a header to request

Parameters:
name - Header name
value - Header value

get

public java.io.InputStream get(java.lang.String endpoint)
                        throws SmartFileException
Executes get request to the endpoint with no params.

Parameters:
endpoint - The endpoint the request sent to
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

get

public java.io.InputStream get(java.lang.String endpoint,
                               java.lang.String id)
                        throws SmartFileException
Executes get request to the endpoint and id with no params.

Parameters:
endpoint - The endpoint the request sent to
id - API id
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

get

public java.io.InputStream get(java.lang.String endpoint,
                               java.lang.String id,
                               java.util.Map<java.lang.String,java.lang.String> args)
                        throws SmartFileException
Executes get request to the endpoint and id with params as Map<String, String>

Parameters:
endpoint - The endpoint the request sent to
id - API id
args - Key-Value pairs of request params
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

get

public java.io.InputStream get(java.lang.String endpoint,
                               java.lang.String id,
                               java.lang.String args)
                        throws SmartFileException
Executes get request to the endpoint and id with params as String Use it when you need few params with same name, like when copying or moving objects

Parameters:
endpoint - The endpoint the request sent to
id - API id
args - String of http request params like: "param1=value1¶m2=value2"
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

post

public java.io.InputStream post(java.lang.String endpoint,
                                java.lang.String id,
                                java.util.Map<java.lang.String,java.lang.String> args)
                         throws SmartFileException
Executes post request to the endpoint and id with params as Map<String, String>

Parameters:
endpoint - The endpoint the request sent to
id - API id
args - Key-Value pairs of request params
Returns:
InputStream server response.
Throws:
SmartFileException

post

public java.io.InputStream post(java.lang.String endpoint,
                                java.lang.String id,
                                java.lang.String args)
                         throws SmartFileException
Executes post request to the endpoint and id with params as String Use it when you need few params with same name, like when copying or moving objects

Parameters:
endpoint - The endpoint the request sent to
id - API id
args - String of http request params like: "param1=value1¶m2=value2"
Returns:
InputStream server response.
Throws:
SmartFileException

post

public java.io.InputStream post(java.lang.String endpoint,
                                java.lang.String id,
                                java.io.File file)
                         throws SmartFileException
Executes post request to the endpoint and id with file in request body. Use it when you need to upload single file

Parameters:
endpoint - The endpoint the request sent to
id - API id
file - File to upload
Returns:
InputStream server response.
Throws:
SmartFileException

post

public java.io.InputStream post(java.lang.String endpoint,
                                java.lang.String id,
                                java.io.File[] files)
                         throws SmartFileException
Executes post request to the endpoint and id with files in request body. Use it when you need to upload multiple files.

Parameters:
endpoint - The endpoint the request sent to
id - API id
files - File[] array to upload.
Returns:
InputStream server response.
Throws:
SmartFileException

post

public java.io.InputStream post(java.lang.String endpoint,
                                java.lang.String id,
                                java.util.List<java.io.File> files)
                         throws SmartFileException
Executes post request to the endpoint and id with files in request body. Use it when you need to upload multiple files.

Parameters:
endpoint - The endpoint the request sent to
id - API id
files - List<File> array to upload.
Returns:
InputStream server response.
Throws:
SmartFileException

put

public java.io.InputStream put(java.lang.String endpoint)
                        throws SmartFileException
Executes put request to the endpoint with no params.

Parameters:
endpoint - The endpoint the request sent to
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

put

public java.io.InputStream put(java.lang.String endpoint,
                               java.lang.String id)
                        throws SmartFileException
Executes put request to the endpoint and id with no params.

Parameters:
endpoint - The endpoint the request sent to
id - API id
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

put

public java.io.InputStream put(java.lang.String endpoint,
                               java.lang.String id,
                               java.util.Map<java.lang.String,java.lang.String> args)
                        throws SmartFileException
Executes put request to the endpoint and id with params as Map<String, String>

Parameters:
endpoint - The endpoint the request sent to
id - API id
args - Key-Value pairs of request params
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

put

public java.io.InputStream put(java.lang.String endpoint,
                               java.lang.String id,
                               java.lang.String args)
                        throws SmartFileException
Executes put request to the endpoint and id with params as String Use it when you need few params with same name, like when copying or moving objects

Parameters:
endpoint - The endpoint the request sent to
id - API id
args - String of http request params like: "param1=value1¶m2=value2"
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

delete

public java.io.InputStream delete(java.lang.String endpoint)
                           throws SmartFileException
Executes delete request to the endpoint with no params.

Parameters:
endpoint - The endpoint the request sent to
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

delete

public java.io.InputStream delete(java.lang.String endpoint,
                                  java.lang.String id)
                           throws SmartFileException
Executes delete request to the endpoint and id with no params.

Parameters:
endpoint - The endpoint the request sent to
id - API id
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

delete

public java.io.InputStream delete(java.lang.String endpoint,
                                  java.lang.String id,
                                  java.util.Map<java.lang.String,java.lang.String> args)
                           throws SmartFileException
Executes delete request to the endpoint and id with params as Map<String, String>

Parameters:
endpoint - The endpoint the request sent to
id - API id
args - Key-Value pairs of request params
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException

delete

public java.io.InputStream delete(java.lang.String endpoint,
                                  java.lang.String id,
                                  java.lang.String args)
                           throws SmartFileException
Executes delete request to the endpoint and id with params as String Use it when you need few params with same name, like when copying or moving objects

Parameters:
endpoint - The endpoint the request sent to
id - API id
args - String of http request params like: "param1=value1¶m2=value2"
Returns:
InputStream. You should convert it to File if you expect result to be a file or to String otherwise.
Throws:
SmartFileException