89 lines
3.2 KiB
Go
89 lines
3.2 KiB
Go
package channels
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"fmt"
|
||
"io"
|
||
"net/http"
|
||
"net/url"
|
||
|
||
"go.fifitido.net/twitch/api/ccls"
|
||
"go.fifitido.net/twitch/api/endpoint"
|
||
)
|
||
|
||
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 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 channel’s 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}}
|
||
|
||
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.Make(c.baseUrl, "channels", v), r)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
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
|
||
}
|