go-twitch/api/extensions/set_extension_required_conf...

60 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 SetExtensionRequiredConfigurationRequest struct {
// The ID of the extension to update.
ExtensionID string `json:"extension_id"`
// The version of the extension to update.
ExtensionVersion string `json:"extension_version"`
// The required_configuration string to use with the extension.
RequiredConfiguration string `json:"required_configuration"`
}
// Updates the extensions required_configuration string.
// Use this endpoint if your extension requires the broadcaster to configure the extension before activating it
// (to require configuration, you must select Custom/My Own Service in Extension Capabilities).
// For more information,
// see Required Configurations: https://dev.twitch.tv/docs/extensions/building#required-configurations
// and Setting Required Configuration: https://dev.twitch.tv/docs/extensions/building#setting-required-configuration-with-the-configuration-service-optional
//
// 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).
// Set the role field to external and the user_id field to the ID of the user that owns the extension.
func (c *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broadcasterID string, body *SetExtensionRequiredConfigurationRequest) error {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/required_configuration", 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.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
}