package extensions import ( "context" "encoding/json" "fmt" "net/http" "net/url" "github.com/google/go-querystring/query" "go.fifitido.net/twitch/api/types" ) type GetExtensionLiveChannelsParams struct { // The ID of the extension to get. Returns the list of broadcasters that are live and that have installed or activated this extension. ExtensionID string `url:"extension_id"` // The maximum number of items to return per page in the response. The minimum page size is 1 item per page and the maximum is 100 items per page. The default is 20. First *int `url:"first,omitempty"` // The cursor used to get the next page of results. The pagination field in the response contains the cursor’s value. // Read More: https://dev.twitch.tv/docs/api/guide#pagination After *types.Cursor `url:"after,omitempty"` } type GetExtensionLiveChannelsResponse struct { // The list of broadcasters that are streaming live and that have installed or activated the extension. Data []ExtensionLiveChannel `json:"data"` // The cursor used to get the next page of results. The pagination field in the response contains the cursor’s value. // Read More: https://dev.twitch.tv/docs/api/guide#pagination Pagination types.Pagination `json:"pagination"` } type ExtensionLiveChannel struct { // The ID of the broadcaster that is streaming live and has installed or activated the extension. BroadcasterID string `json:"broadcaster_id"` // The broadcaster’s display name. BroadcasterName string `json:"broadcaster_name"` // The name of the category or game being streamed. GameName string `json:"game_name"` // The ID of the category or game being streamed. GameID string `json:"game_id"` // The title of the broadcaster’s stream. May be an empty string if not specified. Title string `json:"title"` } // Gets a list of broadcasters that are streaming live and have installed or activated the extension. // // It may take a few minutes for the list to include or remove broadcasters that have recently gone live or stopped broadcasting. // // Requires an app access token or user access token. func (c *Extensions) GetExtensionLiveChannels(ctx context.Context, params *GetExtensionLiveChannelsParams) (*GetExtensionLiveChannelsResponse, error) { v, _ := query.Values(params) endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/live", RawQuery: v.Encode()}) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) if err != nil { return nil, err } res, err := c.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 extension live channels (%d)", res.StatusCode) } var response GetExtensionLiveChannelsResponse if err := json.NewDecoder(res.Body).Decode(&response); err != nil { return nil, err } return &response, nil }