matterbridge/vendor/github.com/slack-go/slack/pins.go

101 lines
2.7 KiB
Go
Raw Permalink Normal View History

2016-09-05 07:34:37 -07:00
package slack
import (
2017-07-16 05:29:46 -07:00
"context"
2016-09-05 07:34:37 -07:00
"errors"
"net/url"
)
type listPinsResponseFull struct {
Items []Item
Paging `json:"paging"`
SlackResponse
}
// AddPin pins an item in a channel.
// For more details, see AddPinContext documentation.
2016-09-05 07:34:37 -07:00
func (api *Client) AddPin(channel string, item ItemRef) error {
2017-07-16 05:29:46 -07:00
return api.AddPinContext(context.Background(), channel, item)
}
// AddPinContext pins an item in a channel with a custom context.
// Slack API docs: https://api.slack.com/methods/pins.add
2017-07-16 05:29:46 -07:00
func (api *Client) AddPinContext(ctx context.Context, channel string, item ItemRef) error {
2016-09-05 07:34:37 -07:00
values := url.Values{
"channel": {channel},
2018-08-09 15:38:19 -07:00
"token": {api.token},
2016-09-05 07:34:37 -07:00
}
if item.Timestamp != "" {
2018-08-09 15:38:19 -07:00
values.Set("timestamp", item.Timestamp)
2016-09-05 07:34:37 -07:00
}
if item.File != "" {
2018-08-09 15:38:19 -07:00
values.Set("file", item.File)
2016-09-05 07:34:37 -07:00
}
if item.Comment != "" {
2018-08-09 15:38:19 -07:00
values.Set("file_comment", item.Comment)
2016-09-05 07:34:37 -07:00
}
2018-08-09 15:38:19 -07:00
2016-09-05 07:34:37 -07:00
response := &SlackResponse{}
2019-09-07 13:46:58 -07:00
if err := api.postMethod(ctx, "pins.add", values, response); err != nil {
2016-09-05 07:34:37 -07:00
return err
}
2018-08-09 15:38:19 -07:00
return response.Err()
2016-09-05 07:34:37 -07:00
}
// RemovePin un-pins an item from a channel.
// For more details, see RemovePinContext documentation.
2016-09-05 07:34:37 -07:00
func (api *Client) RemovePin(channel string, item ItemRef) error {
2017-07-16 05:29:46 -07:00
return api.RemovePinContext(context.Background(), channel, item)
}
// RemovePinContext un-pins an item from a channel with a custom context.
// Slack API docs: https://api.slack.com/methods/pins.remove
2017-07-16 05:29:46 -07:00
func (api *Client) RemovePinContext(ctx context.Context, channel string, item ItemRef) error {
2016-09-05 07:34:37 -07:00
values := url.Values{
"channel": {channel},
2018-08-09 15:38:19 -07:00
"token": {api.token},
2016-09-05 07:34:37 -07:00
}
if item.Timestamp != "" {
2018-08-09 15:38:19 -07:00
values.Set("timestamp", item.Timestamp)
2016-09-05 07:34:37 -07:00
}
if item.File != "" {
2018-08-09 15:38:19 -07:00
values.Set("file", item.File)
2016-09-05 07:34:37 -07:00
}
if item.Comment != "" {
2018-08-09 15:38:19 -07:00
values.Set("file_comment", item.Comment)
2016-09-05 07:34:37 -07:00
}
2018-08-09 15:38:19 -07:00
2016-09-05 07:34:37 -07:00
response := &SlackResponse{}
2019-09-07 13:46:58 -07:00
if err := api.postMethod(ctx, "pins.remove", values, response); err != nil {
2016-09-05 07:34:37 -07:00
return err
}
2018-08-09 15:38:19 -07:00
return response.Err()
2016-09-05 07:34:37 -07:00
}
// ListPins returns information about the items a user reacted to.
// For more details, see ListPinsContext documentation.
2016-09-05 07:34:37 -07:00
func (api *Client) ListPins(channel string) ([]Item, *Paging, error) {
2017-07-16 05:29:46 -07:00
return api.ListPinsContext(context.Background(), channel)
}
// ListPinsContext returns information about the items a user reacted to with a custom context.
// Slack API docs: https://api.slack.com/methods/pins.list
2017-07-16 05:29:46 -07:00
func (api *Client) ListPinsContext(ctx context.Context, channel string) ([]Item, *Paging, error) {
2016-09-05 07:34:37 -07:00
values := url.Values{
"channel": {channel},
2018-08-09 15:38:19 -07:00
"token": {api.token},
2016-09-05 07:34:37 -07:00
}
2018-08-09 15:38:19 -07:00
2016-09-05 07:34:37 -07:00
response := &listPinsResponseFull{}
2019-09-07 13:46:58 -07:00
err := api.postMethod(ctx, "pins.list", values, response)
2016-09-05 07:34:37 -07:00
if err != nil {
return nil, nil, err
}
if !response.Ok {
return nil, nil, errors.New(response.Error)
}
return response.Items, &response.Paging, nil
}