go-twitch/api/channels/modify_channel_information.go

89 lines
3.2 KiB
Go
Raw Normal View History

2024-02-27 22:13:57 -05:00
package channels
import (
"context"
2024-02-27 22:13:57 -05:00
"encoding/json"
"fmt"
2024-02-27 22:13:57 -05:00
"io"
"net/http"
"net/url"
"go.fifitido.net/twitch/api/ccls"
"go.fifitido.net/twitch/api/endpoint"
2024-02-27 22:13:57 -05:00
)
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"`
2024-02-27 22:13:57 -05:00
// 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 {
v := url.Values{"broadcaster_id": {broadcasterID}}
2024-02-27 22:13:57 -05:00
r, w := io.Pipe()
go func() {
if err := json.NewEncoder(w).Encode(body); err != nil {
2024-02-27 22:13:57 -05:00
w.CloseWithError(err)
} else {
w.Close()
}
}()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "channels", v), r)
if err != nil {
return err
}
2024-02-27 22:13:57 -05:00
res, err := c.client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to modify channel information (%d)", res.StatusCode)
}
return nil
2024-02-27 22:13:57 -05:00
}