2024-03-03 18:34:26 -05:00
|
|
|
|
package users
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 18:34:26 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-03-03 18:34:26 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(u.baseUrl, "users/extensions", v), 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()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get user active extensions (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 18:34:26 -05:00
|
|
|
|
var data GetUserActiveExtensionsResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|