Hop.Object Class
Defines an object
This object is created by .defineClass
Item Index
Methods
Methods
del
-
method -
path
Define a HTTP del call on this method
Parameters:
-
methodStringThe name of the method on the associated object
-
pathStringThe 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
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:
-
onErrorFunctionfunction to be called when an error has occured
-
methodObjectThe method call associated with the error
-
requestObjectThe request for the call
-
inputObjectThe input for the call
-
errorStringThe error string
-
stackStringA 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
()
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
Find an object by name
Returns:
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
Define a HTTP get call on this method
Parameters:
-
methodStringThe name of the method on the associated object
-
pathStringThe 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
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:
-
objectNameStringThen name of the object to wrap
Returns:
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
Define a HTTP post call on this method
Parameters:
-
methodStringThe name of the method on the associated object
-
pathStringThe 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
Define a HTTP put call on this method
Parameters:
-
methodStringThe name of the method on the associated object
-
pathStringThe 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
Define the usage for this class
Example:
Hop.defineClass("UserService",function(api){
api.usage("Manages Users");
//..
});
