go-twitch/api/moderation/get_shield_mode_status.go

58 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-03-03 15:14:59 -05:00
package moderation
import (
"context"
"encoding/json"
"fmt"
2024-03-03 15:14:59 -05:00
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
2024-03-03 15:14:59 -05:00
)
type GetShieldModeStatusParams struct {
// The ID of the broadcaster whose Shield Mode activation status you want to get.
BroadcasterID string `url:"broadcaster_id"`
// The ID of the broadcaster or a user that is one of the broadcasters moderators. This ID must match the user ID in the access token.
ModeratorID string `url:"moderator_id"`
}
type GetShieldModeStatusResponse struct {
// A list that contains a single object with the broadcasters Shield Mode status.
Data []ShieldModeStatus `json:"data"`
}
// Gets the broadcasters Shield Mode activation status.
//
// To receive notification when the broadcaster activates and deactivates Shield Mode,
// subscribe to the channel.shield_mode.begin and channel.shield_mode.end subscription types.
//
// Requires a user access token that includes the moderator:read:shield_mode or moderator:manage:shield_mode scope.
func (m *Moderation) GetShieldModeStatus(ctx context.Context, params *GetShieldModeStatusParams) (*GetShieldModeStatusResponse, error) {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/shield_mode", v), nil)
2024-03-03 15:14:59 -05:00
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 shield mode status (%d)", res.StatusCode)
}
2024-03-03 15:14:59 -05:00
var data GetShieldModeStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}