-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatchesGetFiles.go
92 lines (74 loc) · 1.72 KB
/
patchesGetFiles.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
package updateApiClient
import (
"bytes"
"github.com/monaco-io/request"
"io"
)
const (
patchesGetFilesPath = "/update-platform/patches/getFiles"
)
type PatchesGetFilesRequest struct {
PatchUinList []string `json:"patchUinList"`
Login string `json:"login"`
Password string `json:"password"`
}
type PatchesGetFilesResponse struct {
ErrorResponse
PatchDistributionDataList []PatchDistributionData `json:"patchDistributionDataList"`
}
type PatchDistributionData struct {
PatchUeid string `json:"patchUeid"`
PatchFileUrl string `json:"patchFileUrl"`
PatchFileName string `json:"patchFileName"`
Size int `json:"size"`
HashSum string `json:"hashSum"`
}
type PatchDistributionFile struct {
io.Reader
PatchDistributionData
}
func (c PatchesGetFilesResponse) Error() error {
if len(c.ErrorName) == 0 {
return nil
}
return c.ErrorResponse
}
func (c *Client) GetPatchesFilesInfo(patchUinList ...string) (PatchesGetFilesResponse, error) {
var result PatchesGetFilesResponse
data := PatchesGetFilesRequest{
patchUinList,
c.Username,
c.Password,
}
resp, err := c.doRequest(apiRequest{
patchesGetFilesPath,
request.POST,
data,
})
if err != nil {
return result, err
}
resp.Scan(&result)
return result, result.Error()
}
func (c *Client) GetPatchDistributionData(data PatchDistributionData) (*PatchDistributionFile, error) {
type loginParams struct {
Login string `json:"login"`
Password string `json:"password"`
}
resp, err := c.doRawRequest("", apiRequest{
data.PatchFileUrl,
request.POST,
loginParams{
c.Username,
c.Password,
},
})
if err != nil {
return nil, err
}
return &PatchDistributionFile{
bytes.NewBuffer(resp.Bytes()),
data,
}, nil
}