return body.isEmpty() ? null : Iterables.getLast(body);
}
public void submit() {
Preconditions.checkState(method != null);
final RestApiRequest req = new RestApiRequest(service, method);
// If the user has declared a body, set it on the request.
String body = display.getBodyText();
if (!body.isEmpty()) {
req.body = body;
req.addHeader("Content-Type", "application/json");
}
Multimap<String, String> paramValues = display.getParameterValues();
for (Map.Entry<String, String> entry : paramValues.entries()) {
if (entry.getValue().isEmpty()) {
continue;
}
req.getParamValues().put(entry.getKey(), entry.getValue());
}
// Do not send the API key if the service is a public-only API.
req.setUseApiKey(
!ExplorerConfig.PUBLIC_ONLY_APIS.contains(service.getName()));
// Set the auth header if we have a token.
AuthToken oauth2Token = authManager.getToken(service);
if (oauth2Token != null) {
req.addHeader("Authorization", "Bearer " + oauth2Token.getAuthToken());
}
display.setExecuting(true);
final long start = System.currentTimeMillis();
req.send(new AsyncCallback<ApiResponse>() {
@Override
public void onSuccess(ApiResponse response) {
display.setExecuting(false);
callback.finished(req, response, start, System.currentTimeMillis());
}