public class Service
extends java.lang.Object
All transactions are done within the context of a customer, which is the account entity of the API. On initiation, the customer context is set based on which customer the authenticated user is linked to on the server. If the user has access to multiple accounts, a list is available from the ServiceSpec object, and the customer context can be changed with setCustomerContext.
The server transactions are blocking (make sure to not run them in a UI thread), with an Exception thrown if there is a problem and normal completion signifying success.
Constructor and Description |
---|
Service(java.lang.String url) |
Service(java.lang.String url,
int connectTimeout,
int readTimeout) |
Modifier and Type | Method and Description |
---|---|
JSONArray |
doTransaction(ResourceTransaction trans)
Wrapper method executing ResourceTransactions, returning the reply
objects if successful and throwing an Exception if not.
|
ServiceSpec |
getServiceSpec()
The ServiceSpec object has account information for the current client
session, such as user and customer entities and access rights, once
the service has been initiated.
|
void |
initiate(java.lang.String authenticationToken)
Initiate the service, authenticating the client with an authentication
token.
|
void |
initiate(java.lang.String username,
java.lang.String password)
Initiate the service, authenticating the client with user name and
password.
|
void |
setCustomerContext(long customerId)
If the currently authenticated user has access to multiple customer
accounts, it is possible to switch between them, to target a different
account.
|
public Service(java.lang.String url)
url
- server URL, such as https://www.smarttracker.no/web
public Service(java.lang.String url, int connectTimeout, int readTimeout)
url
- server URL, such as https://www.smarttracker.no/web
connectTimeout
- connection timeout for transactions (milliseconds), 0 for nonereadTimeout
- read timeout for transactions (milliseconds), 0 for nonepublic void initiate(java.lang.String username, java.lang.String password) throws java.io.IOException, TransactionException
If the initiation is unsuccessful, an Exception is thrown. An IOException is thrown if there is a network error (couldn't reach the server). A TransactionException is thrown if there was a protocol or parsing error, or the server responded with an error code. This exception has any error code and Exception from the error, and a String message (taken from the server response, if it included an error message).
username
- password
- java.io.IOException
- if there is an error with the server connectionTransactionException
- if there is a protocol, parsing or server response errorpublic void initiate(java.lang.String authenticationToken) throws java.io.IOException, TransactionException
If the transactions is unsuccessful, an Exception is thrown. An IOException is thrown if there is a network error (couldn't reach the server). A TransactionException is thrown if there was a protocol or parsing error, or the server responded with an error code. This exception has any error code and Exception from the error, and a String message (taken from the server response, if it included an error message).
authenticationToken
- java.io.IOException
- if there is an error with the server connectionTransactionException
- if there is a protocol, parsing or server response errorpublic ServiceSpec getServiceSpec()
public void setCustomerContext(long customerId) throws java.io.IOException, TransactionException
customerId
- account to switch tojava.io.IOException
- if there is an error with the server connectionTransactionException
- if there is a protocol, parsing or server response errorpublic JSONArray doTransaction(ResourceTransaction trans) throws java.io.IOException, TransactionException
An IOException is thrown if there is a network error (couldn't reach the server). A TransactionException is thrown if there was a protocol or parsing error, or the server responded with an error code. This exception has any error code and Exception from the error, and a String message (taken from the server response, if it included an error message).
trans
- specifies the transactionjava.io.IOException
- if there is an error with the server connectionTransactionException
- if there is a protocol, parsing or server response error