API Docs for:
Show:

Hop.Object Class

Defined in: lib/api.js:392
Module: Hop

Defines an object

This object is created by .defineClass

Methods

del

(
  • method
  • path
)
chainable

Defined in lib/api.js:610

Define a HTTP del call on this method

Parameters:

  • method String

    The name of the method on the associated object

  • path String

    The HTTP path that this call can be found on. Variables can be specified as part of the path utilizing ':'

Example:

Hop.defineClass("UserService",function(api){
    api.del("delete","/user/:userID");
    //..
});

errorHandler

(
  • onError
)

Defined in lib/api.js:469

Provide a function that will be called when an error occured for any call in the class

This function can be used to filter error messages. A typical use case would be to have a small set of allowed error messages, and return a generic error message in all other cases. Or to attach a unique number to each error and provide details in the console log. This function should return a string for the desired error string or null if no custom error is returned. This function is not asynchronous.

Parameters:

  • onError Function

    function to be called when an error has occured

    • method Object

      The method call associated with the error

    • request Object

      The request for the call

    • input Object

      The input for the call

    • error String

      The error string

    • stack String

      A stack trace of where the error occured

Example:

Hop.defineClass("UserService",function(api){
    api.post("update","/user/:userID");

    api.errorHandler(function(method,request,input,error,stack){
        //If we know what the error is simply return it
        if(allowedErrors.contains(error)){
            return null;
        } else {
            //If we don't recognize the error produce a unique ID for it and spit it out in the logs
            var id = Date.now();
            var err = "Error ("+id+")";
            Log.error(method.getName(),request,input,id,error,stack);
            return err;
        }
    });
});

extend

()

Defined in lib/api.js:543

Have this object extend from an interface

Example:

Hop.defineInterface("Notification",function(api){
    api.post("send","#classname/send").usage("Sends a message").demand("msg").demand("subject").demand("to");
}
Hop.defineClass("Email",function(api){
    //This will essentially evaluate the interface defined above against thsi class adding the send function
    api.extend("Notification");
});

findObject

() String static

Defined in lib/api.js:671

Find an object by name

Returns:

String: The name of the method

Example:

Hop.defineClass("UserService",function(api){
    api.get("load","/user/:userID")

});
var method = Hop.Method.findMethod("UserService.load");
Hop.log(method.getMethod()); //returns UserService.load

get

(
  • method
  • path
)
chainable

Defined in lib/api.js:568

Define a HTTP get call on this method

Parameters:

  • method String

    The name of the method on the associated object

  • path String

    The HTTP path that this call can be found on. Variables can be specified as part of the path utilizing ':'

Example:

Hop.defineClass("UserService",function(api){
    api.get("load","/user/:userID");
    //..
});

Hop.Object.wrap

(
  • objectName
)
Object

Defined in lib/api.js:406

Wrap an object so that it may be called localy with all of the functionality that Hop normally provides

This function will create a wrapped version of a defined object with all of the functionality that Hop would normally provide.

Parameters:

  • objectName String

    Then name of the object to wrap

Returns:

Object:
An object with implementations of all the functions defined by the object. 
The returned functions will have the calling signature (input,onComplete,request)

Example:

Hop.defineClass("UserService",function(api){
    api.get("load","/user/:userID").demand("userID").cacheId("/user/:userID");
});

var userService = Hop.Object.wrap("UserService");

//This call will now be subject to all of the normal constraints and functionality provided by Hop
userService.load({ userID:5 },function(err,result){

},request);

post

(
  • method
  • path
)
chainable

Defined in lib/api.js:589

Define a HTTP post call on this method

Parameters:

  • method String

    The name of the method on the associated object

  • path String

    The HTTP path that this call can be found on. Variables can be specified as part of the path utilizing ':'

Example:

Hop.defineClass("UserService",function(api){
    api.post("update","/user/:userID");
    //..
});

put

(
  • method
  • path
)
chainable

Defined in lib/api.js:632

Define a HTTP put call on this method

Parameters:

  • method String

    The name of the method on the associated object

  • path String

    The HTTP path that this call can be found on. Variables can be specified as part of the path utilizing ':'

Example:

Hop.defineClass("UserService",function(api){
    api.put("create","/user/");
    //..
});

usage

() chainable

Defined in lib/api.js:653

Define the usage for this class

Example:

Hop.defineClass("UserService",function(api){
    api.usage("Manages Users");
    //..
});