Debian Codegraph @

pins.go

raw symbols SCIP
1 package slack
2
3 import (
4 "context"
5 "errors"
6 "net/url"
7 )
8
9 type listPinsResponseFull struct {
10 Items []Item
11 Paging `json:"paging"`
12 SlackResponse
13 }
14
15 // AddPin pins an item in a channel
16 func (api *Client) AddPin(channel string, item ItemRef) error {
17 return api.AddPinContext(context.Background(), channel, item)
18 }
19
20 // AddPinContext pins an item in a channel with a custom context
21 func (api *Client) AddPinContext(ctx context.Context, channel string, item ItemRef) error {
22 values := url.Values{
23 "channel": {channel},
24 "token": {api.token},
25 }
26 if item.Timestamp != "" {
27 values.Set("timestamp", item.Timestamp)
28 }
29 if item.File != "" {
30 values.Set("file", item.File)
31 }
32 if item.Comment != "" {
33 values.Set("file_comment", item.Comment)
34 }
35
36 response := &SlackResponse{}
37 if err := api.postMethod(ctx, "pins.add", values, response); err != nil {
38 return err
39 }
40
41 return response.Err()
42 }
43
44 // RemovePin un-pins an item from a channel
45 func (api *Client) RemovePin(channel string, item ItemRef) error {
46 return api.RemovePinContext(context.Background(), channel, item)
47 }
48
49 // RemovePinContext un-pins an item from a channel with a custom context
50 func (api *Client) RemovePinContext(ctx context.Context, channel string, item ItemRef) error {
51 values := url.Values{
52 "channel": {channel},
53 "token": {api.token},
54 }
55 if item.Timestamp != "" {
56 values.Set("timestamp", item.Timestamp)
57 }
58 if item.File != "" {
59 values.Set("file", item.File)
60 }
61 if item.Comment != "" {
62 values.Set("file_comment", item.Comment)
63 }
64
65 response := &SlackResponse{}
66 if err := api.postMethod(ctx, "pins.remove", values, response); err != nil {
67 return err
68 }
69
70 return response.Err()
71 }
72
73 // ListPins returns information about the items a user reacted to.
74 func (api *Client) ListPins(channel string) ([]Item, *Paging, error) {
75 return api.ListPinsContext(context.Background(), channel)
76 }
77
78 // ListPinsContext returns information about the items a user reacted to with a custom context.
79 func (api *Client) ListPinsContext(ctx context.Context, channel string) ([]Item, *Paging, error) {
80 values := url.Values{
81 "channel": {channel},
82 "token": {api.token},
83 }
84
85 response := &listPinsResponseFull{}
86 err := api.postMethod(ctx, "pins.list", values, response)
87 if err != nil {
88 return nil, nil, err
89 }
90 if !response.Ok {
91 return nil, nil, errors.New(response.Error)
92 }
93 return response.Items, &response.Paging, nil
94 }