diff options
author | Wim <wim@42.be> | 2016-09-05 16:34:37 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-09-05 16:34:37 +0200 |
commit | b30e85836e575974bac1b2ea91e9b6c2dd39fe44 (patch) | |
tree | b3aa5d148e436cacd6c737ad56ba3fc0b9369e26 /vendor/github.com/nlopes/slack/pins.go | |
parent | e449a97bd0114e55c2a73aa79b061b55d755aa16 (diff) | |
download | matterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.tar.gz matterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.tar.bz2 matterbridge-msglm-b30e85836e575974bac1b2ea91e9b6c2dd39fe44.zip |
Add Slack support
Diffstat (limited to 'vendor/github.com/nlopes/slack/pins.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/pins.go | 79 |
1 files changed, 79 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..b95efbb6 --- /dev/null +++ b/vendor/github.com/nlopes/slack/pins.go @@ -0,0 +1,79 @@ +package slack + +import ( + "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 { + 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("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 { + 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("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) { + values := url.Values{ + "channel": {channel}, + "token": {api.config.token}, + } + response := &listPinsResponseFull{} + err := post("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 +} |