forked from igungor/go-putio
-
Notifications
You must be signed in to change notification settings - Fork 8
/
events.go
47 lines (39 loc) · 1.03 KB
/
events.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
package putio
import (
"context"
"net/http"
)
// EventsService is the service to gather information about user's events.
type EventsService struct {
client *Client
}
// nolint:godox
// FIXME: events list returns inconsistent data structures.
// List gets list of dashboard events. It includes downloads and share events.
func (e *EventsService) List(ctx context.Context) ([]Event, error) {
req, err := e.client.NewRequest(ctx, http.MethodGet, "/v2/events/list", nil)
if err != nil {
return nil, err
}
var r struct {
Events []Event
}
_, err = e.client.Do(req, &r) // nolint:bodyclose
if err != nil {
return nil, err
}
return r.Events, nil
}
// Delete Clears all dashboard events.
func (e *EventsService) Delete(ctx context.Context) error {
req, err := e.client.NewRequest(ctx, http.MethodPost, "/v2/events/delete", nil)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
_, err = e.client.Do(req, &struct{}{}) // nolint:bodyclose
if err != nil {
return err
}
return nil
}