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

com.strongloop.android.remoting.adapters.RestContractItem Maven / Gradle / Ivy

The newest version!
package com.strongloop.android.remoting.adapters;

/**
 * A single item within a larger SLRESTContract, encapsulation a single route's
 * verb and pattern, e.g. GET /widgets/:id.
 */
public class RestContractItem {

    private final String pattern;
    private final String verb;
    private final RestAdapter.ParameterEncoding parameterEncoding;

    /**
     * Creates a new item encapsulating the given pattern and the default verb,
     * "POST".
     * @param pattern The pattern corresponding to this route, e.g.
     * "/widgets/:id".
     */
    public RestContractItem(String pattern) {
        this(pattern, "POST");
    }

    /**
     * Creates a new item encapsulating the given pattern and verb.
     * @param pattern The pattern corresponding to this route, e.g.
     * "/widgets/:id".
     * @param verb The verb corresponding to this route, e.g.
     * "GET".
     */
    public RestContractItem(String pattern, String verb) {
        this(pattern, verb, RestAdapter.ParameterEncoding.JSON);
    }

    /**
     * Creates a new item encapsulating a route that expects multi-part request
     * (e.g. file upload).
     * @param pattern The pattern corresponding to this route, e.g.
     * "/files/:id".
     * @param verb The verb corresponding to this route, e.g.
     * "POST".
     * @return The RestContractItem created.
     */
    public static RestContractItem createMultipart(String pattern, String verb) {
        return new RestContractItem(pattern, verb,
                RestAdapter.ParameterEncoding.FORM_MULTIPART);
    }

    private RestContractItem(String pattern,
                             String verb,
                             RestAdapter.ParameterEncoding parameterEncoding) {
        this.pattern = pattern;
        this.verb = verb;
        this.parameterEncoding = parameterEncoding;
    }

    /**
     * Gets the pattern corresponding to this route, e.g.
     * "/widgets/:id".
     * @return the pattern.
     */
    public String getPattern() {
        return pattern;
    }

    /**
     * Gets the verb corresponding to this route, e.g. "GET".
     * @return the verb.
     */
    public String getVerb() {
        return verb;
    }

    /**
     * Gets a boolean that indicates if the item is a multipart form mime type.
     * @return true if the item is multipart
     */
    public RestAdapter.ParameterEncoding getParameterEncoding() {
        return parameterEncoding;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy