68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
|
package users
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"encoding/json"
|
|||
|
"net/http"
|
|||
|
"net/url"
|
|||
|
|
|||
|
"github.com/google/go-querystring/query"
|
|||
|
"go.fifitido.net/twitch/api/types"
|
|||
|
)
|
|||
|
|
|||
|
type GetUserBlockListParams struct {
|
|||
|
// The ID of the broadcaster whose list of blocked users you want to get.
|
|||
|
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.
|
|||
|
// The default is 20.
|
|||
|
First *int `url:"first,omitempty"`
|
|||
|
|
|||
|
// 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
|
|||
|
After *types.Cursor `url:"after,omitempty"`
|
|||
|
}
|
|||
|
|
|||
|
type GetUserBlockListResponse struct {
|
|||
|
// The list of blocked users. The list is in descending order by when the user was blocked.
|
|||
|
Data []struct {
|
|||
|
// An ID that identifies the blocked user.
|
|||
|
UserID string `json:"user_id"`
|
|||
|
|
|||
|
// The blocked user’s login name.
|
|||
|
UserLogin string `json:"user_login"`
|
|||
|
|
|||
|
// The blocked user’s display name.
|
|||
|
DisplayName string `json:"display_name"`
|
|||
|
} `json:"data"`
|
|||
|
}
|
|||
|
|
|||
|
// Gets the list of users that the broadcaster has blocked.
|
|||
|
// Read More: https://help.twitch.tv/s/article/how-to-manage-harassment-in-chat?language=en_US#BlockWhispersandMessagesfromStrangers
|
|||
|
//
|
|||
|
// Requires a user access token that includes the user:read:blocked_users scope.
|
|||
|
func (u *Users) GetUserBlockList(ctx context.Context, params *GetUserBlockListParams) (*GetUserBlockListResponse, error) {
|
|||
|
v, _ := query.Values(params)
|
|||
|
endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/blocks", RawQuery: v.Encode()})
|
|||
|
|
|||
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
res, err := u.client.Do(req)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
defer res.Body.Close()
|
|||
|
|
|||
|
var data GetUserBlockListResponse
|
|||
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
return &data, nil
|
|||
|
}
|