45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package chat
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"fmt"
|
||
"net/http"
|
||
|
||
"go.fifitido.net/twitch/api/endpoint"
|
||
)
|
||
|
||
type GetGlobalChatBadgesResponse struct {
|
||
// The list of chat badges. The list is sorted in ascending order by set_id, and within a set, the list is sorted in ascending order by id.
|
||
Data []Badge `json:"data"`
|
||
}
|
||
|
||
// Gets Twitch’s list of chat badges, which users may use in any channel’s chat room.
|
||
// For information about chat badges, see Twitch Chat Badges Guide: https://help.twitch.tv/s/article/twitch-chat-badges-guide
|
||
//
|
||
// Requires an app access token or user access token.
|
||
func (c *Chat) GetGlobalChatBadges(ctx context.Context) (*GetGlobalChatBadgesResponse, error) {
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/badges/global"), nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
res, err := c.client.Do(req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
defer res.Body.Close()
|
||
|
||
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
||
if !statusOK {
|
||
return nil, fmt.Errorf("failed to get global chat badges (%d)", res.StatusCode)
|
||
}
|
||
|
||
var data GetGlobalChatBadgesResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|