-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRestarter.js
More file actions
54 lines (45 loc) · 1.23 KB
/
Copy pathRestarter.js
File metadata and controls
54 lines (45 loc) · 1.23 KB
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
const fetch = require("node-fetch")
const Heroku = require("./Heroku")
const RequestError = require("./RequestError");
class Restarter {
#token
constructor(token, name) {
this.#token = token
this.name = name
}
async list() {
let response = await fetch(`${Heroku.API_ENDPOINT}/apps/${this.name}/dynos`, {
headers: {
Authorization: `Bearer ${this.#token}`,
Accept: "application/vnd.heroku+json; version=3"
}
})
let json = await response.json()
if(response.status === 200)
return await response.json()
else throw new RequestError(
json.message ?? `Error while trying to listing dynos`,
json,
response.status
)
}
async restart(id) {
let response = await fetch(`${Heroku.API_ENDPOINT}/apps/${this.name}/dynos${id ? `/${id}` : ""}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${this.#token}`,
Accept: "application/vnd.heroku+json; version=3",
"Content-Type": "application/json"
}
})
let json = await response.json()
if(response.status === 202)
return true
else throw new RequestError(
json.message ?? `Error while trying to delete dyno(s)`,
json,
response.status
)
}
}
module.exports = Restarter