com.strongloop.android.remoting.adapters

## Class RestContract

- java.lang.Object
- - com.strongloop.android.remoting.adapters.RestContract

    public class RestContract
    extends java.lang.Object

A contract specifies how remote method names map to HTTP routes. For example, if a remote method on the server has been remapped like so:

    project.getObject = function (id, callback) {
         callback(null, { ... });
     };
     helper.method(project.getObject, {
         http: { verb: 'GET', path: '/:id'},
         accepts: { name: 'id', type: 'string' }
         returns: { name: 'object', type: 'object' }
     })

The new route is GET /:id, instead of POST /project/getObject, so we need to update our contract on the client:

    contract.addItem(new RestContractItem("/:id", "GET"), "project.getObject");

### Constructor Summary

Constructors
Constructor and Description
`RestContract()`

### Method Summary

Methods
`void` `addItem(RestContractItem item, java.lang.String method)` Adds a single item to this contract.
`void` `addItemsFromContract(RestContract contract)` Adds all items from contract.
`com.strongloop.android.remoting.adapters.RestAdapter.ParameterEncoding` `getParameterEncodingForMethod(java.lang.String method)` Gets the ParameterEncoding for the given method.
`java.lang.String` `getPatternForMethod(java.lang.String method)` Returns the custom pattern representing the given method string, or `null` if no custom pattern exists.
`java.lang.String` `getUrl(java.lang.String pattern, java.util.Map<java.lang.String,? extends java.lang.Object> parameters)` Returns a rendered URL pattern using the parameters provided.
`java.lang.String` `getUrlForMethod(java.lang.String method, java.util.Map<java.lang.String,? extends java.lang.Object> parameters)` Resolves a specific method, replacing pattern fragments with the optional parameters as appropriate.
`java.lang.String` `getUrlForMethodWithoutItem(java.lang.String method)` Generates a fallback URL for a method whose contract has not been customized.
`java.lang.String` `getVerbForMethod(java.lang.String method)` Gets the HTTP verb for the given method string.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### RestContract

    public RestContract()

### Method Detail

#### addItem

    public void addItem(RestContractItem item,
               java.lang.String method)

Adds a single item to this contract. The item can be shared among different contracts, managed by the sum of all contracts that contain it. Similarly, each item can be used for more than one method, like so:

     RestContractItem upsert = new RestContractItem("/widgets/:id", "PUT");
     contract.addItem(upsert, "widgets.create");
     contract.addItem(upsert, "widgets.update");

Parameters:
  `item` - The item to add to this contract.
  `method` - The method the item should represent.

#### addItemsFromContract

    public void addItemsFromContract(RestContract contract)

Adds all items from contract.

Parameters:
  `contract` - The contract to copy from.
See Also:
  `addItem(RestContractItem, String)`

#### getPatternForMethod

    public java.lang.String getPatternForMethod(java.lang.String method)

Returns the custom pattern representing the given method string, or `null` if no custom pattern exists.

Parameters:
  `method` - The method to resolve.
Returns:
  The custom pattern if one exists, `null` otherwise.

#### getVerbForMethod

    public java.lang.String getVerbForMethod(java.lang.String method)

Gets the HTTP verb for the given method string.

Parameters:
  `method` - The method to resolve.
Returns:
  The resolved verb, or "POST" if it isn't defined.

#### getParameterEncodingForMethod

    public com.strongloop.android.remoting.adapters.RestAdapter.ParameterEncoding getParameterEncodingForMethod(java.lang.String method)

Gets the ParameterEncoding for the given method.

Parameters:
  `method` - The method to resolve.
Returns:
  The parameter encoding.

#### getUrlForMethod

    public java.lang.String getUrlForMethod(java.lang.String method,
                                   java.util.Map<java.lang.String,? extends java.lang.Object> parameters)

Resolves a specific method, replacing pattern fragments with the optional parameters as appropriate.

Parameters:
  `method` - The method to resolve.
  `parameters` - Pattern parameters. Can be `null`.
Returns:
  The complete, resolved URL.

#### getUrlForMethodWithoutItem

    public java.lang.String getUrlForMethodWithoutItem(java.lang.String method)

Generates a fallback URL for a method whose contract has not been customized.

Parameters:
  `method` - The method to generate from.
Returns:
  The resolved URL.

#### getUrl

    public java.lang.String getUrl(java.lang.String pattern,
                          java.util.Map<java.lang.String,? extends java.lang.Object> parameters)

Returns a rendered URL pattern using the parameters provided. For example, the pattern `"/widgets/:id"` with the parameters that contain the value `"57"` for key `"id"`, begets `"/widgets/57"`.

Parameters:
  `pattern` - The pattern to render.
  `parameters` - The values to render with.
Returns:
  The rendered URL.