go-twitch/api/ccls/get_content_classification_...

61 lines
1.6 KiB
Go

package ccls
import (
"context"
"encoding/json"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/types"
)
type GetContentClassificationLabelsParams struct {
// Locale for the Content Classification Labels.
// You may specify a maximum of 1 locale.
// Default: “en-US”
Locale *types.Locale `url:"locale,omitempty"`
}
type GetContentClassificationLabelsResponse struct {
// A list that contains information about the available content classification labels.
Data []ContentClassificationLabelData `json:"data"`
}
type ContentClassificationLabelData struct {
// Unique identifier for the CCL.
ID ContentClassificationLabel `json:"id"`
// Localized description of the CCL.
Description string `json:"description"`
// Localized name of the CCL.
Name string `json:"name"`
}
// Gets information about Twitch content classification labels.
//
// Requires an app access token or user access token.
func (c *CCLS) GetContentClassificationLabels(ctx context.Context, params GetContentClassificationLabelsParams) (*GetContentClassificationLabelsResponse, error) {
v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "content_classification_labels", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data GetContentClassificationLabelsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}