64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package users
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
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) {
|
|
endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/extensions/list"})
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
|
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)
|
|
}
|
|
|
|
var data GetUserExtensionsResponse
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &data, nil
|
|
}
|