2024-02-27 22:13:57 -05:00
|
|
|
|
package channelpoints
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type DeleteCustomRewardParams struct {
|
|
|
|
|
// The ID of the broadcaster that created the custom reward. This ID must match the user ID found in the OAuth token.
|
|
|
|
|
BroadcasterID string `url:"broadcaster_id"`
|
|
|
|
|
|
|
|
|
|
// The ID of the custom reward to delete.
|
|
|
|
|
ID string `url:"id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Deletes a custom reward that the broadcaster created.
|
|
|
|
|
//
|
|
|
|
|
// The app used to create the reward is the only app that may delete it.
|
|
|
|
|
// If the reward’s redemption status is UNFULFILLED at the time the reward is deleted, its redemption status is marked as FULFILLED.
|
|
|
|
|
//
|
2024-02-27 23:03:40 -05:00
|
|
|
|
// Requires a user access token that includes the channel:manage:redemptions scope.
|
|
|
|
|
func (c *ChannelPoints) DeleteCustomReward(ctx context.Context, params *DeleteCustomRewardParams) error {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), nil)
|
2024-02-27 22:13:57 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
res, err := c.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
2024-02-27 22:13:57 -05:00
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return fmt.Errorf("failed to delete custom reward (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 22:13:57 -05:00
|
|
|
|
return nil
|
|
|
|
|
}
|