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 GetModeratedChannelsParams struct {
|
|
|
|
|
// A user’s ID. Returns the list of channels that this user has moderator privileges in. This ID must match the user ID in the user OAuth token
|
|
|
|
|
UserID string `url:"user_id"`
|
|
|
|
|
|
|
|
|
|
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
2024-03-05 22:29:23 -05:00
|
|
|
|
After *types.Cursor `url:"after,omitempty"`
|
2024-03-03 15:14:59 -05:00
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetModeratedChannelsResponse struct {
|
|
|
|
|
// The list of channels that the user has moderator privileges in.
|
|
|
|
|
Data []GetModeratedChannelsResponseData `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 GetModeratedChannelsResponseData struct {
|
|
|
|
|
// An ID that uniquely identifies the channel this user can moderate.
|
|
|
|
|
BroadcasterID string `json:"broadcaster_id"`
|
|
|
|
|
|
|
|
|
|
// The channel’s login name.
|
|
|
|
|
BroadcasterLogin string `json:"broadcaster_login"`
|
|
|
|
|
|
|
|
|
|
// The channels’ display name.
|
|
|
|
|
BroadcasterName string `json:"broadcaster_name"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets a list of channels that the specified user has moderator privileges in.
|
|
|
|
|
//
|
|
|
|
|
// Query parameter user_id must match the user ID in the User-Access token
|
|
|
|
|
// Requires OAuth Scope: user:read:moderated_channels
|
|
|
|
|
func (m *Moderation) GetModeratedChannels(ctx context.Context, params *GetModeratedChannelsParams) (*GetModeratedChannelsResponse, error) {
|
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/channels", 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
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get moderated channels (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 15:14:59 -05:00
|
|
|
|
var data GetModeratedChannelsResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|