Update nlopes/slack vendor

This commit is contained in:
Wim
2018-08-10 00:38:19 +02:00
parent 51062863a5
commit 68aeb93afa
57 changed files with 2654 additions and 2047 deletions

View File

@@ -28,9 +28,9 @@ type groupResponseFull struct {
SlackResponse
}
func groupRequest(ctx context.Context, path string, values url.Values, debug bool) (*groupResponseFull, error) {
func groupRequest(ctx context.Context, client HTTPRequester, path string, values url.Values, debug bool) (*groupResponseFull, error) {
response := &groupResponseFull{}
err := post(ctx, path, values, response, debug)
err := postForm(ctx, client, SLACK_API+path, values, response, debug)
if err != nil {
return nil, err
}
@@ -45,17 +45,15 @@ func (api *Client) ArchiveGroup(group string) error {
return api.ArchiveGroupContext(context.Background(), group)
}
// ArchiveGroup archives a private group
// ArchiveGroupContext archives a private group
func (api *Client) ArchiveGroupContext(ctx context.Context, group string) error {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
}
_, err := groupRequest(ctx, "groups.archive", values, api.debug)
if err != nil {
return err
}
return nil
_, err := groupRequest(ctx, api.httpclient, "groups.archive", values, api.debug)
return err
}
// UnarchiveGroup unarchives a private group
@@ -63,17 +61,15 @@ func (api *Client) UnarchiveGroup(group string) error {
return api.UnarchiveGroupContext(context.Background(), group)
}
// UnarchiveGroup unarchives a private group
// UnarchiveGroupContext unarchives a private group
func (api *Client) UnarchiveGroupContext(ctx context.Context, group string) error {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
}
_, err := groupRequest(ctx, "groups.unarchive", values, api.debug)
if err != nil {
return err
}
return nil
_, err := groupRequest(ctx, api.httpclient, "groups.unarchive", values, api.debug)
return err
}
// CreateGroup creates a private group
@@ -81,13 +77,14 @@ func (api *Client) CreateGroup(group string) (*Group, error) {
return api.CreateGroupContext(context.Background(), group)
}
// CreateGroup creates a private group
// CreateGroupContext creates a private group
func (api *Client) CreateGroupContext(ctx context.Context, group string) (*Group, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"name": {group},
}
response, err := groupRequest(ctx, "groups.create", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.create", values, api.debug)
if err != nil {
return nil, err
}
@@ -104,14 +101,15 @@ func (api *Client) CreateChildGroup(group string) (*Group, error) {
return api.CreateChildGroupContext(context.Background(), group)
}
// CreateChildGroup creates a new private group archiving the old one with a custom context
// CreateChildGroupContext creates a new private group archiving the old one with a custom context
// For more information see CreateChildGroup
func (api *Client) CreateChildGroupContext(ctx context.Context, group string) (*Group, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
}
response, err := groupRequest(ctx, "groups.createChild", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.createChild", values, api.debug)
if err != nil {
return nil, err
}
@@ -126,10 +124,11 @@ func (api *Client) CloseGroup(group string) (bool, bool, error) {
// CloseGroupContext closes a private group with a custom context
func (api *Client) CloseGroupContext(ctx context.Context, group string) (bool, bool, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
}
response, err := imRequest(ctx, "groups.close", values, api.debug)
response, err := imRequest(ctx, api.httpclient, "groups.close", values, api.debug)
if err != nil {
return false, false, err
}
@@ -144,7 +143,7 @@ func (api *Client) GetGroupHistory(group string, params HistoryParameters) (*His
// GetGroupHistoryContext fetches all the history for a private group with a custom context
func (api *Client) GetGroupHistoryContext(ctx context.Context, group string, params HistoryParameters) (*History, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
}
if params.Latest != DEFAULT_HISTORY_LATEST {
@@ -170,7 +169,8 @@ func (api *Client) GetGroupHistoryContext(ctx context.Context, group string, par
values.Add("unreads", "0")
}
}
response, err := groupRequest(ctx, "groups.history", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.history", values, api.debug)
if err != nil {
return nil, err
}
@@ -185,11 +185,12 @@ func (api *Client) InviteUserToGroup(group, user string) (*Group, bool, error) {
// InviteUserToGroupContext invites a specific user to a private group with a custom context
func (api *Client) InviteUserToGroupContext(ctx context.Context, group, user string) (*Group, bool, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
"user": {user},
}
response, err := groupRequest(ctx, "groups.invite", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.invite", values, api.debug)
if err != nil {
return nil, false, err
}
@@ -202,12 +203,13 @@ func (api *Client) LeaveGroup(group string) error {
}
// LeaveGroupContext makes authenticated user leave the group with a custom context
func (api *Client) LeaveGroupContext(ctx context.Context, group string) error {
func (api *Client) LeaveGroupContext(ctx context.Context, group string) (err error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
}
_, err := groupRequest(ctx, "groups.leave", values, api.debug)
_, err = groupRequest(ctx, api.httpclient, "groups.leave", values, api.debug)
return err
}
@@ -217,13 +219,14 @@ func (api *Client) KickUserFromGroup(group, user string) error {
}
// KickUserFromGroupContext kicks a user from a group with a custom context
func (api *Client) KickUserFromGroupContext(ctx context.Context, group, user string) error {
func (api *Client) KickUserFromGroupContext(ctx context.Context, group, user string) (err error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
"user": {user},
}
_, err := groupRequest(ctx, "groups.kick", values, api.debug)
_, err = groupRequest(ctx, api.httpclient, "groups.kick", values, api.debug)
return err
}
@@ -235,12 +238,13 @@ func (api *Client) GetGroups(excludeArchived bool) ([]Group, error) {
// GetGroupsContext retrieves all groups with a custom context
func (api *Client) GetGroupsContext(ctx context.Context, excludeArchived bool) ([]Group, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
}
if excludeArchived {
values.Add("exclude_archived", "1")
}
response, err := groupRequest(ctx, "groups.list", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.list", values, api.debug)
if err != nil {
return nil, err
}
@@ -255,10 +259,11 @@ func (api *Client) GetGroupInfo(group string) (*Group, error) {
// GetGroupInfoContext retrieves the given group with a custom context
func (api *Client) GetGroupInfoContext(ctx context.Context, group string) (*Group, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
}
response, err := groupRequest(ctx, "groups.info", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.info", values, api.debug)
if err != nil {
return nil, err
}
@@ -276,13 +281,14 @@ func (api *Client) SetGroupReadMark(group, ts string) error {
// SetGroupReadMarkContext sets the read mark on a private group with a custom context
// For more details see SetGroupReadMark
func (api *Client) SetGroupReadMarkContext(ctx context.Context, group, ts string) error {
func (api *Client) SetGroupReadMarkContext(ctx context.Context, group, ts string) (err error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
"ts": {ts},
}
_, err := groupRequest(ctx, "groups.mark", values, api.debug)
_, err = groupRequest(ctx, api.httpclient, "groups.mark", values, api.debug)
return err
}
@@ -294,10 +300,11 @@ func (api *Client) OpenGroup(group string) (bool, bool, error) {
// OpenGroupContext opens a private group with a custom context
func (api *Client) OpenGroupContext(ctx context.Context, group string) (bool, bool, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
}
response, err := groupRequest(ctx, "groups.open", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.open", values, api.debug)
if err != nil {
return false, false, err
}
@@ -314,13 +321,14 @@ func (api *Client) RenameGroup(group, name string) (*Channel, error) {
// RenameGroupContext renames a group with a custom context
func (api *Client) RenameGroupContext(ctx context.Context, group, name string) (*Channel, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
"name": {name},
}
// XXX: the created entry in this call returns a string instead of a number
// so I may have to do some workaround to solve it.
response, err := groupRequest(ctx, "groups.rename", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.rename", values, api.debug)
if err != nil {
return nil, err
}
@@ -335,11 +343,12 @@ func (api *Client) SetGroupPurpose(group, purpose string) (string, error) {
// SetGroupPurposeContext sets the group purpose with a custom context
func (api *Client) SetGroupPurposeContext(ctx context.Context, group, purpose string) (string, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
"purpose": {purpose},
}
response, err := groupRequest(ctx, "groups.setPurpose", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.setPurpose", values, api.debug)
if err != nil {
return "", err
}
@@ -354,11 +363,12 @@ func (api *Client) SetGroupTopic(group, topic string) (string, error) {
// SetGroupTopicContext sets the group topic with a custom context
func (api *Client) SetGroupTopicContext(ctx context.Context, group, topic string) (string, error) {
values := url.Values{
"token": {api.config.token},
"token": {api.token},
"channel": {group},
"topic": {topic},
}
response, err := groupRequest(ctx, "groups.setTopic", values, api.debug)
response, err := groupRequest(ctx, api.httpclient, "groups.setTopic", values, api.debug)
if err != nil {
return "", err
}