Skip to content

Commit

Permalink
add GetStickerNamesByCollection method
Browse files Browse the repository at this point in the history
  • Loading branch information
UtopistMan committed Dec 25, 2021
1 parent 62ddef9 commit 7e193d1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions utopia.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ func (c *UtopiaClient) queryResultToInterfaceArray(methodName string, params map
return nil, errors.New("accaptable result doesn't exists in client response")
}

func (c *UtopiaClient) queryResultToStringsArray(methodName string, params map[string]interface{}) ([]string, error) {
if !c.CheckClientConnection() {
return nil, errors.New("client disconected")
}
response, err := c.apiQuery(methodName, params)
if result, ok := response["result"]; ok {
//check type assertion
IResult, isConvertable := result.([]string)
if !isConvertable {
return nil, errors.New("failed to get result array")
}
return IResult, err
}
return nil, errors.New("accaptable result doesn't exists in client response")
}

func (c *UtopiaClient) queryResultToString(methodName string, params map[string]interface{}) (string, error) {
if !c.CheckClientConnection() {
return "", errors.New("client disconected")
Expand Down Expand Up @@ -293,3 +309,11 @@ func (c *UtopiaClient) SendChannelPicture(channelID, base64Image, comment, filen
}
return c.queryResultToString("sendChannelPicture", params)
}

// GetStickerNamesByCollection returns available names from corresponded collection
func (c *UtopiaClient) GetStickerNamesByCollection(collectionName string) ([]string, error) {
params := map[string]interface{}{
"collection_name": collectionName,
}
return c.queryResultToStringsArray("getStickerNamesByCollection", params)
}

0 comments on commit 7e193d1

Please sign in to comment.