forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstars.go
76 lines (69 loc) · 1.75 KB
/
stars.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
package slack
import (
"errors"
"net/url"
"strconv"
)
const (
DEFAULT_STARS_USERID = ""
DEFAULT_STARS_COUNT = 100
DEFAULT_STARS_PAGE = 1
)
type StarsParameters struct {
User string
Count int
Page int
}
// XXX: Verify this. The whole thing is complicated. I don't like the way they mixed things
type StarredItem struct {
Type string `json:"type"`
ChannelId string `json:"channel"`
Message `json:"message"`
File `json:"file"`
Comment `json:"comment"`
}
type starsResponseFull struct {
Items []StarredItem `json:"items"`
Paging `json:"paging"`
SlackResponse
}
func NewStarsParameters() StarsParameters {
return StarsParameters{
User: DEFAULT_STARS_USERID,
Count: DEFAULT_STARS_COUNT,
Page: DEFAULT_STARS_PAGE,
}
}
// GetStarred returns a list of StarredItem items. The user then has to iterate over them and figure out what they should
// be looking at according to what is in the Type.
// for _, item := range items {
// switch c.Type {
// case "file_comment":
// log.Println(c.Comment)
// case "file":
// ...
// }
// }
func (api *Slack) GetStarred(params StarsParameters) ([]StarredItem, *Paging, error) {
response := &starsResponseFull{}
values := url.Values{
"token": {api.config.token},
}
if params.User != DEFAULT_STARS_USERID {
values.Add("user", params.User)
}
if params.Count != DEFAULT_STARS_COUNT {
values.Add("count", strconv.Itoa(params.Count))
}
if params.Page != DEFAULT_STARS_PAGE {
values.Add("page", strconv.Itoa(params.Page))
}
err := parseResponse("stars.list", values, response, api.debug)
if err != nil {
return nil, nil, err
}
if !response.Ok {
return nil, nil, errors.New(response.Error)
}
return response.Items, &response.Paging, nil
}