go-twitch/api/moderation/get_shield_mode_status.go

58 lines
1.7 KiB
Go
Raw Permalink 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"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
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)
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)
}
var data GetShieldModeStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}