go-twitch/api/moderation/get_vips.go

86 lines
2.6 KiB
Go
Raw Permalink Normal View History

2024-03-03 15:14:59 -05:00
package moderation
import (
"context"
"encoding/json"
"fmt"
2024-03-03 15:14:59 -05:00
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
2024-03-03 15:14:59 -05:00
"go.fifitido.net/twitch/api/types"
)
type GetVIPsParams struct {
// Filters the list for specific VIPs.
// To specify more than one user, include the user_id parameter for each user to get. For example, &user_id=1234&user_id=5678.
// The maximum number of IDs that you may specify is 100.
// Ignores the ID of those users in the list that arent VIPs.
UserIDs []string `url:"user_id,omitempty"`
2024-03-03 15:14:59 -05:00
// The ID of the broadcaster whose list of VIPs you want to get. This ID must match the user ID in the access token.
BroadcasterID string `url:"broadcaster_id"`
// The maximum number of items to return per page in the response.
// The minimum page size is 1 item per page and the maximum is 100 items per page.
// The default is 20.
First *int `url:"first,omitempty"`
2024-03-03 15:14:59 -05:00
// The cursor used to get the next page of results.
// The Pagination object in the response contains the cursors value.
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
After *types.Cursor `url:"after,omitempty"`
2024-03-03 15:14:59 -05:00
}
type GetVIPsResponse struct {
// The list of VIPs. The list contains a single object that contains all the VIPs.
Data []GetVIPsResponseData `json:"data"`
// Contains information about the pagination in the response.
// The object is empty if there are no more pages of results.
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
Pagination types.Pagination `json:"pagination"`
}
type GetVIPsResponseData struct {
// An ID that uniquely identifies the VIP user.
UserID string `json:"user_id"`
// The users display name.
UserName string `json:"user_name"`
// The users login name.
UserLogin string `json:"user_login"`
}
// Gets a list of the broadcasters VIPs.
//
// Requires a user access token that includes the channel:read:vips scope.
// If your app also adds and removes VIP status, you can use the channel:manage:vips scope instead.
func (m *Moderation) GetVIPs(ctx context.Context, params GetVIPsParams) (*GetVIPsResponse, error) {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/vips", v), nil)
2024-03-03 15:14:59 -05:00
if err != nil {
return nil, err
}
res, err := m.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 VIPs (%d)", res.StatusCode)
}
2024-03-03 15:14:59 -05:00
var data GetVIPsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}