go-twitch/api/extensions/set_extension_configuration...

66 lines
2.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 extensions
import (
"context"
"encoding/json"
"io"
"net/http"
"net/url"
)
type SetExtensionConfigurationSegmentRequest struct {
// The ID of the extension to update.
ExtensionID string `json:"extension_id"`
// The configuration segment to update.
Segment ConfigurationSegment `json:"segment"`
// The ID of the broadcaster that installed the extension.
// Include this field only if the segment is set to developer or broadcaster.
BroadcasterID *string `json:"broadcaster_id,omitempty"`
// The contents of the segment.
// This string may be a plain-text string or a string-encoded JSON object.
Content *string `json:"content,omitempty"`
// The version number that identifies this definition of the segments data.
// If not specified, the latest definition is updated.
Version *string `json:"version,omitempty"`
}
// Updates a configuration segment. The segment is limited to 5 KB. Extensions that are active on a channel do not receive the updated configuration.
//
// Rate Limits: You may update the configuration a maximum of 20 times per minute.
//
// Requires a signed JSON Web Token (JWT) created by an EBS. For signing requirements,
// see Signing the JWT: https://dev.twitch.tv/docs/extensions/building/#signing-the-jwt
// The signed JWT must include the role, user_id, and exp fields
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
// The role field must be set to external.
func (c *Extensions) SetExtensionConfigurationSegment(ctx context.Context, body *SetExtensionConfigurationSegmentRequest) error {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/configurations"})
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.MethodPut, endpoint.String(), r)
if err != nil {
return err
}
res, err := c.client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
return nil
}