public class ConnectAPI
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
API_BASE_URL |
protected java.lang.String |
apiKey |
protected com.squareup.okhttp.OkHttpClient |
client |
protected java.lang.String |
eventsUrl |
protected static com.google.gson.Gson |
gson |
protected static com.squareup.okhttp.MediaType |
JSON |
protected java.lang.String |
projectId |
| Constructor and Description |
|---|
ConnectAPI(java.lang.String projectId,
java.lang.String apiKey)
Creates a new Connect API client.
|
ConnectAPI(java.lang.String projectId,
java.lang.String apiKey,
java.lang.String baseUrl)
Creates a new Connect API client.
|
| Modifier and Type | Method and Description |
|---|---|
protected static java.util.Map<java.lang.String,java.lang.Iterable<EventPushResponse>> |
buildResponseForBatch(java.util.Map<java.lang.String,java.lang.Iterable<Event>> batch,
com.squareup.okhttp.Response response) |
protected com.squareup.okhttp.Request |
generatePostRequest(java.lang.String url,
java.lang.String json) |
protected static java.util.Map<java.lang.String,java.lang.Object> |
getDeserializedResponseBody(com.squareup.okhttp.Response response) |
protected static ConnectException |
getExceptionForBatchResponse(com.squareup.okhttp.Response response) |
protected static ConnectException |
getExceptionForResponse(com.squareup.okhttp.Response response) |
void |
pushEvent(java.lang.String collection,
Event event)
Pushes a single event to the Connect API synchronously.
|
void |
pushEvent(java.lang.String collection,
Event event,
ConnectCallback callback)
Pushes a single event to the Connect API asynchronously.
|
java.util.Map<java.lang.String,java.lang.Iterable<EventPushResponse>> |
pushEventBatch(java.util.Map<java.lang.String,java.lang.Iterable<Event>> batch)
Pushes a batch of events to the Connect API synchronously.
|
void |
pushEventBatch(java.util.Map<java.lang.String,java.lang.Iterable<Event>> batch,
ConnectBatchCallback callback)
Pushes a batch of events to the Connect API asynchronously.
|
protected static final java.lang.String API_BASE_URL
protected static final com.google.gson.Gson gson
protected static final com.squareup.okhttp.MediaType JSON
protected final java.lang.String projectId
protected final java.lang.String apiKey
protected final java.lang.String eventsUrl
protected final com.squareup.okhttp.OkHttpClient client
public ConnectAPI(java.lang.String projectId,
java.lang.String apiKey)
projectId - ID of the project to which to push events.apiKey - API key used to access the project (this must be a push or push/query key).public ConnectAPI(java.lang.String projectId,
java.lang.String apiKey,
java.lang.String baseUrl)
projectId - ID of the project to which to push events.apiKey - API key used to access the project (this must be a push or push/query key).baseUrl - Base URL of the Connect API.public void pushEvent(java.lang.String collection,
Event event)
throws ConnectException
collection - The name of the collection to push to.event - The Event to send.ConnectException - When an error occurs.
Will be InvalidEventException,
or a generic ConnectException with an inner exception.public void pushEvent(java.lang.String collection,
Event event,
ConnectCallback callback)
collection - The name of the collection to push to.event - The Event to send.callback - A ConnectCallback that will be invoked with the results of the requestpublic java.util.Map<java.lang.String,java.lang.Iterable<EventPushResponse>> pushEventBatch(java.util.Map<java.lang.String,java.lang.Iterable<Event>> batch) throws ConnectException
batch - The event batch as a Map keyed by collection name containing a collection of @{link Event}s.ConnectException - When an error occurs.
Will be InvalidEventException,
or a generic ConnectException with an inner exception.public void pushEventBatch(java.util.Map<java.lang.String,java.lang.Iterable<Event>> batch, ConnectBatchCallback callback)
batch - The event batch as a Map keyed by collection name containing a collection of @{link Event}s.callback - A ConnectBatchCallback that will be invoked with the results of the requestprotected com.squareup.okhttp.Request generatePostRequest(java.lang.String url,
java.lang.String json)
protected static ConnectException getExceptionForResponse(com.squareup.okhttp.Response response)
protected static ConnectException getExceptionForBatchResponse(com.squareup.okhttp.Response response)
protected static java.util.Map<java.lang.String,java.lang.Object> getDeserializedResponseBody(com.squareup.okhttp.Response response)
throws java.io.IOException
java.io.IOExceptionprotected static java.util.Map<java.lang.String,java.lang.Iterable<EventPushResponse>> buildResponseForBatch(java.util.Map<java.lang.String,java.lang.Iterable<Event>> batch, com.squareup.okhttp.Response response) throws java.io.IOException
java.io.IOException