* @return Response object.
*/
protected Response getApiResponse(Verbs verb, String methodName, Map<String, String> params) throws IOException {
Response response;
String apiResourceUrl = config.getApiURL() + methodName;
OAuthRequest request = new OAuthRequest(verb, apiResourceUrl);
request.setConnectTimeout(config.getConnectionTimeoutMills(), TimeUnit.MILLISECONDS);
request.setReadTimeout(config.getReadTimeoutMills(), TimeUnit.MILLISECONDS);
if (enforceSignatrue != null) {
request.addHeader(EnforceSignedHeaderUtils.ENFORCE_SIGNED_HEADER, enforceSignatrue);
}
// Additional parameters in url
if (params != null) {
for (Map.Entry<String, String> entry : params.entrySet()) {
if (verb == Verbs.GET) {
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
else {
request.addBodyParameter(entry.getKey(), entry.getValue());
}
}
}
// Add the AccessToken to the Request Url
if ((verb == Verbs.GET) || (verb == Verbs.DELETE)) {
if (accessToken == null) {
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, clientId);
} else {
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
}
}
else {
if (accessToken == null) {
request.addBodyParameter(OAuthConstants.CLIENT_ID, clientId);
} else {
request.addBodyParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
}
}
response = request.send();
return response;
}