|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.smartfile.api.Client
public abstract class Client
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.put("param1","value1");
arg.put("param2","value2");
System.out.println(IOUtils.toString(api.get("/ping","/",arg)));
File upload.
File file = new File("file.txt");
You can also upload multiple files at once, just pass the array or List.
api.post("/path/data","/",file);
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 |
|---|
public void setApiUrl()
public void setApiUrl(java.lang.String url)
url - Yours API urlpublic java.lang.String getApiUrl()
public void addHeader(java.lang.String name,
java.lang.String value)
name - Header namevalue - Header value
public java.io.InputStream get(java.lang.String endpoint)
throws SmartFileException
endpoint - The endpoint the request sent to
SmartFileException
public java.io.InputStream get(java.lang.String endpoint,
java.lang.String id)
throws SmartFileException
endpoint - The endpoint the request sent toid - API id
SmartFileException
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
Map<String, String>
endpoint - The endpoint the request sent toid - API idargs - Key-Value pairs of request params
SmartFileException
public java.io.InputStream get(java.lang.String endpoint,
java.lang.String id,
java.lang.String args)
throws SmartFileException
String
Use it when you need few params with same name, like when copying or moving objects
endpoint - The endpoint the request sent toid - API idargs - String of http request params like: "param1=value1¶m2=value2"
SmartFileException
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
Map<String, String>
endpoint - The endpoint the request sent toid - API idargs - Key-Value pairs of request params
SmartFileException
public java.io.InputStream post(java.lang.String endpoint,
java.lang.String id,
java.lang.String args)
throws SmartFileException
String
Use it when you need few params with same name, like when copying or moving objects
endpoint - The endpoint the request sent toid - API idargs - String of http request params like: "param1=value1¶m2=value2"
SmartFileException
public java.io.InputStream post(java.lang.String endpoint,
java.lang.String id,
java.io.File file)
throws SmartFileException
endpoint - The endpoint the request sent toid - API idfile - File to upload
SmartFileException
public java.io.InputStream post(java.lang.String endpoint,
java.lang.String id,
java.io.File[] files)
throws SmartFileException
endpoint - The endpoint the request sent toid - API idfiles - File[] array to upload.
SmartFileException
public java.io.InputStream post(java.lang.String endpoint,
java.lang.String id,
java.util.List<java.io.File> files)
throws SmartFileException
endpoint - The endpoint the request sent toid - API idfiles - List<File> array to upload.
SmartFileException
public java.io.InputStream put(java.lang.String endpoint)
throws SmartFileException
endpoint - The endpoint the request sent to
SmartFileException
public java.io.InputStream put(java.lang.String endpoint,
java.lang.String id)
throws SmartFileException
endpoint - The endpoint the request sent toid - API id
SmartFileException
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
Map<String, String>
endpoint - The endpoint the request sent toid - API idargs - Key-Value pairs of request params
SmartFileException
public java.io.InputStream put(java.lang.String endpoint,
java.lang.String id,
java.lang.String args)
throws SmartFileException
String
Use it when you need few params with same name, like when copying or moving objects
endpoint - The endpoint the request sent toid - API idargs - String of http request params like: "param1=value1¶m2=value2"
SmartFileException
public java.io.InputStream delete(java.lang.String endpoint)
throws SmartFileException
endpoint - The endpoint the request sent to
SmartFileException
public java.io.InputStream delete(java.lang.String endpoint,
java.lang.String id)
throws SmartFileException
endpoint - The endpoint the request sent toid - API id
SmartFileException
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
Map<String, String>
endpoint - The endpoint the request sent toid - API idargs - Key-Value pairs of request params
SmartFileException
public java.io.InputStream delete(java.lang.String endpoint,
java.lang.String id,
java.lang.String args)
throws SmartFileException
String
Use it when you need few params with same name, like when copying or moving objects
endpoint - The endpoint the request sent toid - API idargs - String of http request params like: "param1=value1¶m2=value2"
SmartFileException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||