2024-02-27 22:13:57 -05:00
|
|
|
|
package channelpoints
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"context"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
"encoding/json"
|
|
|
|
|
"io"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UpdateRedemptionStatusParams struct {
|
|
|
|
|
// A list of IDs that identify the redemptions to update. To specify more than one ID, include this parameter for each redemption you want to update.
|
|
|
|
|
// For example, id=1234&id=5678. You may specify a maximum of 50 IDs.
|
|
|
|
|
IDs []string `url:"id"`
|
|
|
|
|
|
|
|
|
|
// The ID of the broadcaster that’s updating the redemption. This ID must match the user ID in the user access token.
|
|
|
|
|
BroadcasterID string `url:"broadcaster_id"`
|
|
|
|
|
|
|
|
|
|
// The ID that identifies the reward that’s been redeemed.
|
|
|
|
|
RewardID string `url:"reward_id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UpdateRedemptionStatusRequest struct {
|
|
|
|
|
// The status to set the redemption to. Possible values are:
|
|
|
|
|
//
|
|
|
|
|
// CANCELED, FULFILLED
|
|
|
|
|
//
|
|
|
|
|
// Setting the status to CANCELED refunds the user’s channel points.
|
|
|
|
|
Status RewardRedemptionStatus `json:"status"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UpdateRedemptionStatusResponse struct {
|
|
|
|
|
// The list contains the single redemption that you updated.
|
|
|
|
|
Data []CustomRewardRedemption `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Updates a redemption’s status. You may update a redemption only if its status is UNFULFILLED.
|
|
|
|
|
// The app used to create the reward is the only app that may update the redemption.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the channel:manage:redemptions scope.
|
2024-02-27 23:03:40 -05:00
|
|
|
|
func (c *ChannelPoints) UpdateRedemptionStatus(ctx context.Context, params *UpdateRedemptionStatusParams, body *UpdateRedemptionStatusRequest) (*UpdateRedemptionStatusResponse, error) {
|
|
|
|
|
v, _ := query.Values(body)
|
2024-02-27 22:13:57 -05:00
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards/redemptions", RawQuery: v.Encode()})
|
|
|
|
|
|
|
|
|
|
r, w := io.Pipe()
|
|
|
|
|
|
|
|
|
|
go func() {
|
2024-02-27 23:03:40 -05:00
|
|
|
|
if err := json.NewEncoder(w).Encode(body); err != nil {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
w.CloseWithError(err)
|
|
|
|
|
} else {
|
|
|
|
|
w.Close()
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
|
2024-02-27 22:13:57 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
res, err := c.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer res.Body.Close()
|
2024-02-27 22:13:57 -05:00
|
|
|
|
|
|
|
|
|
var data UpdateRedemptionStatusResponse
|
2024-02-27 23:03:40 -05:00
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|