diff --git a/api/api.go b/api/api.go index 08e761d..f300293 100644 --- a/api/api.go +++ b/api/api.go @@ -7,6 +7,7 @@ import ( "go.fifitido.net/twitch/api/ads" "go.fifitido.net/twitch/api/analytics" "go.fifitido.net/twitch/api/bits" + "go.fifitido.net/twitch/api/ccls" "go.fifitido.net/twitch/api/channelpoints" "go.fifitido.net/twitch/api/channels" "go.fifitido.net/twitch/api/charity" @@ -29,6 +30,7 @@ type API struct { Charity *charity.Charity Chat *chat.Chat Conduit *conduit.Conduit + CCLS *ccls.CCLS EventSub *eventsub.EventSub } @@ -48,6 +50,7 @@ func New() *API { Charity: charity.New(client, baseUrl), Chat: chat.New(client, baseUrl), Conduit: conduit.New(client, baseUrl), + CCLS: ccls.New(client, baseUrl), EventSub: eventsub.New(client, baseUrl), } } diff --git a/api/ccls/ccls.go b/api/ccls/ccls.go new file mode 100644 index 0000000..8377444 --- /dev/null +++ b/api/ccls/ccls.go @@ -0,0 +1,18 @@ +package ccls + +import ( + "net/http" + "net/url" +) + +type CCLS struct { + client *http.Client + baseUrl *url.URL +} + +func New(client *http.Client, baseUrl *url.URL) *CCLS { + return &CCLS{ + client: client, + baseUrl: baseUrl, + } +} diff --git a/api/ccls/get_content_classification_labels.go b/api/ccls/get_content_classification_labels.go new file mode 100644 index 0000000..d9b35a7 --- /dev/null +++ b/api/ccls/get_content_classification_labels.go @@ -0,0 +1,60 @@ +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 +} diff --git a/api/ccls/models.go b/api/ccls/models.go new file mode 100644 index 0000000..1c15e70 --- /dev/null +++ b/api/ccls/models.go @@ -0,0 +1,12 @@ +package ccls + +// Content Classification Label +type ContentClassificationLabel string + +const ( + ContentClassificationLabelDrugsIntoxication ContentClassificationLabel = "DrugsIntoxication" + ContentClassificationLabelSexualThemes ContentClassificationLabel = "SexualThemes" + ContentClassificationLabelViolentGraphic ContentClassificationLabel = "ViolentGraphic" + ContentClassificationLabelGambling ContentClassificationLabel = "Gambling" + ContentClassificationLabelProfanityVulgarity ContentClassificationLabel = "ProfanityVulgarity" +) diff --git a/api/channels/get_channel_information.go b/api/channels/get_channel_information.go index 98bc8c9..f167536 100644 --- a/api/channels/get_channel_information.go +++ b/api/channels/get_channel_information.go @@ -7,7 +7,7 @@ import ( "net/url" "github.com/google/go-querystring/query" - "go.fifitido.net/twitch/api/types" + "go.fifitido.net/twitch/api/ccls" ) type GetChannelInformationParams struct { @@ -59,7 +59,7 @@ type ChannelInformation struct { Tags []string `json:"tags"` // The CCLs applied to the channel. - ContentClassficationLabels []types.CCL `json:"content_classification"` + ContentClassficationLabels []ccls.ContentClassificationLabel `json:"content_classification"` // Boolean flag indicating if the channel has branded content. IsBrandedContent bool `json:"is_branded_content"` diff --git a/api/channels/modify_channel_information.go b/api/channels/modify_channel_information.go index 1141650..e868655 100644 --- a/api/channels/modify_channel_information.go +++ b/api/channels/modify_channel_information.go @@ -7,7 +7,7 @@ import ( "net/http" "net/url" - "go.fifitido.net/twitch/api/types" + "go.fifitido.net/twitch/api/ccls" ) type ModifyChannelInformationRequest struct { @@ -44,7 +44,7 @@ type ModifyChannelInformationRequest struct { type ModifyContentClassificationLabel struct { // ID of the Content Classification Labels that must be added/removed from the channel. - ID types.CCL `json:"id"` + ID ccls.ContentClassificationLabel `json:"id"` // Boolean flag indicating whether the label should be enabled (true) or disabled for the channel. IsEnabled bool `json:"is_enabled"` diff --git a/api/types/types.go b/api/types/types.go index 7e51450..f625e80 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -46,17 +46,6 @@ type DateRange struct { EndedAt time.Time `json:"ended_at"` } -// Content Classification Label -type CCL string - -const ( - CCLDrugsIntoxication CCL = "DrugsIntoxication" - CCLSexualThemes CCL = "SexualThemes" - CCLViolentGraphic CCL = "ViolentGraphic" - CCLGambling CCL = "Gambling" - CCLProfanityVulgarity CCL = "ProfanityVulgarity" -) - // Sort Order type SortOrder string @@ -91,3 +80,36 @@ const ( AccentColorOrange AccentColor = "orange" AccentColorPurple AccentColor = "purple" ) + +type Locale string + +const ( + LocaleBgBg = "bg-BG" + LocaleCsCz = "cs-CZ" + LocaleDaDk = "da-DK" + LocaleDeDe = "de-DE" + LocaleElGr = "el-GR" + LocaleEnGb = "en-GB" + LocaleEnUs = "en-US" + LocaleEsEs = "es-ES" + LocaleEsMx = "es-MX" + LocaleFiFi = "fi-FI" + LocaleFrFr = "fr-FR" + LocaleHuHu = "hu-HU" + LocaleItIt = "it-IT" + LocaleJaJp = "ja-JP" + LocaleKoKr = "ko-KR" + LocaleNlNl = "nl-NL" + LocalePlPl = "pl-PL" + LocalePtBt = "pt-BT" + LocalePtPt = "pt-PT" + LocaleRoRo = "ro-RO" + LocaleRuRu = "ru-RU" + LocaleSkSk = "sk-SK" + LocaleSvSe = "sv-SE" + LocaleThTh = "th-TH" + LocaleTrTr = "tr-TR" + LocaleViVn = "vi-VN" + LocaleZhCn = "zh-CN" + LocaleZhTw = "zh-TW" +) diff --git a/ptr_types.go b/ptr_types.go index d6134d6..b879531 100644 --- a/ptr_types.go +++ b/ptr_types.go @@ -173,3 +173,14 @@ func ToConduitStatus(s *conduit.Status) conduit.Status { } return *s } + +func Locale(s types.Locale) *types.Locale { + return &s +} + +func ToLocale(s *types.Locale) types.Locale { + if s == nil { + return "" + } + return *s +}