2024-02-27 22:13:57 -05:00
|
|
|
|
package channels
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"context"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
"encoding/json"
|
|
|
|
|
"io"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ModifyChannelInformationRequest struct {
|
|
|
|
|
// The ID of the game that the user plays. The game is not updated if the ID isn’t a game ID that Twitch recognizes.
|
|
|
|
|
// To unset this field, use “0” or “” (an empty string).
|
|
|
|
|
GameID *string `json:"game_id,omitempty"`
|
|
|
|
|
|
|
|
|
|
// The user’s preferred language. Set the value to an ISO 639-1 two-letter language code (for example, en for English).
|
|
|
|
|
// Set to “other” if the user’s preferred language is not a Twitch supported language.
|
|
|
|
|
// The language isn’t updated if the language code isn’t a Twitch supported language.
|
|
|
|
|
Language *string `json:"language,omitempty"`
|
|
|
|
|
|
|
|
|
|
// The title of the user’s 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 Channel’s 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 types.CCL `json:"id"`
|
|
|
|
|
|
|
|
|
|
// Boolean flag indicating whether the label should be enabled (true) or disabled for the channel.
|
|
|
|
|
IsEnabled bool `json:"is_enabled"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Updates a channel’s properties.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the channel:manage:broadcast scope.
|
2024-02-27 23:03:40 -05:00
|
|
|
|
func (c *Channels) ModifyChannelInformation(ctx context.Context, broadcasterID string, body *ModifyChannelInformationRequest) error {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels", RawQuery: "broadcaster_id=" + broadcasterID})
|
|
|
|
|
|
|
|
|
|
r, w := io.Pipe()
|
|
|
|
|
|
|
|
|
|
go func() {
|
2024-02-27 23:03:40 -05:00
|
|
|
|
if err := json.NewEncoder(w).Encode(body); err != nil {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
w.CloseWithError(err)
|
|
|
|
|
} else {
|
|
|
|
|
w.Close()
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2024-02-27 22:13:57 -05:00
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
if _, err := c.client.Do(req); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
2024-02-27 22:13:57 -05:00
|
|
|
|
}
|