go-twitch/api/channelpoints/get_custom_reward.go

65 lines
2.3 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 channelpoints
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
type GetCustomRewardParams struct {
// The ID of the broadcaster whose custom rewards you want to get. This ID must match the user ID found in the OAuth token.
BroadcasterID string `url:"broadcaster_id"`
// A list of IDs to filter the rewards by. To specify more than one ID, include this parameter for each reward you want to get.
// For example, id=1234&id=5678. You may specify a maximum of 50 IDs.
//
// Duplicate IDs are ignored. The response contains only the IDs that were found. If none of the IDs were found, the response is 404 Not Found.
IDs []string `url:"id,omitempty"`
// A Boolean value that determines whether the response contains only the custom rewards that the app may manage
// (the app is identified by the ID in the Client-Id header). Set to true to get only the custom rewards that the app may manage.
// The default is false.
OnlyManageableRewards *bool `url:"only_manageable_rewards,omitempty"`
}
type GetCustomRewardResponse struct {
// A list of custom rewards. The list is in ascending order by id. If the broadcaster hasnt created custom rewards, the list is empty.
Data []CustomReward `json:"data"`
}
// Gets a list of custom rewards that the specified broadcaster created.
//
// NOTE: A channel may offer a maximum of 50 rewards, which includes both enabled and disabled rewards.
//
// Requires a user access token that includes the channel:read:redemptions or channel:manage:redemptions scope.
func (c *ChannelPoints) GetCustomReward(ctx context.Context, params *GetCustomRewardParams) (*GetCustomRewardResponse, error) {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), nil)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get custom rewards (%d)", res.StatusCode)
}
var data GetCustomRewardResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}