use of com.amazonaws.services.pinpoint.model.EventsBatch in project aws-sdk-android by aws-amplify.
the class EventRecorder method createRecordEventsRequest.
/**
* @param events array of events
* @param endpointProfile endpoint profile for the device endpoint
*
* @return the request to put event
*/
private PutEventsRequest createRecordEventsRequest(final JSONArray events, final EndpointProfile endpointProfile) {
final PutEventsRequest putRequest = new PutEventsRequest().withApplicationId(endpointProfile.getApplicationId());
final String endpointId = endpointProfile.getEndpointId();
final Map<String, EventsBatch> eventsBatchMap = new HashMap<String, EventsBatch>();
final EventsBatch eventsBatch = new EventsBatch();
final PublicEndpoint endpoint = new PublicEndpoint();
final Map<String, Event> eventsMap = new HashMap<String, Event>();
// build endpoint payload
buildEndpointPayload(endpointProfile, endpoint);
for (int i = 0; i < events.length(); i++) {
JSONObject eventJSON = null;
AnalyticsEvent internalEvent = null;
try {
eventJSON = events.getJSONObject(i);
internalEvent = AnalyticsEvent.translateToEvent(eventJSON);
} catch (final JSONException jsonException) {
// Do not log JSONException due to potentially sensitive information
log.error("Stored event was invalid JSON.", jsonException);
continue;
}
// build event payload
final Event event = new Event();
buildEventPayload(internalEvent, event);
eventsMap.put(internalEvent.getEventId(), event);
}
// build request payload, could also build with only endpoint payload
buildRequestPayload(putRequest, endpointId, eventsBatchMap, eventsBatch, endpoint, eventsMap);
return putRequest;
}
Aggregations