public class DatashopClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
BUFFER_SIZE
number of bytes to read at a time.
|
Constructor and Description |
---|
DatashopClient(java.lang.String apiToken,
java.lang.String secret)
Constructor.
|
DatashopClient(java.lang.String servicesRoot,
java.lang.String apiToken,
java.lang.String secret)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getApiToken()
Gets the API token.
|
java.lang.String |
getDataset(java.lang.Integer id)
Convenience method for calling the dataset web service.
|
java.lang.String |
getDatasetAdd(java.lang.String name,
java.lang.Long instanceId)
Convenience method for calling the dataset add web service.
|
java.lang.String |
getDatasetDelete(java.lang.Integer id)
Convenience method for calling the dataset delete web service.
|
java.lang.String |
getDatasetSet(java.lang.Integer id,
java.lang.String datasetInfo)
Convenience method for calling the dataset set web service.
|
static DatashopClient |
getDatashopClientForLocalRequests()
Instantiates a Datashop client to be used for remote requests to master DataShop servers.
|
static DatashopClient |
getDatashopClientForRemoteRequests()
Instantiates a Datashop client to be used for remote requests to master DataShop servers.
|
java.lang.String |
getDiscourseAdd(java.lang.String name,
java.lang.Long instanceId)
Convenience method for calling the discourse add web service.
|
java.lang.String |
getDiscourseDelete(java.lang.Long id)
Convenience method for calling the discourse delete web service.
|
java.lang.String |
getDiscourseSet(java.lang.Long id,
java.lang.String discourseInfo)
Convenience method for calling the discourse set web service.
|
java.lang.String |
getHelloWorld()
Hello World is our sanity check, to confirm that web services are up and running.
|
java.lang.String |
getInstanceAdd(java.lang.String name,
java.lang.String url)
Convenience method for calling the instance add web service.
|
java.lang.String |
getInstanceSet(java.lang.Long instanceId,
java.lang.String name,
java.lang.String url)
Convenience method for calling the instance set web service.
|
java.lang.String |
getPostService(java.lang.String path,
java.lang.String postData,
java.lang.String accept)
Get the results of calling the specified service as a string.
|
java.lang.String |
getPostServiceWithFileUpload(java.lang.String servicePath,
java.util.Map<java.lang.String,java.lang.String> postDataPairs,
java.lang.String accept,
java.lang.String fileName)
Get the results of calling the specified post service with a file to upload.
|
java.lang.String |
getRootURL()
Returns the root URL.
|
java.lang.String |
getSample(java.lang.Integer datasetId,
java.lang.Integer sampleId)
Convenience method for calling the sample web service.
|
java.lang.String |
getSecret()
Gets the secret.
|
java.lang.String |
getService(java.lang.String path,
java.lang.String accept)
Get the results of calling the specified service as a string.
|
static void |
main(java.lang.String[] args)
Run DatashopClient from the command line.
|
protected void |
print(java.io.InputStream in,
java.io.OutputStream out)
Print the entire contents of in to out.
|
void |
printDataset(java.lang.Integer id)
Convenience method for calling the dataset web service.
|
void |
printHelloWorld()
Hello World is our sanity check, to confirm that web services are up and running.
|
void |
printSample(java.lang.Integer datasetId,
java.lang.Integer sampleId)
Convenience method for calling the sample web service.
|
void |
printService(java.lang.String path,
java.lang.String accept)
Print the results of calling the specified service to standard out.
|
protected java.lang.String |
printToString(java.io.InputStream is)
Return the entire contents of the input stream as a string.
|
java.net.HttpURLConnection |
serviceGetConnection(java.lang.String servicePath)
Signed connection to the service specified by path using HTTP GET method.
|
java.net.HttpURLConnection |
servicePostConnection(java.lang.String servicePath,
java.lang.String contentType)
Signed connection to the service specified by path with HTTP method POST.
|
java.net.HttpURLConnection |
servicePutConnection(java.lang.String servicePath)
Signed connection to the service specified by path with HTTP method PUT.
|
void |
setApiToken(java.lang.String apiToken)
Sets the API token.
|
void |
setRootURL(java.lang.String rootURL)
Sets the root URL.
|
void |
setSecret(java.lang.String secret)
Sets the secret
|
public static final int BUFFER_SIZE
public DatashopClient(java.lang.String servicesRoot, java.lang.String apiToken, java.lang.String secret)
servicesRoot
- URL prefix for web servicesapiToken
- public API token for authenticationsecret
- secret key for authenticationpublic DatashopClient(java.lang.String apiToken, java.lang.String secret)
apiToken
- public API token for authenticationsecret
- secret key for authenticationpublic static DatashopClient getDatashopClientForRemoteRequests()
public static DatashopClient getDatashopClientForLocalRequests()
public java.lang.String getRootURL()
public void setRootURL(java.lang.String rootURL)
public java.lang.String getApiToken()
public void setApiToken(java.lang.String apiToken)
apiToken
- the API tokenpublic java.lang.String getSecret()
public void setSecret(java.lang.String secret)
secret
- the secretpublic java.net.HttpURLConnection serviceGetConnection(java.lang.String servicePath)
servicePath
- specifies the service to GETpublic java.net.HttpURLConnection servicePutConnection(java.lang.String servicePath)
servicePath
- specifies the service to PUTpublic java.net.HttpURLConnection servicePostConnection(java.lang.String servicePath, java.lang.String contentType)
servicePath
- specifies the servicecontentType
- mime type of contentpublic void printService(java.lang.String path, java.lang.String accept) throws java.io.IOException
path
- the path indicating which web service to call.accept
- mime type we expect in return, such as text/xml
(should we allow multiple values here?)java.io.IOException
- thrown if there is a communications problempublic java.lang.String getService(java.lang.String path, java.lang.String accept) throws java.io.IOException
path
- the path indicating which web service to call.accept
- mime type we expect in return, such as text/xml
(should we allow multiple values here?)java.io.IOException
- thrown if there is a communications problempublic java.lang.String getPostService(java.lang.String path, java.lang.String postData, java.lang.String accept) throws java.io.IOException
path
- the path indicating which web service to call.postData
- the contentaccept
- mime type we expect in return, such as text/xmljava.io.IOException
- thrown if there is a communications problempublic java.lang.String getPostServiceWithFileUpload(java.lang.String servicePath, java.util.Map<java.lang.String,java.lang.String> postDataPairs, java.lang.String accept, java.lang.String fileName) throws java.io.IOException
path
- the path indicating which web service to call.postData
- the contentaccept
- mime type we expect in return, such as text/xmljava.io.IOException
- thrown if there is a communications problemprotected void print(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- the input streamout
- the output streamjava.io.IOException
- if something goes wrongprotected java.lang.String printToString(java.io.InputStream is) throws java.io.IOException
is
- the input streamjava.io.IOException
- if something goes wrongpublic void printHelloWorld() throws java.lang.Exception
java.lang.Exception
- if something goes wrongpublic java.lang.String getHelloWorld() throws java.lang.Exception
java.lang.Exception
- if something goes wrongpublic void printDataset(java.lang.Integer id) throws java.io.IOException
id
- the dataset idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getDataset(java.lang.Integer id) throws java.io.IOException
id
- the dataset idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getDatasetAdd(java.lang.String name, java.lang.Long instanceId) throws java.io.IOException
name
- the dataset nameinstanceId
- the remote instance idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getDatasetDelete(java.lang.Integer id) throws java.io.IOException
id
- the dataset idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getDatasetSet(java.lang.Integer id, java.lang.String datasetInfo) throws java.io.IOException
id
- the dataset iddatasetInfo
- the meta-data for the dataset as XMLjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getDiscourseAdd(java.lang.String name, java.lang.Long instanceId) throws java.io.IOException
name
- the discourse nameinstanceId
- the remote instance idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getDiscourseDelete(java.lang.Long id) throws java.io.IOException
id
- the discourse idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getDiscourseSet(java.lang.Long id, java.lang.String discourseInfo) throws java.io.IOException
id
- the discourse iddiscourseInfo
- the meta-data for the discourse as XMLjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getInstanceAdd(java.lang.String name, java.lang.String url) throws java.io.IOException
name
- the instance nameurl
- the DataShop URL for the instancejava.io.IOException
- thrown if there is a communications problempublic java.lang.String getInstanceSet(java.lang.Long instanceId, java.lang.String name, java.lang.String url) throws java.io.IOException
instanceId
- the remote instance idname
- the instance nameurl
- the DataShop URL for the instancejava.io.IOException
- thrown if there is a communications problempublic void printSample(java.lang.Integer datasetId, java.lang.Integer sampleId) throws java.io.IOException
datasetId
- the dataset idsampleId
- the sample idjava.io.IOException
- thrown if there is a communications problempublic java.lang.String getSample(java.lang.Integer datasetId, java.lang.Integer sampleId) throws java.io.IOException
datasetId
- the dataset idsampleId
- the sample idjava.io.IOException
- thrown if there is a communications problempublic static void main(java.lang.String[] args)
args
- Arguments are alternating keys and values. Valid keys are
apitoken - the user's public token
secret - the user's secret key
root - the root URL for the web service host
path - the path indicating which web service to call.
file - name of the file to upload to the server
ALTERNATIVE: a single argument is taken to be a complete web services URL to call,
with the credentials provided in webservices.properties.Copyright (c) 2015 - Pittsburgh Science of Learning Center