com.withabound.resources.base.AboundUserScopedResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of withabound-java Show documentation
Show all versions of withabound-java Show documentation
The Abound Java SDK provides convenient access to the Abound API from applications written in Java.
The newest version!
package com.withabound.resources.base;
import com.withabound.AboundConfig;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import okhttp3.OkHttpClient;
/**
* Abstract class for all user-scoped resources, wherein a user-scoped resource is one having the
* relative path `https://baseURL/v3/users/{userId}/{resourceName}`
*
* @param input — the data type of the request body
* @param output — the data type of the payloads returned by SDK methods.
*/
public abstract class AboundUserScopedResource extends AbstractAboundResource {
protected AboundUserScopedResource(
final AboundConfig aboundConfig, final OkHttpClient httpClient, final Class clazz) {
super(aboundConfig, httpClient, clazz);
}
protected AboundBulkResponse listForUser(final String userId) throws IOException {
return listForUser(userId, EmptyQueryParameters.getInstance());
}
protected AboundBulkResponse listForUser(
final String userId, final AboundQueryParameters params) throws IOException {
final String url = getUserScopedResourcesUrl(userId);
return super.list(url, params);
}
protected AboundResponse retrieveForUser(final String userId, final String id)
throws IOException {
final String url = getUserScopedResourceUrl(userId, id);
return super.retrieve(url);
}
protected AboundResponse createForUser(
final String userId, final Map requestPayload) throws IOException {
final String url = getUserScopedResourcesUrl(userId);
return super.create(url, requestPayload);
}
protected AboundBulkResponse bulkCreateForUser(
final String userId, final Map> requestPayload) throws IOException {
final String url = getUserScopedResourcesUrl(userId);
return super.bulkCreate(url, requestPayload);
}
protected AboundResponse updateForUser(
final String userId, final String id, final Map requestPayload)
throws IOException {
final String url = getUserScopedResourceUrl(userId, id);
return super.update(url, requestPayload);
}
protected AboundResponse deleteForUser(final String userId, final String id)
throws IOException {
final String url = getUserScopedResourceUrl(userId, id);
return super.delete(url);
}
/** @return e.g., "https://baseURL/v3/users/{userId}/{resourceName}" */
private String getUserScopedResourcesUrl(final String userId) {
return String.format("%s%s%s%s", aboundConfig.getBaseUrl(), "/users/", userId, getPath());
}
/** @return e.g., "https://baseURL/v3/users/{userId}/{resourceName}/{resourceId}" */
private String getUserScopedResourceUrl(final String userId, final String id) {
return String.format(
"%s%s%s%s/%s", aboundConfig.getBaseUrl(), "/users/", userId, getPath(), id);
}
}