Blame view
node_modules/strong-remoting/example/documentation/remotes/simple-class.js
1.69 KB
f7563de62
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
// Copyright IBM Corp. 2013,2016. All Rights Reserved. // Node module: strong-remoting // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 // This example shows using the helper for a type in a "post-definition" style. var helper = require('../../../').extend(module.exports); /** * A simple class that contains a name. */ function SimpleClass(name) { this.name = name; } helper.type(SimpleClass, { description: 'A simple class example', accepts: [{ name: 'name', type: 'string', required: true }] }); /** * Returns the SimpleClass instance's name. */ SimpleClass.prototype.getName = function(callback) { callback(null, this.name); }; helper.method(SimpleClass.prototype.getName, { path: 'SimpleClass.prototype.getName', description: 'Returns the SimpleClass instance\'s name.', returns: { name: 'name', type: 'string' } }); /** * Takes in a name, returning a greeting for that name. */ SimpleClass.prototype.greet = function(other, callback) { callback(null, 'Hi, ' + other + '!'); }; helper.method(SimpleClass.prototype.greet, { path: 'SimpleClass.prototype.greet', description: 'Takes in a name, returning a greeting for that name.', accepts: [{ name: 'other', type: 'string', required: true }], returns: { name: 'greeting', type: 'string' } }); /** * Returns the SimpleClass prototype's favorite person's name. */ SimpleClass.getFavoritePerson = function(callback) { callback(null, 'You'); }; helper.method(SimpleClass.getFavoritePerson, { path: 'SimpleClass.getFavoritePerson', description: 'Returns the SimpleClass prototype\'s favorite person\'s name.', returns: { name: 'name', type: 'string' } }); |