Skip to content

Commit

Permalink
Swap to struct input
Browse files Browse the repository at this point in the history
  • Loading branch information
johanmcgwire-cb committed Nov 24, 2021
1 parent 094f096 commit 122cb48
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 17 additions & 6 deletions conversation.go
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion conversation_test.go
Expand Up @@ -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
Expand Down

0 comments on commit 122cb48

Please sign in to comment.