-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
102 lines (82 loc) · 2.3 KB
/
client.go
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package reportportal
import "net/http"
import "encoding/json"
import "bytes"
import "io/ioutil"
type Client struct {
ApiKey string
ApiUrl string
}
type CreateProjectRequest struct {
ProjectName string
EntryType string
}
type GetProjectResponse struct {
ProjectId string
Configuration ProjectConfiguration
}
type ProjectConfiguration struct {
ExternalSystem []string
EntryType string
StatisticCalculationStrategy string
ProjectSpecific string
InterruptedJob string
KeepLogs string
KeepScreenshots string
EmailConfiguration ProjectEmailConfiguration
AnalyzerConfiguration ProjectAnalyzerConfiguration
}
type ProjectEmailConfiguration struct {
EmailEnabled bool
FromAddress string
EmailCases EmailCase
}
type EmailCase struct {
Recipients []string
SendCase string
LaunchNames []string
Tags []string
}
type ProjectAnalyzerConfiguration struct {
MinDocFreq int
MinTermFreq int
MinShouldMatch int
NumberOfLogLines int
IsAutoAnalyzerEnabled bool
AnalyzerMode string `json:"analyzer_mode"`
IndexingRunning string `json:"indexing_running"`
}
func (c *Client) CreateProject(projectName string) string{
requestBody := &CreateProjectRequest{
ProjectName: projectName,
EntryType: "INTERNAL",
}
bodyStream, _ := json.Marshal(requestBody)
client := &http.Client{}
req, _ := http.NewRequest("POST", c.ApiUrl + "/project", bytes.NewReader(bodyStream))
req.Header.Set("Authorization", "bearer " + c.ApiKey)
req.Header.Set("Content-Type", "application/json")
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return string(body)
}
func (c *Client) DeleteProject(projectName string) string{
client := &http.Client{}
req, _ := http.NewRequest("DELETE", c.ApiUrl + "/project/" + projectName, nil)
req.Header.Set("Authorization", "bearer " + c.ApiKey)
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return string(body)
}
func (c *Client) GetProject(projectName string) *GetProjectResponse{
client := &http.Client{}
req, _ := http.NewRequest("GET", c.ApiUrl + "/project/" + projectName, nil)
req.Header.Set("Authorization", "bearer " + c.ApiKey)
resp, _ := client.Do(req)
getProjectResponse := GetProjectResponse{}
json.NewDecoder(resp.Body).Decode(&getProjectResponse)
defer resp.Body.Close()
return &getProjectResponse
}