Class Index | File Index

Classes


Class Resource


Extends EventEmitter.
Base class for Spire API Resources
Defined in: resource.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Resource(spire, data)
Base class for objects repreenting resources in the spire api.
Field Summary
Field Attributes Field Name and Description
 
Actual data from the spire.io api.
 
Reference to spire object.
Method Summary
Method Attributes Method Name and Description
 
authorization(resource, method)
Returns the Authorization header for this resource, or for another capability if one is passed in.
 
Returns the capabilities for the resource.
 
capability(method)
Returns the capability for the resource and method
<static>  
Resource.defineRequest(obj, name, fn)
Creates a request method on given object.
 
get(cb)

Gets the resource.

 

Gets the resource if we have the get capability.

 
mediaType(name)
Returns the MIME type for this resource or the resource of a given name.
 

Makes the request with the given name.

 
schema(name)
Returns the resource schema for this resource the resource of a given name.
 
update(data, cb)

Updates (puts to) the message.

 
url()
Returns the url for the resource.
Class Detail
Resource(spire, data)
Base class for objects repreenting resources in the spire api. It is meant to be extended by other classes.

Resources have methods for making requests to the spire api. These methods are defined with `Request.defineRequest`. Note that this is a method on the Request object itself, not the prototype. It is used to create methods on the prototype of Resource classes.

The `Resource` class provides default requests for the `get`, `put`, `delete`, and `post` methods. These methods can be overwritten by subclasses.

Once a request method has been defined, it can be run with


  resource.request();

Such request methods have no side effects, and return JSON objects direct from the spire api.

Parameters:
{object} spire
Spire object
{object} data
Resource data from the spire api
Field Detail
data
Actual data from the spire.io api.

spire
Reference to spire object.
Method Detail
{string} authorization(resource, method)
Returns the Authorization header for this resource, or for another capability if one is passed in.
Parameters:
{Resource} resource Optional
Optional resource
{string} method
Method
Returns:
{string} Authorization header

{object} capabilities()
Returns the capabilities for the resource.
Returns:
{object} Capabilities

{string} capability(method)
Returns the capability for the resource and method
Parameters:
method
Returns:
{string} Capability

<static> Resource.defineRequest(obj, name, fn)
Creates a request method on given object. `name` is the name of the request. This is what gets passed to the `request` method when actually calling the request. For instance, a request defined with

  defineRequest(somePrototype, 'get', createGetReq);
is run by calling

  resource.request('get', callback);
`fn` is a function that takes any number of arguments and returns a hash describing the http request we are about to send. Any arguments to this function can be passed to the `request` method. For example, suppose `createGetReq` from above is the following function, which takes an id number as argument as puts it in the query params:

  function createGetReq (id) {
    return {
      method: 'get',
      url: this.url(),
      query: { id: id },
     };
  };
You would call that request like this: resource.request('get', id, callback);
Parameters:
{object} obj
Object to add the request method to.
{string} name
Name of the request method
{function (*args)} fn
Function taking any number of arguments, returning an object describing the HTTP request.

get(cb)

Gets the resource.

Default method that may be overwritten by subclasses.

Parameters:
{function (err|resource)} cb
Callback

getIfCapable(cb)

Gets the resource if we have the get capability. Otherwise just return the resource.

Default method that may be overwritten by subclasses.

Parameters:
{function (err|resource)} cb
Callback

{string} mediaType(name)
Returns the MIME type for this resource or the resource of a given name.
Parameters:
{string} name Optional
Optional name of the resource MIME type to return
Returns:
{string} MIME type

request()

Makes the request with the given name.

Arguments are the request name, followed by any number of arguments that will be passed to the function which creates the request description, and a callback.


{string} schema(name)
Returns the resource schema for this resource the resource of a given name.
Parameters:
{string} name Optional
Optional name of the resource schema to return
Returns:
{string} Schema

update(data, cb)

Updates (puts to) the message.
Defined in: message.js.

Parameters:
{object} data
Message data
{function (err|resource)} cb
Callback

{string} url()
Returns the url for the resource.
Returns:
{string} url

Documentation generated by JsDoc Toolkit 2.4.0 on Wed May 30 2012 16:58:14 GMT-0700 (PDT)