summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nlopes/slack/pins.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-01-08 22:41:38 +0100
committerWim <wim@42.be>2018-01-09 00:07:55 +0100
commitbe898b44c3c057c7b70efb83f66b7bbbdd5e9276 (patch)
tree01c8983913bcae177b5e0e015de9a45abe8369a7 /vendor/github.com/nlopes/slack/pins.go
parent4828c434439949f62a6e219ab9947c221a06b111 (diff)
downloadmatterbridge-msglm-be898b44c3c057c7b70efb83f66b7bbbdd5e9276.tar.gz
matterbridge-msglm-be898b44c3c057c7b70efb83f66b7bbbdd5e9276.tar.bz2
matterbridge-msglm-be898b44c3c057c7b70efb83f66b7bbbdd5e9276.zip
Update vendor (slack)
Diffstat (limited to 'vendor/github.com/nlopes/slack/pins.go')
-rw-r--r--vendor/github.com/nlopes/slack/pins.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/vendor/github.com/nlopes/slack/pins.go b/vendor/github.com/nlopes/slack/pins.go
new file mode 100644
index 00000000..a20f8f73
--- /dev/null
+++ b/vendor/github.com/nlopes/slack/pins.go
@@ -0,0 +1,95 @@
+package slack
+
+import (
+ "context"
+ "errors"
+ "net/url"
+)
+
+type listPinsResponseFull struct {
+ Items []Item
+ Paging `json:"paging"`
+ SlackResponse
+}
+
+// AddPin pins an item in a channel
+func (api *Client) AddPin(channel string, item ItemRef) error {
+ return api.AddPinContext(context.Background(), channel, item)
+}
+
+// AddPinContext pins an item in a channel with a custom context
+func (api *Client) AddPinContext(ctx context.Context, channel string, item ItemRef) error {
+ values := url.Values{
+ "channel": {channel},
+ "token": {api.config.token},
+ }
+ if item.Timestamp != "" {
+ values.Set("timestamp", string(item.Timestamp))
+ }
+ if item.File != "" {
+ values.Set("file", string(item.File))
+ }
+ if item.Comment != "" {
+ values.Set("file_comment", string(item.Comment))
+ }
+ response := &SlackResponse{}
+ if err := post(ctx, "pins.add", values, response, api.debug); err != nil {
+ return err
+ }
+ if !response.Ok {
+ return errors.New(response.Error)
+ }
+ return nil
+}
+
+// RemovePin un-pins an item from a channel
+func (api *Client) RemovePin(channel string, item ItemRef) error {
+ return api.RemovePinContext(context.Background(), channel, item)
+}
+
+// RemovePinContext un-pins an item from a channel with a custom context
+func (api *Client) RemovePinContext(ctx context.Context, channel string, item ItemRef) error {
+ values := url.Values{
+ "channel": {channel},
+ "token": {api.config.token},
+ }
+ if item.Timestamp != "" {
+ values.Set("timestamp", string(item.Timestamp))
+ }
+ if item.File != "" {
+ values.Set("file", string(item.File))
+ }
+ if item.Comment != "" {
+ values.Set("file_comment", string(item.Comment))
+ }
+ response := &SlackResponse{}
+ if err := post(ctx, "pins.remove", values, response, api.debug); err != nil {
+ return err
+ }
+ if !response.Ok {
+ return errors.New(response.Error)
+ }
+ return nil
+}
+
+// ListPins returns information about the items a user reacted to.
+func (api *Client) ListPins(channel string) ([]Item, *Paging, error) {
+ return api.ListPinsContext(context.Background(), channel)
+}
+
+// ListPinsContext returns information about the items a user reacted to with a custom context.
+func (api *Client) ListPinsContext(ctx context.Context, channel string) ([]Item, *Paging, error) {
+ values := url.Values{
+ "channel": {channel},
+ "token": {api.config.token},
+ }
+ response := &listPinsResponseFull{}
+ err := post(ctx, "pins.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
+}