If you are working with a Java environment we provide a Java package that provides library functions to make interacting with the CloudTables API as simple as initializing a class and a method call. Using the library you can easily embed data sets securely into your pages, get information about data sets and the data of a specified dataset.
The CloudTables libraries are available for download on Bitbucket.
You will also need a JDK and a JRE to use these libraries if you do not have one already. Instructions on how to install a JDK and a JRE can be found here.
To import the CloudTables API into your project use the following line.
import CloudTablesApi.*;
Once imported into your application, an instance can be created using:
CloudTableApi api = new CloudTablesApi("sub-domain", "{apiKey}")
.clientId("Unique client id") // Client id (e.g. a login id) - optional
.clientName("Name"); // Client's name - optional
Where:
{apiKey}
should be replaced by the API key that you want to use for the access.clientId
and clientName
parameters are optional, but we strongly recommend they are used when integrating with your own login system as it allows the identification of each client's actions in CloudTables' auditing features. Typically the clientId
would be set to your login system's user id and clientName
the user's username or full name.A new CloudTablesApi
instance should be created for each access request, as it will cache and reuse the access token if one is required.
There are two methods provided by the library which can be used to embed a data set into your HTML page. The end result is a <script>
tag which includes an access token. This can be called directly from your JSP page as follows.
The scriptTag
method can be used to get an access token (based on the initialisation options) for a data set, and will return a String that contains the full <script>
tag that should be inserted into your HTML:
String script = api.scriptTag("{data-set-id}");
Where:
{data-set-id}
is the ID of the data set you wish to embed into the page. The data set ID can be found in the Inspector for the data set on the Data tab.Alternatively, you can also build your own <script>
tag based on a token:
String token = api.token();
String script = "<script src=\"https://sub-domain.cloudtables.io/loader/{data-set-id}/table/d\" data-token=\"" + token + "\"></script>";
new CloudTablesApi(String subdomain, String key)
Creates a new instance of the CloudTables API libraries.
String
- The application sub-domain for your CloudTables (i.e. the part before .cloudtables.com
).String
- The API key to be used.public DatasetData data(String dataset)
Get the data and columns for a given dataset.
String dataset
- ID of the data set to get the data of. See the Data page for the data set to get its ID, or use the .datasets()
method.DatasetData
containing data
and columns
array lists. Please refer to the API documentation for a full description of the structure returned.public Datasets datasets()
Get summary information about the available datasets (note that the roles applied in the constructor can restrict access so certain data sets will not be shown).
Datasets
with property datasets
which is an array containing information about the available data sets in the form of DatasetInfo
. Please refer to the API documentation for a full description of the structure returned.public String scriptTag(String dataset)
public String scriptTag(String token, String dataset)
public String scriptTag(String token, String dataset, String style)
Get a <script>
tag for a specific dataset to be displayed as a table. Insert this script tag where you want the table to appear in your HTML.
String dataset
- ID (UUID) of the dataset to be shown
*. String token
- Secure access token (from .token()
)
*. String style
- The styling framework to use for this table. Can be one of:
d
- Defaultauto
- Auto detectbs
- Bootstrap 3bs4
- Bootstrap 4dt
- CloudTables / DataTables default stylingzf
- Zurb Foundationju
- jQuery UIse
- Semantic UIno
- No styling<script>
tag to use.public String scriptTagAsync(String dataset, String style)
Get a <script>
tag for a specific dataset to be displayed as a table. Insert this script tag where you want the table to appear in your HTML. This is the same as scriptTag
, but it will retrieve the secure access token for you.
String dataset
- ID (UUID) of the dataset to be shownString style
- The styling framework to use for this table. See the scriptTag
method for valid values.<script>
tag to use.public String token()
Get an access token. Note that this value is cached per API instance. It will only be obtained from the CloudTables server's once.
<script>
tag to access a data set.Methods used to configure the Api instance for access.
A unique id for the client accessing the table on your system. While this is optional it is a recommended parameter as it is useful for tracking requests in CloudTables’ analytics.
Api clientId(String value)
String value
- Client ID to use.this
for chaining.A label that can help identify a user - e.g. a name or e-mail address.
Api clientName(String value)
String value
- Client name to use.this
for chaining.Condition(s) to apply to data being fetched. Please see the embedding conditions documentation for full details. Requires Cloudtables.Api
1.1 or newer. Note that this method can be called multiple times to add additional conditions to the access request. They will then be combined with AND logic.
Please see below for a full description of the CloudTables.Condition
class and its methods.
Api condition(Condition cond)
Condition cond
- Condition to apply to the data access.this
for chaining.Host domain for the CloudTables instance. Used for self-hosted installs of CloudTables.
Api domain(String value)
String value
- Domain name or IP address.this
for chaining.Access token’s idle time out (defaults to 20 minutes).
Api duration(int value)
int value
- Idle time out value (seconds).this
for chaining.Per roles
but for a single role only.
Api role(String value)
String value
- role to assign.this
for chaining.The name of the role that should be used for the generated access token (if assigned to the API key - if the role is not available for the API key no access will be granted). If not provided then all roles available to the API key will be used.
Api roles(IEnumerable<String> value)
ArrayList<String> value
- roles to assign.this
for chaining.Use https
or http
connections. Used for self-hosted installs of CloudTables.
Api ssl(String value)
boolean value
- SSL flagthis
for chaining.Creates a new condition instance which can be applied to a data access request, limiting the data that will be returned by the server. See the embedding conditions documentation for full details.
new Condition();
new Condition(String id, String value);
String
- The id of the data point the condition should be applied to.String
- The value to use.Set the id of the data point to perform the condition on. The ids can be found from your data set's Data page and click on the item in question. The id will be shown in the item inspector on the right. It will start dp-
for a regular data point. Conditions on computed values (c-
) and links (l-
) are not currently supported.
Condition id(String id)
String id
- The id of the data point to perform the condition on.this
for chaining.Set the name of the data point to perform the condition on. This can be given as an alternative to the id
option as it is easier to remember. However, while the id
is static, the name
can be changed in the application.
Condition name(String name)
String id
- The data point's name that the condition should be performed upon.this
for chaining.Set the conditional operator.
Condition op(String op)
String op
- Conditional operator - it may be one of =
, !=
, <
, <=
, >=
, >
.this
for chaining.Mark the value to be set (default) or not when creating a new row.
Condition set(boolean set)
boolean set
- When a new record is created, the API can set the data point to a specific value (defined by setValue
or value
if the former is not specified).this
for chaining.The value that will be written to the database if Set
is enabled. Note that Value
will be used by default, and this method can override it with a new value to be set. It must be specified if Op
is not set to =
.
Condition setValue(String setValue)
String setValue
- Value to set when a new record is created.this
for chaining.The value that will be used for the conditional matching, and for writing to new records, unless SetValue
is specified. The formatting must follow these rules:
date
- ISO 8601 (date only)datetime
- ISO 8601number
- Unformatted numbertext
- Plain texttime
- ISO 8601 (time only).Condition value(String value)
String Value
- Value to set when a new record is created.this
for chaining.Our API libraries for CloudTables are open source under the MIT license. The Java source is available here and pull requests or suggestions for it are welcome.