2024-03-03 18:34:26 -05:00
|
|
|
|
package users
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 18:34:26 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-03-03 18:34:26 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Removes the user from the broadcaster’s list of blocked users.
|
|
|
|
|
// The user ID in the OAuth token identifies the broadcaster who’s removing the block.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the user:manage:blocked_users scope.
|
|
|
|
|
func (u *Users) UnblockUser(ctx context.Context, targetUserID string) error {
|
2024-03-07 20:52:42 -05:00
|
|
|
|
v := url.Values{"target_user_id": {targetUserID}}
|
2024-03-03 18:34:26 -05:00
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(u.baseUrl, "users/blocks", v), nil)
|
2024-03-03 18:34:26 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := u.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return fmt.Errorf("failed to unblock user (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 18:34:26 -05:00
|
|
|
|
return nil
|
|
|
|
|
}
|