From 122cb48ebf969196e6a80de3a1563ba798243a23 Mon Sep 17 00:00:00 2001 From: Johan McGwire Date: Wed, 24 Nov 2021 10:50:24 -0500 Subject: [PATCH] Swap to struct input --- conversation.go | 23 +++++++++++++++++------ conversation_test.go | 4 +++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/conversation.go b/conversation.go index 586430452..afde30ff0 100644 --- a/conversation.go +++ b/conversation.go @@ -357,18 +357,29 @@ func (api *Client) CreateConversationContext(ctx context.Context, channelName st return &response.Channel, nil } +// GetConversationInfoInput Defines the parameters of a GetConversationInfo and GetConversationInfoContext function +type GetConversationInfoInput struct { + ChannelID string + IncludeLocale bool + IncludeNumMembers bool +} + // GetConversationInfo retrieves information about a conversation -func (api *Client) GetConversationInfo(channelID string, includeLocale, includeNumMembers bool) (*Channel, error) { - return api.GetConversationInfoContext(context.Background(), channelID, includeLocale, includeNumMembers) +func (api *Client) GetConversationInfo(input *GetConversationInfoInput) (*Channel, error) { + return api.GetConversationInfoContext(context.Background(), input) } // GetConversationInfoContext retrieves information about a conversation with a custom context -func (api *Client) GetConversationInfoContext(ctx context.Context, channelID string, includeLocale, includeNumMembers bool) (*Channel, error) { +func (api *Client) GetConversationInfoContext(ctx context.Context, input *GetConversationInfoInput) (*Channel, error) { + if input == nil { + input = &GetConversationInfoInput{} + } + values := url.Values{ "token": {api.token}, - "channel": {channelID}, - "include_locale": {strconv.FormatBool(includeLocale)}, - "include_num_members": {strconv.FormatBool(includeNumMembers)}, + "channel": {input.ChannelID}, + "include_locale": {strconv.FormatBool(input.IncludeLocale)}, + "include_num_members": {strconv.FormatBool(input.IncludeNumMembers)}, } response, err := api.channelRequest(ctx, "conversations.info", values) if err != nil { diff --git a/conversation_test.go b/conversation_test.go index f1a4a0dd9..fedba8f8b 100644 --- a/conversation_test.go +++ b/conversation_test.go @@ -400,7 +400,9 @@ func TestGetConversationInfo(t *testing.T) { http.HandleFunc("/conversations.info", okChannelJsonHandler) once.Do(startServer) api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/")) - channel, err := api.GetConversationInfo("CXXXXXXXX", false, false) + channel, err := api.GetConversationInfo(&GetConversationInfoInput{ + ChannelID: "CXXXXXXXX", + }) if err != nil { t.Errorf("Unexpected error: %s", err) return