Understanding Acts - rezolved/rezolve_sdk_sampleapp_android GitHub Wiki
SspActManager
SspActManager
is responsible for getting Acts by Act ID or Engagement ID. It is also used to submit answers to the Acts and getting historical submissions. To implement it you need ssp-android
module dependency. If you're not using new RxpSdk
you will also need legacy methods provided in old-ssp-android
module.
dependencies {
implementation "com.rezolve.sdk:ssp-android:$rezolveSdkVersion"
implementation "com.rezolve.sdk:old-ssp-android:$rezolveSdkVersion"
}
old-ssp-android
module provides extension of SspActManager
class so if make sure you import it from correct package (com.rezolve.sdk.ssp.managers.SspActManager
vs com.rezolve.sdk.old_ssp.managers.SspActManager
). This extended manager provides getSspGeofenceEngagements
method that allows to fetch nearby engagements.
To initialize SspActManager
:
AuthParams authParams = new AuthParams(
AUTH0_CLIENT_ID,
AUTH0_CLIENT_SECRET,
AUTH0_API_KEY,
AUTH0_AUDIENCE,
AUTH0_ENDPOINT,
SSP_ENGAGEMENT_ENDPOINT,
SSP_ACT_ENDPOINT
);
HttpClientConfig httpConfig = new HttpClientConfig.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.build();
HttpClientFactory httpClientFactory = new HttpClientFactory.Builder()
.setHttpClientConfig(httpConfig)
.setAuthParams(authParams)
.build();
SspHttpClient sspHttpClient = httpClientFactory.createHttpClient(SSP_ENDPOINT);
SspActManager sspActManager = new SspActManager(sspHttpClient, rezolveSDK);
Getting Act
Getting acts is handled by sspActManager
in the form of SspAct
instances.
Acts cannot be fetched in bulk. In order to get an act, proceed by calling sspActManager
's getAct
method. Required parameters are the act's id, parameter describing the act's image width and SspGetActInterface which is a callback to getAct method.
sspActManager.getAct(actId, 400, new SspGetActInterface() {
@Override
public void onGetActSuccess(SspAct sspAct) {
Log.d(TAG, "SspAct: " + sspAct.entityToJson());
}
@Override
public void onError(@NonNull RezolveError rezolveError) {
// Error handling
}
});
Presenting Act
Sample implementation can be found here
Before displaying sspAct, check the value of the field sspAct.getPageBuildingBlocks()
. If it is not null and is not empty, it means that engagement owner has designed custom layout to present it. Here is how to handle it.
- Create helper data class that holds both block and answer (if applicable):
class BlockWrapper {
private final PageBuildingBlock pageBuildingBlock;
private String answerToDisplay;
public BlockWrapper(PageBuildingBlock pageBuildingBlock, String answerToDisplay){
this.pageBuildingBlock = pageBuildingBlock;
this.answerToDisplay = answerToDisplay;
}
public PageBuildingBlock getPageBuildingBlock() {
return pageBuildingBlock;
}
public String getAnswerToDisplay() {
return answerToDisplay;
}
public void setAnswerToDisplay(String answerToDisplay) {
this.answerToDisplay = answerToDisplay;
}
}
- Create an adapter class to show the custom layout.
- List blocks In your fragment or activity class submit list of blocks to the adapter.
- Create layouts to present different types of blocks:
PageBuildingBlock.getType()
all available types:
Type.HEADER
Type.PARAGRAPH
Type.DIVIDER
Type.IMAGE
Type.VIDEO
Type.DATE_FIELD
Type.SELECT
Type.TEXT_FIELD
Type.COUPON
Type.UNKNOWN
Act submission
In order to post an act proceed by calling sspActManager
's submitAnswer
method, providing the act's id and act data in SspActSubmission
format as parameters. Please note that any answers to relevant act questions are a part of the act data in SspActAnswer
format. To create SspActSubmission
use SspActSubmission.Builder
.
SspActSubmission sspActSubmission = new SspActSubmission.Builder()
.setUserId(String)
.setUserName(String)
.setEntityId(String)
.setServiceId(String)
.setAnswers(List<SspActAnswer>)
.setPersonTitle(String)
.setFirstName(String)
.setLastName(String)
.setEmail(String)
.setPhone(String)
.setLocation(RezolveLocation)
.build();
sspActManager.submitAnswer(actId, sspActSubmission, new SspSubmitActDataInterface() {
@Override
public void onSubmitActDataSuccess(SspActSubmissionResponse sspActSubmissionResponse) {
// Handle success
}
@Override
public void onError(@NonNull RezolveError rezolveError) {
// Error handling
}
});
Act submission history
In order to fetch historical act submissions by the user proceed by calling sspActManager
's getActSubmissions
method, while providing the entity id as a parameter. The request will return a ActSubmissionHistoryObject
instance, while the submitted acts are available by calling getActs
method on this object.
Please note that answers in the act data are in SspActAnswer
format. Meaning the text of the question is unavailable until the developer fetches the act. To get the question texts, the developer has to call the above-mentioned getAct
with an adequate act id.
sspActManager.getActSubmissions(entityId, new SspGetActSubmissionInterface() {
@Override
public void onGetSspActSubmissionsSuccess(ActSubmissionHistoryObject actSubmissionHistoryObject) {
actSubmissionHistoryObject.getActs();
}
@Override
public void onError(@NonNull RezolveError rezolveError) {
// Error handling
}
});