go-twitch/api/channelpoints/delete_custom_reward.go

47 lines
1.3 KiB
Go
Raw Permalink 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 channelpoints
import (
"context"
"fmt"
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
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 rewards redemption status is UNFULFILLED at the time the reward is deleted, its redemption status is marked as FULFILLED.
//
// Requires a user access token that includes the channel:manage:redemptions scope.
func (c *ChannelPoints) DeleteCustomReward(ctx context.Context, params *DeleteCustomRewardParams) error {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), nil)
if err != nil {
return err
}
res, err := c.client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to delete custom reward (%d)", res.StatusCode)
}
return nil
}