Skip to content

Commit 02bc29b

Browse files
committed
Refactor(main): Cleaner methods code with JSDoc
1 parent b304428 commit 02bc29b

1 file changed

Lines changed: 86 additions & 25 deletions

File tree

requestbin.js

Lines changed: 86 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,36 +84,97 @@ function talk (method, path, props, callback) {
8484
}
8585

8686

87-
module.exports = {
88-
config: function (props) {
89-
var name;
90-
91-
for (name in props) {
92-
config [name] = props [name];
93-
}
94-
},
87+
/**
88+
* Set configuration
89+
*
90+
* @param props {object} - Config parameters
91+
* @return {void}
92+
*/
9593

96-
create: function (isPrivate, callback) {
97-
var props = {};
94+
function methodConfig (props) (
95+
var name;
9896

99-
if (typeof isPrivate === 'function') {
100-
callback = isPrivate;
101-
} else if (isPrivate === true) {
102-
props.private = 'true';
103-
}
97+
for (name in props) {
98+
config [name] = props [name];
99+
}
100+
}
104101

105-
talk ('POST', 'bins', props, callback);
106-
},
107102

108-
get: function (bin, callback) {
109-
talk ('GET', 'bins/' + bin, callback);
110-
},
103+
/**
104+
* Create request instance
105+
*
106+
* @callback callback
107+
* @param [isPrivate = false] {boolean} - Make instance private
108+
* @param callback {function} - `function (err, data) {}`
109+
* @return {void}
110+
*/
111111

112-
requests: function (bin, callback) {
113-
talk ('GET', 'bins/' + bin + '/requests', callback);
114-
},
112+
function methodCreate (isPrivate, callback) (
113+
var props = {};
115114

116-
request: function (bin, request, callback) {
117-
talk ('GET', 'bins/' + bin + '/requests/' + request, callback);
115+
if (typeof isPrivate === 'function') {
116+
callback = isPrivate;
117+
} else if (isPrivate === true) {
118+
props.private = 'true';
118119
}
120+
121+
talk ('POST', 'bins', props, callback);
122+
}
123+
124+
125+
/**
126+
* Get a request instance
127+
*
128+
* @callback callback
129+
* @param bin {string} - Bin instance ID
130+
* @param callback {function} - `function (err, data) {}`
131+
* @return {void}
132+
*/
133+
134+
function methodGet (bin, callback) {
135+
talk ('GET', 'bins/' + bin, callback);
136+
}
137+
138+
139+
/**
140+
* Get received requests
141+
*
142+
* @callback callback
143+
* @param bin {string} - Bin instance ID
144+
* @param callback {function} - `function (err, data) {}`
145+
* @return {void}
146+
*/
147+
148+
function methodRequests (bin, callback) {
149+
talk ('GET', 'bins/' + bin + '/requests', callback);
150+
}
151+
152+
153+
/**
154+
* Get one received request
155+
*
156+
* @callback callback
157+
* @param bin {string} - Bin instance ID
158+
* @param request {string} - Request ID
159+
* @param callback {function} - `function (err, data) {}`
160+
* @return {void}
161+
*/
162+
163+
function methodRequest (bin, request, callback) {
164+
talk ('GET', 'bins/' + bin + '/requests/' + request, callback);
165+
}
166+
167+
168+
/**
169+
* Interface methods
170+
*
171+
* @return {object} - Methods
172+
*/
173+
174+
module.exports = {
175+
config: methodConfig,
176+
create: methodCreate,
177+
get: methodGet,
178+
requests: methodRequests,
179+
request: methodRequest
119180
};

0 commit comments

Comments
 (0)