go-twitch/api/users/get_user_extensions.go

63 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-03-03 18:34:26 -05:00
package users
import (
"context"
"encoding/json"
"fmt"
2024-03-03 18:34:26 -05:00
"net/http"
"go.fifitido.net/twitch/api/endpoint"
2024-03-03 18:34:26 -05:00
)
type GetUserExtensionsResponse struct {
// The list of extensions that the user has installed.
Data []struct {
// An ID that identifies the extension.
ID string `json:"id"`
// The extension's version.
Version string `json:"version"`
// The extension's name.
Name string `json:"name"`
// A Boolean value that determines whether the extension is configured and can be activated. Is true if the extension is configured and can be activated.
CanActivate bool `json:"can_activate"`
// The extension types that you can activate for this extension. Possible values are:
//
// component, mobile, overlay, panel
Type []string `json:"type"`
} `json:"data"`
}
// Gets a list of all extensions (both active and inactive) that the broadcaster has installed.
// The user ID in the access token identifies the broadcaster.
//
// Requires a user access token that includes the user:read:broadcast or user:edit:broadcast scope.
// To include inactive extensions, you must include the user:edit:broadcast scope.
func (u *Users) GetUserExtensions(ctx context.Context) (*GetUserExtensionsResponse, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(u.baseUrl, "users/extensions/list"), nil)
2024-03-03 18:34:26 -05:00
if err != nil {
return nil, err
}
res, err := u.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 user extensions (%d)", res.StatusCode)
}
2024-03-03 18:34:26 -05:00
var data GetUserExtensionsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}