2024-03-02 22:45:59 -05:00
|
|
|
|
package extensions
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-02 22:45:59 -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-02 22:45:59 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetExtensionsParams struct {
|
|
|
|
|
// The ID of the extension to get.
|
|
|
|
|
ExtensionID string `url:"extension_id"`
|
|
|
|
|
|
|
|
|
|
// The version of the extension to get. If not specified, it returns the latest, released version.
|
|
|
|
|
// If you don’t have a released version, you must specify a version; otherwise, the list is empty.
|
|
|
|
|
ExtensionVersion *string `url:"extension_version,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetExtensionsResponse struct {
|
|
|
|
|
// A list that contains the specified extension.
|
|
|
|
|
Data []Extension `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets information about an extension.
|
|
|
|
|
//
|
|
|
|
|
// Requires a signed JSON Web Token (JWT) created by an EBS. For signing requirements,
|
|
|
|
|
// see Signing the JWT: https://dev.twitch.tv/docs/extensions/building/#signing-the-jwt
|
|
|
|
|
// The signed JWT must include the role, user_id, and exp fields
|
|
|
|
|
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
|
|
|
|
|
// The role field must be set to external.
|
2024-03-07 20:52:42 -05:00
|
|
|
|
func (e *Extensions) GetExtensions(ctx context.Context, params *GetExtensionsParams) (*GetExtensionsResponse, error) {
|
2024-03-02 22:45:59 -05:00
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions", v), nil)
|
2024-03-02 22:45:59 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
res, err := e.client.Do(req)
|
2024-03-02 22:45:59 -05:00
|
|
|
|
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 extensions (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 22:45:59 -05:00
|
|
|
|
var data GetExtensionsResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|