com.ning.api.client.access.Items Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ning-api-java Show documentation
Show all versions of ning-api-java Show documentation
Java client library for accessing Ning external API
package com.ning.api.client.access;
import com.ning.api.client.NingClientConfig;
import com.ning.api.client.access.impl.DefaultFinder;
import com.ning.api.client.action.Finder;
import com.ning.api.client.item.ContentItem;
import com.ning.api.client.item.Fields;
import com.ning.api.client.item.Typed;
/**
* Base class to contain shared functionality and constants for
* conceptual groups of objects (which are essentially accessors,
* or request builders for modifying individual items or groups
* of items of specified type).
*
* @author tatu
*
* @param Type of Content item
* @param Type of enumeration that defines accessible fields
* of content item (of type C)
*/
public abstract class Items<
C extends ContentItem, // item type
F extends Enum & Typed // set of fields used for filtering
>
{
protected final NingConnection connection;
/**
* Current configuration used for operations for accessing
* items.
*/
protected NingClientConfig config;
/**
* Part of end point path that differs between resource type; typically
* just name of the resource type (like "User")
*/
protected final String endpointBase;
protected final Class itemType;
protected final Class fieldType;
protected Items(NingConnection connection, NingClientConfig config,
String endpointBase, Class itemType, Class fieldType)
{
this.connection = connection;
this.endpointBase = endpointBase;
this.itemType = itemType;
this.fieldType = fieldType;
this.config = config;
}
/*
///////////////////////////////////////////////////////////////////////
// Public API: configuration
///////////////////////////////////////////////////////////////////////
*/
public NingClientConfig getConfig() { return config; }
/**
* Method for overriding configuration of this object with
* specified overrides. Resulting configuration will be used as the
* default configuration for all accessors created by this object.
*/
public void setConfig(NingClientConfig configOverrides) {
// note: we will merge settings, to ensure there are defaults of some kind
this.config = config.overrideWith(configOverrides);
}
/*
///////////////////////////////////////////////////////////////////////
// Public API: constructing request builders
///////////////////////////////////////////////////////////////////////
*/
// non-final to allow custom Finder types
public Finder finder(F firstField, F... otherFields) {
return finder(new Fields(fieldType, firstField, otherFields));
}
// non-final to allow custom Finder types
public Finder finder(Fields fields) {
return new DefaultFinder(connection, config, endpointForRecent(),
itemType, fields);
}
/*
///////////////////////////////////////////////////////////////////////
// Public API, constructing standard paths
///////////////////////////////////////////////////////////////////////
*/
protected String endpointForSingle() {
return endpointBase;
}
protected String endpointForDELETE() {
return endpointBase;
}
protected String endpointForPUT() {
return endpointBase;
}
protected String endpointForPOST() {
return endpointBase;
}
protected String endpointForAlpha() {
return endpointBase+"/alpha";
}
protected String endpointForRecent() {
return endpointBase+"/recent";
}
protected String endpointForCount() {
return endpointBase+"/count";
}
/*
///////////////////////////////////////////////////////////////////////
// Public API, filter construction
///////////////////////////////////////////////////////////////////////
*/
/**
* Helper method for constructing empty field set
*/
public Fields fields()
{
return new Fields(fieldType);
}
/**
* Helper method for constructing field sets to use for filtering
*/
public Fields fields(F first, F... other)
{
return new Fields(fieldType, first, other);
}
}