This repository was archived by the owner on Nov 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrtm_lists.go
More file actions
66 lines (58 loc) · 1.33 KB
/
rtm_lists.go
File metadata and controls
66 lines (58 loc) · 1.33 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
package rtm
import (
"context"
"encoding/json"
)
type ListsService struct {
client *Client
}
type List struct {
ID string
Name string
Position int
Locked bool
Archived bool
Deleted bool
Smart bool
}
// https://www.rememberthemilk.com/services/api/methods/rtm.lists.getList.rtm
func (l *ListsService) GetList(ctx context.Context) ([]List, error) {
b, err := l.client.Call(ctx, "rtm.lists.getList", nil)
if err != nil {
return nil, err
}
return l.getListUnmarshal(b)
}
func (l *ListsService) getListUnmarshal(b []byte) ([]List, error) {
var resp struct {
Rsp struct {
Lists struct {
List []struct {
ID string `json:"id"`
Name string `json:"name"`
Deleted rtmBool `json:"deleted"`
Locked rtmBool `json:"locked"`
Archived rtmBool `json:"archived"`
Position int `json:"position,string"`
Smart rtmBool `json:"smart"`
} `json:"list"`
} `json:"lists"`
} `json:"rsp"`
}
if err := json.Unmarshal(b, &resp); err != nil {
return nil, err
}
res := make([]List, len(resp.Rsp.Lists.List))
for i, l := range resp.Rsp.Lists.List {
res[i] = List{
ID: l.ID,
Name: l.Name,
Position: l.Position,
Locked: bool(l.Locked),
Archived: bool(l.Archived),
Deleted: bool(l.Deleted),
Smart: bool(l.Smart),
}
}
return res, nil
}