ApiManager
The api manager may be used to perform all the different calls to Scantrust's backend server. It is a "singleton" wrapper around a Retrofit2 instance and gives access to the different API interfaces needed in the various apps.
It requires a unique app tag that will identify the scans coming from your app.
Installation
Include the api lib as a dependency
implementation 'com.scantrust.consumer:android-api:x.y.z'
Add your app tag to your code, e.g.
public final class HttpConstants {
/**
* Application tag
*/
static final String APP_TAG = "app name"; // "Your Scantrust-granted app name"
}
Basic usage
ApiManager.getNameApiInterface(apiBaseUrl).interfaceMethodName(
param1,
param2,
...
).enqueue(new Callback<GsonResultClass>() {
@Override
public void onResponse(Call<GsonResultClass> call, Response<GsonResultClass> response) {
if (response.isSuccessful()) {
// Http code in the range [200..300)
} else {
// Http code out of the range [200..300)
switch (response.code()) {
case 404:
break;
case 400:
case 500:
break;
default:
break;
}
}
}
@Override
public void onFailure(Call<GsonResultClass> call, Throwable t) {
// Network exception occurred talking to the server or
// an unexpected exception occurred creating the request or processing the response.
}
});
Two API service interfaces exist for the consumer and the enterprise app(replace getApiInterfaceName with the appropriate interface). The apiBaseUrl given when obtaining the implementation of the API endpoints defined by the service interface may change, but if the previous base url was different, then the Retrofit instance will be recreated which is a costly operation and therefore should be avoided if possible. If the service interface is obtained without the apiBaseUrl, the default base url will be "https://api.scantrust.com".
The enterprise interface contains a large number of methods that won't be discussed here, the consumer interface however has a small number of methods which basic utility can be found in the next table(for more information see the docs).
Interface Methods | Utility |
---|---|
authenticate | Regular authentication endpoint to be used when a scan is obtained without encountering any problems |
sendInsufficientQualityCode | The endpoint to be used when a scan is obtained but the flow encountered quality issues |
sendUnsupportedRequest | The endpoint to be used when a scan is obtained for an unsupported phone |
syncQr | The endpoint to upload the whole QR Code image for scans that have already successfully been sent to the server with authenticate or sendInsufficientQualityCode |
checkApiVersionCompatibility | Verifies the compatibility of the app's api |
getPreCheck | Fetches the pre-check info of a given code. To be used with the "double ping" feature. |