2024-02-27 22:13:57 -05:00
|
|
|
|
package channels
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"context"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"net/http"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
"net/url"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetChannelEditorsResponse struct {
|
|
|
|
|
// A list of users that are editors for the specified broadcaster. The list is empty if the broadcaster doesn’t have editors.
|
|
|
|
|
Data []ChannelEditor `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ChannelEditor struct {
|
|
|
|
|
// An ID that uniquely identifies a user with editor permissions.
|
|
|
|
|
UserID string `json:"user_id"`
|
|
|
|
|
|
|
|
|
|
// The user’s display name.
|
|
|
|
|
UserName string `json:"user_name"`
|
|
|
|
|
|
|
|
|
|
// The date and time, in RFC3339 format, when the user became one of the broadcaster’s editors.
|
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets the broadcaster’s list editors.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the channel:read:editors scope.
|
2024-02-27 23:03:40 -05:00
|
|
|
|
func (c *Channels) GetChannelEditors(ctx context.Context, broadcasterID string) (*GetChannelEditorsResponse, error) {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels/editors", RawQuery: "broadcaster_id=" + broadcasterID})
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
2024-02-27 22:13:57 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
res, err := c.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
2024-02-27 22:13:57 -05:00
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get channel editors (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 22:13:57 -05:00
|
|
|
|
var data GetChannelEditorsResponse
|
2024-02-27 23:03:40 -05:00
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|