go-twitch/api/moderation/get_moderators.go

83 lines
2.8 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 moderation
import (
"context"
"encoding/json"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/types"
)
type GetModeratorsParams struct {
// The ID of the broadcaster whose list of moderators you want to get. This ID must match the user ID in the access token.
BroadcasterID string `url:"broadcaster_id"`
// A list of user IDs used to filter the results.
// To specify more than one ID, include this parameter for each moderator you want to get.
// For example, user_id=1234&user_id=5678.
// You may specify a maximum of 100 IDs.
//
// The returned list includes only the users from the list who are moderators in the broadcasters channel.
// The list is returned in the same order as you specified the IDs.
UserID []string `url:"user_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"`
// 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"`
}
type GetModeratorsResponse struct {
// The list of moderators. The list contains a single object that contains all the moderators.
Data []GetModeratorsResponseData `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 GetModeratorsResponseData struct {
// The ID of the user that has permission to moderate the broadcasters channel.
UserID string `json:"user_id"`
// The users login name.
UserLogin string `json:"user_login"`
// The users display name.
UserName string `json:"user_name"`
}
// Gets all users allowed to moderate the broadcasters chat room.
//
// Requires a user access token that includes the moderation:read scope.
// If your app also adds and removes moderators, you can use the channel:manage:moderators scope instead.
func (m *Moderation) GetModerators(ctx context.Context, params *GetModeratorsParams) (*GetModeratorsResponse, error) {
v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", 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()
var data GetModeratorsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}