go-twitch/api/extensions/get_extensions.go

55 lines
1.6 KiB
Go
Raw 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 extensions
import (
"context"
"encoding/json"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
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 dont 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.
func (c *Extensions) GetExtensions(ctx context.Context, params *GetExtensionsParams) (*GetExtensionsResponse, error) {
v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data GetExtensionsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}