/
API.ts
72 lines (63 loc) · 1.95 KB
/
API.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import axios from "axios";
import { AccessStatus, Build, Project } from "../types";
export default class API {
owner?: string;
title?: string;
constructor(owner, title) {
this.owner = owner;
this.title = title;
}
async getAccessStatus(): Promise<AccessStatus> {
if (this.owner && this.title) {
return (await axios.get(`/users/status/${this.owner}/${this.title}/`)).data;
} else {
return (await axios.get(`/users/status/`)).data;
}
}
async getProject(): Promise<Project> {
return (await axios.get(`/projects/api/v1/${this.owner}/${this.title}/`)).data;
}
async updateProject(data): Promise<Project> {
return (await axios.put(`/projects/api/v1/${this.owner}/${this.title}/`, data)).data;
}
async createProject(data): Promise<Project> {
return (await axios.post(`/projects/api/v1/`, data)).data;
}
async createBuild(data): Promise<Build> {
return (await axios.post(`/projects/api/v1/${this.owner}/${this.title}/builds/`, data)).data;
}
async getBuild(id: number, force_reload?: boolean): Promise<Build> {
return (
await axios.get(`/projects/api/v1/builds/${id}/`, {
params: {
force_reload: force_reload,
},
})
).data;
}
async promoteTag(tag: string, version?: string): Promise<Build> {
return (
await axios.post(`/projects/api/v1/${this.owner}/${this.title}/tags/`, {
latest_tag: tag,
version: version,
staging_tag: null,
})
).data;
}
async listBuilds(): Promise<{
count: number;
next?: string;
previous: string;
results: Build[];
}> {
console.log("URL", `projects/api/v1/${this.owner}/${this.title}/builds/`);
return (await axios.get(`/projects/api/v1/${this.owner}/${this.title}/builds/`)).data;
}
async save(data): Promise<Project> {
if (this.owner && this.title) {
return await this.updateProject(data);
} else {
return await this.createProject(data);
}
}
}