if (id == null || id.isEmpty()) {
throw new IllegalArgumentException("A push subscription ID is required");
}
final FutureData<PulledInteractions> future = new FutureData<>();
URI uri = newParams().forURL(config.newAPIEndpointURI(PULL));
POST request = config.http().POST(uri, new PageReader(new Function2<String, Response>() {
public void apply(String s, Response response) {
if (!response.hasFailed()) {
JavaType type = DataSiftClient.MAPPER.getTypeFactory()
.constructCollectionType(List.class, Interaction.class);
try {
List<Interaction> interactions = DataSiftClient.MAPPER.readValue(s, type);
PulledInteractions pi = new PulledInteractions();
pi.data(interactions);
future.received(pi);
} catch (IOException e) {
fail(s, response, e);
}
} else {
fail(s, response, null);
}
}
private void fail(String s, Response response, Throwable e) {
PulledInteractions pi = new PulledInteractions();
pi.failed(e != null ? e : response.failureCause());
pi.setResponse(new com.datasift.client.Response(s, response));
future.received(pi);
}
})).form("id", id);
if (cursor != null && !cursor.isEmpty()) {
request.form("cursor", cursor);
}
if (size > 0) {
request.form("size", size);
}
applyConfig(request).execute();
return future;
}