-
Notifications
You must be signed in to change notification settings - Fork 5
/
client.go
93 lines (76 loc) · 2.33 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
package pgyer
import (
"github.com/go-resty/resty/v2"
)
type Client struct {
apiKey string
restyClient *resty.Client
}
// https://www.pgyer.com/doc/view/api#fastUploadApp
func NewClient(apiKey string) *Client {
restyClient := resty.New()
restyClient.SetDebug(false)
restyClient.SetDebugBodyLimit(1000)
restyClient.SetBaseURL("https://www.pgyer.com/apiv2")
restyClient.SetHeader("Content-Type", "application/x-www-form-urlencoded")
return &Client{
apiKey: apiKey,
restyClient: restyClient,
}
}
type getCosTokenResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Key string `json:"key"`
Endpoint string `json:"endpoint"`
Params map[string]string `json:"params"`
} `json:"data"`
}
func (c *Client) getCosToken(updateDesc string) (*getCosTokenResponse, error) {
var r getCosTokenResponse
_, err := c.restyClient.R().
SetFormData(map[string]string{
"_api_key": c.apiKey,
"buildType": "apk",
"buildUpdateDescription": updateDesc,
}).
SetResult(&r).
Post("/app/getCOSToken")
return &r, err
}
type buildInfoResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Key string `json:"buildKey"`
Type string `json:"buildType"`
IsFirst string `json:"buildIsFirst"`
IsLastest string `json:"buildIsLastest"`
FileSize string `json:"buildFileSize"`
Name string `json:"buildName"`
Version string `json:"buildVersion"`
VersionNo string `json:"buildVersionNo"`
BuildVersion string `json:"buildBuildVersion"`
Identifier string `json:"buildIdentifier"`
Icon string `json:"buildIcon"`
Description string `json:"buildDescription"`
UpdateDesc string `json:"buildUpdateDescription"`
ScreenShots string `json:"buildScreenShots"`
ShortcutUrl string `json:"buildShortcutUrl"`
QRCodeUrl string `json:"buildQRCodeURL"`
Created string `json:"buildCreated"`
Updated string `json:"buildUpdated"`
} `json:"data"`
}
func (c *Client) buildInfo(buildKey string) (buildInfoResponse, error) {
var r buildInfoResponse
_, err := c.restyClient.R().
SetQueryParams(map[string]string{
"_api_key": c.apiKey,
"buildKey": buildKey,
}).
SetResult(&r).
Get("/app/buildInfo")
return r, err
}