go-twitch/api/channels/modify_channel_information.go

80 lines
3.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package channels
import (
"context"
"encoding/json"
"io"
"net/http"
"net/url"
"go.fifitido.net/twitch/api/ccls"
)
type ModifyChannelInformationRequest struct {
// The ID of the game that the user plays. The game is not updated if the ID isnt a game ID that Twitch recognizes.
// To unset this field, use “0” or “” (an empty string).
GameID *string `json:"game_id,omitempty"`
// The users preferred language. Set the value to an ISO 639-1 two-letter language code (for example, en for English).
// Set to “other” if the users preferred language is not a Twitch supported language.
// The language isnt updated if the language code isnt a Twitch supported language.
Language *string `json:"language,omitempty"`
// The title of the users stream. You may not set this field to an empty string.
Title *string `json:"title,omitempty"`
// The number of seconds you want your broadcast buffered before streaming it live. The delay helps ensure fairness during competitive play.
// Only users with Partner status may set this field. The maximum delay is 900 seconds (15 minutes).
Delay *int `json:"delay,omitempty"`
// A list of channel-defined tags to apply to the channel. To remove all tags from the channel, set tags to an empty array.
// Tags help identify the content that the channel streams. Learn More: https://help.twitch.tv/s/article/guide-to-tags
//
// A channel may specify a maximum of 10 tags.
// Each tag is limited to a maximum of 25 characters and may not be an empty string or contain spaces or special characters.
// Tags are case insensitive. For readability, consider using camelCasing or PascalCasing.
Tags *[]string `json:"tags,omitempty"`
// List of labels that should be set as the Channels CCLs.
ContentClassificationLabels []ModifyContentClassificationLabel `json:"content_classification_labels,omitempty"`
// Boolean flag indicating if the channel has branded content.
IsBrandedContent *bool `json:"is_branded_content,omitempty"`
}
type ModifyContentClassificationLabel struct {
// ID of the Content Classification Labels that must be added/removed from the channel.
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"`
}
// Updates a channels properties.
//
// Requires a user access token that includes the channel:manage:broadcast scope.
func (c *Channels) ModifyChannelInformation(ctx context.Context, broadcasterID string, body *ModifyChannelInformationRequest) error {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels", RawQuery: "broadcaster_id=" + broadcasterID})
r, w := io.Pipe()
go func() {
if err := json.NewEncoder(w).Encode(body); err != nil {
w.CloseWithError(err)
} else {
w.Close()
}
}()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil {
return err
}
if _, err := c.client.Do(req); err != nil {
return err
}
return nil
}