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"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"net/http"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
|
|
|
|
|
"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 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 hasn’t 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.
|
2024-02-27 23:03:40 -05:00
|
|
|
|
func (c *ChannelPoints) GetCustomReward(ctx context.Context, params *GetCustomRewardParams) (*GetCustomRewardResponse, 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.MethodGet, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), nil)
|
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
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get custom rewards (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 22:13:57 -05:00
|
|
|
|
var data GetCustomRewardResponse
|
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
|
|
|
|
|
}
|