Hop Class
Item Index
Methods
- addToJSONHandler static
- addToJSONHandler static
- apiHook
- call static
- checksum static
- defineClass static
- defineInterface static
- defineTestCase static
- renderTemplate
Methods
addToJSONHandler
-
onJSON -
The
Add a call back which will be called when a version of the API must be built from JSON
Parameters:
-
onJSONFunctionCallback to be called when a json version of Hop is requested
-
TheObjectstub object which is being populated for conversion to JSON
addToJSONHandler
-
onJSON -
The
Add a call back which will be called when a JSON version of the API is requested
Parameters:
-
onJSONFunctionCallback to be called when a json version of Hop is requested
-
TheObjectstub object which is being populated for conversion to JSON
apiHook
-
basePath -
app
Inserts the Hop calls into express
Parameters:
-
basePathStringthe path which the Hop will hang off of -
appObjectthe express app
call
-
name -
input -
callback -
[request]
Calls the specified method
This function is provided so that all functionality around a specific call may be utilized.
Parameters:
-
nameStringName of the function to call
-
inputObjectInput for the call
-
callbackFunctionfor completion
-
errThe error returned from the call
-
resultThe result returned from the call
-
-
[request]Object optionalExpressJS/HTTP request object
Example:
var input = { username: "cfox", email:"cfox@gmail.com"}
Hop.call("UserService.create",input,function(err,res){
Hop.log(err,res);
});
checksum
()
static
Calculate a checksum for the Hop
This is used to detect changes in the version of the Hop
defineClass
-
name -
[instance] -
onDefine
Define a new class
- Use #classname to have the class name substituted into the URL
Parameters:
-
nameStringthe name of the class
-
[instance]Object optionalan instance of the object
-
onDefineFunctionthe lambda used to define the interface
Example:
Hop.defineClass("Email",new Email(),function(api){
//define the class
});
defineInterface
-
name -
onDefine
Define a new interface
- Use #classname to have the class name substituted into the URL
Parameters:
-
nameStringthe name of the interface
-
onDefineFunctionthe lambda used to define the interface
Example:
Hop.defineInterface("Notification",function(api){
api.post("send","#classname/send").usage("Sends a message").demand("msg").demand("subject").demand("to");
}
defineTestCase
-
name -
lambda
Define a test case for a specific method
Parameters:
-
nameStringthe name of the method to test, this must be the same as a defined API method, and may also contain a commnet appened after a :
-
lambdaFunctionThe lambda defining the test
Example:
Hop.defineTestCase("User.authenticate: Test Authentication",function(test){
var validUser = { email:"test@test.com", username:"TestUser" };
test.do("User.create").with(validUser).noError();
test.do("User.authenticate").with(validUser).noError();
test.do("User.authenticate").with({password:"BOB"},validUser).containsError("Permission denied");
});
renderTemplate
-
filename -
input
Render a template using the cumbustion template engine
Parameters:
-
filenameStringThe filename of the template relative to the "./static" path
-
inputObjectThe inputs to the template
