1 | module.exports = class Batch {
|
2 | constructor(sriClient) {
|
3 | this.array = [];
|
4 | this.sriClient = sriClient;
|
5 | }
|
6 |
|
7 | getPayload() {
|
8 | return this.array;
|
9 | }
|
10 |
|
11 | get(href) {
|
12 | this.array.push({
|
13 | href: href,
|
14 | verb: 'GET'
|
15 | });
|
16 | }
|
17 |
|
18 | put(href, payload) {
|
19 |
|
20 | if (typeof href === 'object' && href.$$meta && href.$$meta.permalink) {
|
21 | this.array.push({
|
22 | href: href.$$meta.permalink,
|
23 | verb: 'PUT',
|
24 | body: href
|
25 | });
|
26 | } else {
|
27 | this.array.push({
|
28 | href: href,
|
29 | verb: 'PUT',
|
30 | body: payload
|
31 | });
|
32 | }
|
33 | }
|
34 |
|
35 | post(href, payload) {
|
36 | this.array.push({
|
37 | href: href,
|
38 | verb: 'POST',
|
39 | body: payload
|
40 | });
|
41 | }
|
42 |
|
43 | delete(href) {
|
44 |
|
45 | if (typeof href === 'object' && href.$$meta && href.$$meta.permalink) {
|
46 | this.array.push({
|
47 | href: href.$$meta.permalink,
|
48 | verb: 'DELETE'
|
49 | });
|
50 | } else {
|
51 | this.array.push({
|
52 | href: href,
|
53 | verb: 'DELETE'
|
54 | });
|
55 | }
|
56 |
|
57 | }
|
58 |
|
59 | send(href, sriClient) {
|
60 | return sriClient ? sriClient.put(href, this.array) : this.sriClient.put(href, this.array);
|
61 | }
|
62 | }; |
\ | No newline at end of file |