All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.withabound.resources.base.AboundBaseResource Maven / Gradle / Ivy

Go to download

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 base resources, wherein a base resource is one having the relative path
 * `https://baseURL/v3/resource` (i.e. it is not scoped to a user).
 *
 * @param  input — the data type of the request body
 * @param  output — the data type of the payloads returned by SDK methods.
 */
public abstract class AboundBaseResource extends AbstractAboundResource {
  protected AboundBaseResource(
      final AboundConfig aboundConfig, final OkHttpClient httpClient, final Class clazz) {
    super(aboundConfig, httpClient, clazz);
  }

  protected AboundResponse create(final Map requestPayload) throws IOException {
    final String url = getResourcesUrl();

    return super.create(url, requestPayload);
  }

  protected AboundBulkResponse bulkCreate(final Map> requestPayload)
      throws IOException {
    final String url = getResourcesUrl();

    return super.bulkCreate(url, requestPayload);
  }

  protected AboundBulkResponse list() throws IOException {
    return list(EmptyQueryParameters.getInstance());
  }

  protected AboundBulkResponse list(final AboundQueryParameters params) throws IOException {
    final String url = getResourcesUrl();

    return super.list(url, params);
  }

  @Override
  protected AboundResponse retrieve(final String id) throws IOException {
    final String url = getResourceUrl(id);

    return super.retrieve(url);
  }

  /** Updates a single object by issuing a PUT request to /v3/{resourceName}/{resourceId} */
  protected AboundResponse update(final String id, final Map requestPayload)
      throws IOException {
    final String url = getResourceUrl(id);

    return super.update(url, requestPayload);
  }

  @Override
  protected AboundResponse delete(final String id) throws IOException {
    final String url = getResourceUrl(id);

    return super.delete(url);
  }

  /**
   * @return returns the baseUrl + the resource path. e.g.,
   *     "https://sandbox-api.withabound.com/v3/users"
   */
  private String getResourcesUrl() {
    return String.format("%s%s", aboundConfig.getBaseUrl(), getPath());
  }

  /**
   * @return returns the baseUrl + the resource path + the id of the resource. e.g.,
   *     "https://sandbox-api.withabound.com/v3/users/{userId}"
   */
  private String getResourceUrl(final String id) {
    return String.format("%s%s/%s", aboundConfig.getBaseUrl(), getPath(), id);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy