114 lines
4.2 KiB
Go
114 lines
4.2 KiB
Go
|
package channelpoints
|
|||
|
|
|||
|
import (
|
|||
|
"encoding/json"
|
|||
|
"io"
|
|||
|
"net/http"
|
|||
|
"net/url"
|
|||
|
|
|||
|
"github.com/google/go-querystring/query"
|
|||
|
)
|
|||
|
|
|||
|
type UpdateCustomRewardParams struct {
|
|||
|
// The ID of the broadcaster that’s updating the reward. This ID must match the user ID found in the OAuth token.
|
|||
|
BroadcasterID string `url:"broadcaster_id"`
|
|||
|
|
|||
|
// The ID of the reward to update.
|
|||
|
ID string `url:"id"`
|
|||
|
}
|
|||
|
|
|||
|
type UpdateCustomRewardRequest struct {
|
|||
|
// The custom reward’s title. The title may contain a maximum of 45 characters and it must be unique amongst all of the broadcaster’s custom rewards.
|
|||
|
Title *string `json:"title"`
|
|||
|
|
|||
|
// The cost of the reward, in Channel Points.
|
|||
|
// The minimum is 1 point.
|
|||
|
Cost *int64 `json:"cost"`
|
|||
|
|
|||
|
// The prompt shown to the viewer when they redeem the reward.
|
|||
|
// Specify a prompt if is_user_input_required is true.
|
|||
|
// The prompt is limited to a maximum of 200 characters.
|
|||
|
Prompt *string `json:"prompt"`
|
|||
|
|
|||
|
// A Boolean value that determines whether the reward is enabled. Viewers see only enabled rewards.
|
|||
|
// The default is true.
|
|||
|
IsEnabled *bool `json:"is_enabled"`
|
|||
|
|
|||
|
// The background color to use for the reward. Specify the color using Hex format (for example, #9147FF).
|
|||
|
BackgroundColor *string `json:"background_color"`
|
|||
|
|
|||
|
// A Boolean value that determines whether the user needs to enter information when redeeming the reward. See the prompt field.
|
|||
|
// The default is false.
|
|||
|
IsUserInputRequired *bool `json:"is_user_input_required"`
|
|||
|
|
|||
|
// A Boolean value that determines whether to limit the maximum number of redemptions allowed per live stream (see the max_per_stream field).
|
|||
|
// The default is false.
|
|||
|
IsMaxPerStreamEnabled *bool `json:"is_max_per_stream_enabled"`
|
|||
|
|
|||
|
// The maximum number of redemptions allowed per live stream. Applied only if is_max_per_stream_enabled is true.
|
|||
|
// The minimum value is 1.
|
|||
|
MaxPerStream *int `json:"max_per_stream"`
|
|||
|
|
|||
|
// A Boolean value that determines whether to limit the maximum number of redemptions allowed per user per stream (see the max_per_user_per_stream field).
|
|||
|
// The default is false.
|
|||
|
IsMaxPerUserPerStreamEnabled *bool `json:"is_max_per_user_per_stream_enabled"`
|
|||
|
|
|||
|
// The maximum number of redemptions allowed per user per stream. Applied only if is_max_per_user_per_stream_enabled is true.
|
|||
|
// The minimum value is 1.
|
|||
|
MaxPerUserPerStream *int `json:"max_per_user_per_stream"`
|
|||
|
|
|||
|
// A Boolean value that determines whether to apply a cooldown period between redemptions (see the global_cooldown_seconds field for the duration of the cooldown period).
|
|||
|
// The default is false.
|
|||
|
IsGlobalCooldownEnabled *bool `json:"is_global_cooldown_enabled"`
|
|||
|
|
|||
|
// The cooldown period, in seconds. Applied only if the is_global_cooldown_enabled field is true.
|
|||
|
// The minimum value is 1; however, the minimum value is 60 for it to be shown in the Twitch UX.
|
|||
|
GlobalCooldownSeconds *int `json:"global_cooldown_seconds"`
|
|||
|
|
|||
|
// A Boolean value that determines whether redemptions should be set to FULFILLED status immediately when a reward is redeemed.
|
|||
|
// If false, status is set to UNFULFILLED and follows the normal request queue process.
|
|||
|
// The default is false.
|
|||
|
ShouldRedemptionsSkipRequestQueue *bool `json:"should_redemptions_skip_request_queue"`
|
|||
|
}
|
|||
|
|
|||
|
type UpdateCustomRewardResponse struct {
|
|||
|
// The list contains the single reward that you updated.
|
|||
|
Data []CustomReward `json:"data"`
|
|||
|
}
|
|||
|
|
|||
|
// Updates a custom reward. The app used to create the reward is the only app that may update the reward.
|
|||
|
//
|
|||
|
// Requires a user access token that includes the channel:manage:redemptions scope.
|
|||
|
func (c *ChannelPoints) UpdateCustomReward(params *UpdateCustomRewardParams, req *UpdateCustomRewardRequest) (*UpdateCustomRewardResponse, error) {
|
|||
|
v, _ := query.Values(req)
|
|||
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards", RawQuery: v.Encode()})
|
|||
|
|
|||
|
r, w := io.Pipe()
|
|||
|
|
|||
|
go func() {
|
|||
|
if err := json.NewEncoder(w).Encode(req); err != nil {
|
|||
|
w.CloseWithError(err)
|
|||
|
} else {
|
|||
|
w.Close()
|
|||
|
}
|
|||
|
}()
|
|||
|
|
|||
|
resp, err := c.client.Do(&http.Request{
|
|||
|
Method: http.MethodPatch,
|
|||
|
URL: endpoint,
|
|||
|
Body: r,
|
|||
|
})
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
defer resp.Body.Close()
|
|||
|
|
|||
|
var data UpdateCustomRewardResponse
|
|||
|
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
return &data, nil
|
|||
|
}
|