2024-03-03 15:14:59 -05:00
|
|
|
|
package moderation
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 15:14:59 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
|
"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 aren’t VIPs.
|
2024-03-05 22:29:23 -05:00
|
|
|
|
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.
|
2024-03-05 22:29:23 -05:00
|
|
|
|
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 cursor’s value.
|
|
|
|
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
2024-03-05 22:29:23 -05:00
|
|
|
|
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 user’s display name.
|
|
|
|
|
UserName string `json:"user_name"`
|
|
|
|
|
|
|
|
|
|
// The user’s login name.
|
|
|
|
|
UserLogin string `json:"user_login"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets a list of the broadcaster’s 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)
|
|
|
|
|
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/vips", RawQuery: v.Encode()})
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := m.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2024-03-07 19:41:05 -05:00
|
|
|
|
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
|
|
|
|
|
}
|