1 |
|
2 | import fetch from "@36node/fetch";
|
3 |
|
4 | export default class SDK {
|
5 |
|
6 | base;
|
7 |
|
8 | token;
|
9 |
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 | get auth() {
|
16 | return "";
|
17 | }
|
18 |
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | constructor(opt = { base: "", token: "" }) {
|
27 | this.base = opt.base;
|
28 | this.token = opt.token;
|
29 | }
|
30 |
|
31 | |
32 |
|
33 |
|
34 | pet = {
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | listPets: req => {
|
42 | const { query } = req || {};
|
43 |
|
44 | return fetch(`${this.base}/pets`, {
|
45 | method: "GET",
|
46 | query,
|
47 | headers: { Authorization: this.auth },
|
48 | });
|
49 | },
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | createPet: req => {
|
57 | const { body } = req || {};
|
58 |
|
59 | if (!body) throw new Error("requetBody is required for createPet");
|
60 |
|
61 | return fetch(`${this.base}/pets`, {
|
62 | method: "POST",
|
63 | body,
|
64 | headers: { Authorization: this.auth },
|
65 | });
|
66 | },
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | showPetById: req => {
|
74 | const { petId } = req || {};
|
75 |
|
76 | if (!petId) throw new Error("petId is required for showPetById");
|
77 |
|
78 | return fetch(`${this.base}/pets/${petId}`, {
|
79 | method: "GET",
|
80 | headers: { Authorization: this.auth },
|
81 | });
|
82 | },
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | updatePet: req => {
|
90 | const { petId, body } = req || {};
|
91 |
|
92 | if (!petId) throw new Error("petId is required for updatePet");
|
93 | if (!body) throw new Error("requetBody is required for updatePet");
|
94 |
|
95 | return fetch(`${this.base}/pets/${petId}`, {
|
96 | method: "PUT",
|
97 | body,
|
98 | headers: { Authorization: this.auth },
|
99 | });
|
100 | },
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 | deletePet: req => {
|
107 | const { petId } = req || {};
|
108 |
|
109 | if (!petId) throw new Error("petId is required for deletePet");
|
110 |
|
111 | return fetch(`${this.base}/pets/${petId}`, {
|
112 | method: "DELETE",
|
113 | headers: { Authorization: this.auth },
|
114 | });
|
115 | },
|
116 | };
|
117 | }
|