82 lines
3.0 KiB
Go
82 lines
3.0 KiB
Go
|
package extensions
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"encoding/json"
|
|||
|
"net/http"
|
|||
|
"net/url"
|
|||
|
|
|||
|
"github.com/google/go-querystring/query"
|
|||
|
)
|
|||
|
|
|||
|
type GetExtensionConfigurationSegmentParams struct {
|
|||
|
// The ID of the broadcaster that installed the extension.
|
|||
|
// This parameter is required if you set the segment parameter to broadcaster or developer.
|
|||
|
// Do not specify this parameter if you set segment to global.
|
|||
|
BroadcasterID *string `url:"broadcaster_id,omitempty"`
|
|||
|
|
|||
|
// The ID of the extension that contains the configuration segment you want to get.
|
|||
|
ExtensionID string `url:"extension_id"`
|
|||
|
|
|||
|
// The type of configuration segment to get. Possible case-sensitive values are:
|
|||
|
//
|
|||
|
// broadcaster, developer, global
|
|||
|
//
|
|||
|
// You may specify one or more segments. To specify multiple segments, include the segment parameter for each segment to get.
|
|||
|
// For example, segment=broadcaster&segment=developer. Ignores duplicate segments.
|
|||
|
Segment []ConfigurationSegment `url:"segment"`
|
|||
|
}
|
|||
|
|
|||
|
type GetExtensionConfigurationSegmentResponse struct {
|
|||
|
// The list of requested configuration segments.
|
|||
|
// The list is returned in the same order that you specified the list of segments in the request.
|
|||
|
Data []ConfigurationSegmentData `json:"data"`
|
|||
|
}
|
|||
|
|
|||
|
type ConfigurationSegmentData struct {
|
|||
|
// The type of segment.
|
|||
|
Segment ConfigurationSegment `json:"segment"`
|
|||
|
|
|||
|
// The ID of the broadcaster that installed the extension.
|
|||
|
// The object includes this field only if the segment query parameter is set to developer or broadcaster.
|
|||
|
BroadcasterID *string `json:"broadcaster_id,omitempty"`
|
|||
|
|
|||
|
// The contents of the segment. This string may be a plain-text string or a string-encoded JSON object.
|
|||
|
Content string `json:"content"`
|
|||
|
|
|||
|
// The version number that identifies this definition of the segment’s data.
|
|||
|
Version string `json:"version"`
|
|||
|
}
|
|||
|
|
|||
|
// Gets the specified configuration segment from the specified extension.
|
|||
|
//
|
|||
|
// Rate Limits: You may retrieve each segment a maximum of 20 times per minute.
|
|||
|
//
|
|||
|
// 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) GetExtensionConfigurationSegment(ctx context.Context, params *GetExtensionConfigurationSegmentParams) (*GetExtensionConfigurationSegmentResponse, error) {
|
|||
|
v, _ := query.Values(params)
|
|||
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/configurations", 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 GetExtensionConfigurationSegmentResponse
|
|||
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
return &data, nil
|
|||
|
}
|