66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package ccls
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/google/go-querystring/query"
|
|
"go.fifitido.net/twitch/api/endpoint"
|
|
"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)
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "content_classification_labels", v), 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 content classification labels (%d)", res.StatusCode)
|
|
}
|
|
|
|
var data GetContentClassificationLabelsResponse
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &data, nil
|
|
}
|