go-twitch/api/moderation/get_unban_requests.go

124 lines
3.7 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"
"fmt"
"net/http"
"time"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types"
)
type GetUnbanRequestsParams struct {
// The ID of the broadcaster whose chat room the user is banned from chatting in.
BroadcasterID string `url:"broadcaster_id"`
// The ID of the broadcaster or a user that has permission to moderate the broadcasters chat room.
// This ID must match the user ID in the user access token.
ModeratorID string `url:"moderator_id"`
// Filter by a status. Accepted values:
// pending, approved, denied, acknowledged, or canceled
Status string `url:"status"`
// The ID used to filter what unban requests are returned.
UserID *string `url:"user_id"`
// Cursor used to get next page of results. Pagination object in response contains cursor value.
After *types.Cursor `url:"after"`
// The maximum number of items to return per page in response
First *int `url:"first"`
}
type GetUnbanRequestsResponse struct {
// A list that contains information about the channel's unban requests.
Data []GetUnbanRequestsResponseData `json:"data"`
// Contains information used to page through a list of results.
// The object is empty if there are no more pages left to page through.
Pagination types.Pagination `json:"pagination"`
}
type GetUnbanRequestsResponseData struct {
// Unban request ID.
ID string `json:"id"`
// User ID of broadcaster whose channel is receiving the unban request.
BroadcasterID string `json:"broadcaster_id"`
// The broadcaster's display name.
BroadcasterName string `json:"broadcaster_name"`
// The broadcaster's login name.
BroadcasterLogin string `json:"broadcaster_login"`
// User ID of moderator who approved/denied the request.
ModeratorID string `json:"moderator_id"`
// The moderator's login name
ModeratorLogin string `json:"moderator_login"`
// The moderator's display name
ModeratorName string `json:"moderator_name"`
// User ID of the requestor who is asking for an unban.
UserID string `json:"user_id"`
// The user's login name.
UserLogin string `json:"user_login"`
// The user's display name.
UserName string `json:"user_name"`
// Text of the request from the requesting user.
Text string `json:"text"`
// Status of the request. One of:
// pending, approved, denied, acknowledged, or canceled
Status string `json:"status"`
// Timestamp of when the unban request was created.
CreatedAt time.Time `json:"created_at"`
// Timestamp of when moderator/broadcaster approved or denied the request.
ResolvedAt *time.Time `json:"resolved_at"`
// Text input by the resolver (moderator) of the unban. request
ResolutionText string `json:"resolution_text"`
}
// Gets a list of unban requests for a broadcasters channel.
//
// Requires a user access token that includes the moderator:read:unban_requests or moderator:manage:unban_requests scope.
// Query parameter moderator_id must match the user_id in the user access token.
func (m *Moderation) GetUnbanRequests(ctx context.Context, params *GetUnbanRequestsParams) (*GetUnbanRequestsResponse, error) {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/unban_requests", v), nil)
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 unban requests (%d)", res.StatusCode)
}
var data GetUnbanRequestsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}