go-twitch/api/moderation/get_shield_mode_status.go

59 lines
1.8 KiB
Go
Raw 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"
"net/url"
"github.com/google/go-querystring/query"
)
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)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/shield_mode", 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()
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
}