53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package users
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"net/http"
|
||
"net/url"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
)
|
||
|
||
type GetUserActiveExtensionsParams struct {
|
||
// The ID of the broadcaster whose active extensions you want to get.
|
||
//
|
||
// This parameter is required if you specify an app access token and is optional if you specify a user access token.
|
||
// If you specify a user access token and don’t specify this parameter, the API uses the user ID from the access token.
|
||
UserID string `url:"user_id,omitempty"`
|
||
}
|
||
|
||
type GetUserActiveExtensionsResponse struct {
|
||
// The active extensions that the broadcaster has installed.
|
||
Data []ActiveExtension `json:"data"`
|
||
}
|
||
|
||
// Gets the active extensions that the broadcaster has installed for each configuration.
|
||
//
|
||
// NOTE: To include extensions that you have under development,
|
||
// you must specify a user access token that includes the user:read:broadcast or user:edit:broadcast scope.
|
||
//
|
||
// Requires an app access token or user access token.
|
||
func (u *Users) GetUserActiveExtensions(ctx context.Context, params *GetUserActiveExtensionsParams) (*GetUserActiveExtensionsResponse, error) {
|
||
v, _ := query.Values(params)
|
||
endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/extensions", RawQuery: v.Encode()})
|
||
|
||
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()
|
||
|
||
var data GetUserActiveExtensionsResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|