-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublic.go
More file actions
101 lines (81 loc) · 2.51 KB
/
public.go
File metadata and controls
101 lines (81 loc) · 2.51 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
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
package mefrpApi
import "fmt"
// GetStatistics retrieves public statistics
func (c *Client) GetStatistics() (*Statistics, error) {
var resp Response[Statistics]
err := c.request("GET", "/public/statistics", nil, &resp)
if err != nil {
return nil, err
}
if resp.Code != 200 {
return nil, fmt.Errorf("api error: %s (code: %d)", resp.Message, resp.Code)
}
return &resp.Data, nil
}
// GetStoreItems retrieves items from the store
func (c *Client) GetStoreItems() ([]StoreItem, error) {
var resp Response[[]StoreItem]
err := c.request("GET", "/public/store/products", nil, &resp)
if err != nil {
return nil, err
}
if resp.Code != 200 {
return nil, fmt.Errorf("api error: %s (code: %d)", resp.Message, resp.Code)
}
return resp.Data, nil
}
// GetHolidayData retrieves holiday data for a given year
func (c *Client) GetHolidayData(year int) ([]string, error) {
var resp Response[[]string]
err := c.request("GET", fmt.Sprintf("/public/holiday?year=%d", year), nil, &resp)
if err != nil {
return nil, err
}
if resp.Code != 200 {
return nil, fmt.Errorf("api error: %s (code: %d)", resp.Message, resp.Code)
}
return resp.Data, nil
}
// CheckUpdateRequest represents the update check request
type CheckUpdateRequest struct {
ProductID string `json:"productId"`
CurrentVersion string `json:"currentVersion"`
System string `json:"system"`
Arch string `json:"arch"`
}
// CheckUpdate checks for software updates
func (c *Client) CheckUpdate(req CheckUpdateRequest) (*CheckUpdateResponse, error) {
var resp Response[CheckUpdateResponse]
err := c.request("POST", "/public/checkUpdate", req, &resp)
if err != nil {
return nil, err
}
if resp.Code != 200 {
return nil, fmt.Errorf("api error: %s (code: %d)", resp.Message, resp.Code)
}
return &resp.Data, nil
}
// GetDownloadSources retrieves the list of download sources
func (c *Client) GetDownloadSources() ([]DownloadSource, error) {
var resp Response[[]DownloadSource]
err := c.request("GET", "/auth/downloadSources", nil, &resp)
if err != nil {
return nil, err
}
if resp.Code != 200 {
return nil, fmt.Errorf("api error: %s (code: %d)", resp.Message, resp.Code)
}
return resp.Data, nil
}
// GetProducts retrieves the list of products
func (c *Client) GetProducts() ([]Product, error) {
var resp Response[[]Product]
err := c.request("GET", "/auth/products", nil, &resp)
if err != nil {
return nil, err
}
if resp.Code != 200 {
return nil, fmt.Errorf("api error: %s (code: %d)", resp.Message, resp.Code)
}
return resp.Data, nil
}