forked from igungor/go-putio
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaccount.go
45 lines (39 loc) · 984 Bytes
/
account.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
package putio
import (
"context"
"net/http"
)
// AccountService is the service to gather information about user account.
type AccountService struct {
client *Client
}
// Info retrieves user account information.
func (a *AccountService) Info(ctx context.Context) (AccountInfo, error) {
req, err := a.client.NewRequest(ctx, http.MethodGet, "/v2/account/info", nil)
if err != nil {
return AccountInfo{}, err
}
var r struct {
Info AccountInfo
}
_, err = a.client.Do(req, &r) // nolint:bodyclose
if err != nil {
return AccountInfo{}, err
}
return r.Info, nil
}
// Settings retrieves user preferences.
func (a *AccountService) Settings(ctx context.Context) (Settings, error) {
req, err := a.client.NewRequest(ctx, http.MethodGet, "/v2/account/settings", nil)
if err != nil {
return Settings{}, err
}
var r struct {
Settings Settings
}
_, err = a.client.Do(req, &r) // nolint:bodyclose
if err != nil {
return Settings{}, err
}
return r.Settings, nil
}