UNPKG

914 BJavaScriptView Raw
1const Request = require('./Request');
2
3class RequestBuilder {
4 constructor(defaultOptions) {
5 this.defaultOptions = defaultOptions;
6 this.options = {};
7 }
8
9 setOptions(name, options) {
10 this.options[name] = options;
11 return this;
12 }
13
14 request(names = []) {
15 if (!Array.isArray(names)) {
16 names = [names];
17 }
18 const request = new Request(this.defaultOptions);
19 for (const name of names) {
20 request.addOptions(this.options[name]);
21 }
22 return request;
23 }
24
25 send(path, options) {
26 return this.request().send(path, options);
27 }
28
29 delete(path, options) {
30 return this.request().delete(path, options);
31 }
32
33 get(path, options) {
34 return this.request().get(path, options);
35 }
36
37 post(path, options) {
38 return this.request().post(path, options);
39 }
40
41 put(path, options) {
42 return this.request().put(path, options);
43 }
44}
45
46module.exports = RequestBuilder;