go-twitch/api/users/get_user_active_extensions.go

58 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package users
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
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 dont 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)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(u.baseUrl, "users/extensions", v), 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 active extensions (%d)", res.StatusCode)
}
var data GetUserActiveExtensionsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}