-
Notifications
You must be signed in to change notification settings - Fork 18
/
event_drive.go
107 lines (81 loc) · 2.42 KB
/
event_drive.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
103
104
105
106
107
package proton
import (
"context"
"github.com/go-resty/resty/v2"
)
func (c *Client) GetLatestVolumeEventID(ctx context.Context, volumeID string) (string, error) {
var res struct {
EventID string
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/drive/volumes/" + volumeID + "/events/latest")
}); err != nil {
return "", err
}
return res.EventID, nil
}
func (c *Client) GetLatestShareEventID(ctx context.Context, shareID string) (string, error) {
var res struct {
EventID string
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/drive/shares/" + shareID + "/events/latest")
}); err != nil {
return "", err
}
return res.EventID, nil
}
func (c *Client) GetVolumeEvent(ctx context.Context, volumeID, eventID string) (DriveEvent, error) {
event, more, err := c.getVolumeEvent(ctx, volumeID, eventID)
if err != nil {
return DriveEvent{}, err
}
for more {
var next DriveEvent
next, more, err = c.getVolumeEvent(ctx, volumeID, event.EventID)
if err != nil {
return DriveEvent{}, err
}
event.Events = append(event.Events, next.Events...)
}
return event, nil
}
func (c *Client) GetShareEvent(ctx context.Context, shareID, eventID string) (DriveEvent, error) {
event, more, err := c.getShareEvent(ctx, shareID, eventID)
if err != nil {
return DriveEvent{}, err
}
for more {
var next DriveEvent
next, more, err = c.getShareEvent(ctx, shareID, event.EventID)
if err != nil {
return DriveEvent{}, err
}
event.Events = append(event.Events, next.Events...)
}
return event, nil
}
func (c *Client) getVolumeEvent(ctx context.Context, volumeID, eventID string) (DriveEvent, bool, error) {
var res struct {
DriveEvent
More Bool
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/drive/volumes/" + volumeID + "/events/" + eventID)
}); err != nil {
return DriveEvent{}, false, err
}
return res.DriveEvent, bool(res.More), nil
}
func (c *Client) getShareEvent(ctx context.Context, shareID, eventID string) (DriveEvent, bool, error) {
var res struct {
DriveEvent
More Bool
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/drive/shares/" + shareID + "/events/" + eventID)
}); err != nil {
return DriveEvent{}, false, err
}
return res.DriveEvent, bool(res.More), nil
}