Fix optional query params by adding ,omitempty and fix create polls to use request body
This commit is contained in:
parent
39f46618ab
commit
4803b82eba
|
@ -18,7 +18,7 @@ type GetChannelFollowersParams struct {
|
||||||
//
|
//
|
||||||
// Using this parameter requires both a user access token with the moderator:read:followers scope and the user ID
|
// Using this parameter requires both a user access token with the moderator:read:followers scope and the user ID
|
||||||
// in the access token match the broadcaster_id or be the user ID for a moderator of the specified broadcaster.
|
// in the access token match the broadcaster_id or be the user ID for a moderator of the specified broadcaster.
|
||||||
UserID *string `url:"user_id"`
|
UserID *string `url:"user_id,omitempty"`
|
||||||
|
|
||||||
// The broadcaster’s ID. Returns the list of users that follow this broadcaster.
|
// The broadcaster’s ID. Returns the list of users that follow this broadcaster.
|
||||||
BroadcasterID string `url:"broadcaster_id"`
|
BroadcasterID string `url:"broadcaster_id"`
|
||||||
|
|
|
@ -17,7 +17,7 @@ type CreateExtensionSecretParams struct {
|
||||||
// The delay should provide enough time for instances of the extension to gracefully switch over to the new secret.
|
// The delay should provide enough time for instances of the extension to gracefully switch over to the new secret.
|
||||||
// The minimum delay is 300 seconds (5 minutes).
|
// The minimum delay is 300 seconds (5 minutes).
|
||||||
// The default is 300 seconds.
|
// The default is 300 seconds.
|
||||||
Delay *int `url:"delay"`
|
Delay *int `url:"delay,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateExtensionSecretResponse struct {
|
type CreateExtensionSecretResponse struct {
|
||||||
|
|
|
@ -27,7 +27,7 @@ type DeleteGuestStarSlotParams struct {
|
||||||
SlotID int `url:"slot_id"`
|
SlotID int `url:"slot_id"`
|
||||||
|
|
||||||
// Flag signaling that the guest should be reinvited to the session, sending them back to the invite queue.
|
// Flag signaling that the guest should be reinvited to the session, sending them back to the invite queue.
|
||||||
ShouldReinviteGuest *bool `url:"should_reinvite_guest"`
|
ShouldReinviteGuest *bool `url:"should_reinvite_guest,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows a caller to remove a slot assignment from a user participating in an active Guest Star session. This revokes their access to the session immediately and disables their access to publish or subscribe to media within the session.
|
// Allows a caller to remove a slot assignment from a user participating in an active Guest Star session. This revokes their access to the session immediately and disables their access to publish or subscribe to media within the session.
|
||||||
|
|
|
@ -24,18 +24,18 @@ type UpdateGuestStarSlotSettingsParams struct {
|
||||||
|
|
||||||
// Flag indicating whether the slot is allowed to share their audio with the rest of the session.
|
// Flag indicating whether the slot is allowed to share their audio with the rest of the session.
|
||||||
// If false, the slot will be muted in any views containing the slot.
|
// If false, the slot will be muted in any views containing the slot.
|
||||||
IsAudioEnabled *bool `url:"is_audio_enabled"`
|
IsAudioEnabled *bool `url:"is_audio_enabled,omitempty"`
|
||||||
|
|
||||||
// Flag indicating whether the slot is allowed to share their video with the rest of the session.
|
// Flag indicating whether the slot is allowed to share their video with the rest of the session.
|
||||||
// If false, the slot will have no video shared in any views containing the slot.
|
// If false, the slot will have no video shared in any views containing the slot.
|
||||||
IsVideoEnabled *bool `url:"is_video_enabled"`
|
IsVideoEnabled *bool `url:"is_video_enabled,omitempty"`
|
||||||
|
|
||||||
// Flag indicating whether the user assigned to this slot is visible/can be heard from any public subscriptions.
|
// Flag indicating whether the user assigned to this slot is visible/can be heard from any public subscriptions.
|
||||||
// Generally, this determines whether or not the slot is enabled in any broadcasting software integrations.
|
// Generally, this determines whether or not the slot is enabled in any broadcasting software integrations.
|
||||||
IsLive *bool `url:"is_live"`
|
IsLive *bool `url:"is_live,omitempty"`
|
||||||
|
|
||||||
// Value from 0-100 that controls the audio volume for shared views containing the slot.
|
// Value from 0-100 that controls the audio volume for shared views containing the slot.
|
||||||
Volume *int `url:"volume"`
|
Volume *int `url:"volume,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows a user to update slot settings for a particular guest within a Guest Star session, such as allowing the user to share audio or video within the call as a host. These settings will be broadcasted to all subscribers which control their view of the guest in that slot. One or more of the optional parameters to this API can be specified at any time.
|
// Allows a user to update slot settings for a particular guest within a Guest Star session, such as allowing the user to share audio or video within the call as a host. These settings will be broadcasted to all subscribers which control their view of the guest in that slot. One or more of the optional parameters to this API can be specified at any time.
|
||||||
|
|
|
@ -19,11 +19,11 @@ type GetHypeTrainEventsParams struct {
|
||||||
// The maximum number of items to return per page in the response.
|
// The maximum number of items to return per page in the response.
|
||||||
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
||||||
// The default is 1.
|
// The default is 1.
|
||||||
First *int `url:"first"`
|
First *int `url:"first,omitempty"`
|
||||||
|
|
||||||
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
||||||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||||||
After *types.Cursor `url:"after"`
|
After *types.Cursor `url:"after,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
|
|
|
@ -22,20 +22,20 @@ type GetBannedUsersParams struct {
|
||||||
//
|
//
|
||||||
// The returned list includes only those users that were banned or put in a timeout.
|
// The returned list includes only those users that were banned or put in a timeout.
|
||||||
// The list is returned in the same order that you specified the IDs.
|
// The list is returned in the same order that you specified the IDs.
|
||||||
UserID []string `url:"user_id"`
|
UserID []string `url:"user_id,omitempty"`
|
||||||
|
|
||||||
// The maximum number of items to return per page in the response.
|
// The maximum number of items to return per page in the response.
|
||||||
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
||||||
// The default is 20.
|
// The default is 20.
|
||||||
First *int `url:"first"`
|
First *int `url:"first,omitempty"`
|
||||||
|
|
||||||
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
||||||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||||||
After *types.Cursor `url:"after"`
|
After *types.Cursor `url:"after,omitempty"`
|
||||||
|
|
||||||
// The cursor used to get the previous page of results. The Pagination object in the response contains the cursor’s value.
|
// The cursor used to get the previous page of results. The Pagination object in the response contains the cursor’s value.
|
||||||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||||||
Before *types.Cursor `url:"before"`
|
Before *types.Cursor `url:"before,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetBannedUsersResponse struct {
|
type GetBannedUsersResponse struct {
|
||||||
|
|
|
@ -21,10 +21,10 @@ type GetBlockedTermsParams struct {
|
||||||
// The maximum number of items to return per page in the response.
|
// The maximum number of items to return per page in the response.
|
||||||
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
||||||
// The default is 20.
|
// The default is 20.
|
||||||
First *int `url:"first"`
|
First *int `url:"first,omitempty"`
|
||||||
|
|
||||||
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
||||||
After *types.Cursor `url:"after"`
|
After *types.Cursor `url:"after,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetBlockedTermsResponse struct {
|
type GetBlockedTermsResponse struct {
|
||||||
|
|
|
@ -15,12 +15,12 @@ type GetModeratedChannelsParams struct {
|
||||||
UserID string `url:"user_id"`
|
UserID string `url:"user_id"`
|
||||||
|
|
||||||
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
||||||
After *types.Cursor `url:"after"`
|
After *types.Cursor `url:"after,omitempty"`
|
||||||
|
|
||||||
// The maximum number of items to return per page in the response.
|
// The maximum number of items to return per page in the response.
|
||||||
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
||||||
// The default is 20.
|
// The default is 20.
|
||||||
First *int `url:"first"`
|
First *int `url:"first,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetModeratedChannelsResponse struct {
|
type GetModeratedChannelsResponse struct {
|
||||||
|
|
|
@ -21,16 +21,16 @@ type GetModeratorsParams struct {
|
||||||
//
|
//
|
||||||
// The returned list includes only the users from the list who are moderators in the broadcaster’s channel.
|
// The returned list includes only the users from the list who are moderators in the broadcaster’s channel.
|
||||||
// The list is returned in the same order as you specified the IDs.
|
// The list is returned in the same order as you specified the IDs.
|
||||||
UserID []string `url:"user_id"`
|
UserID []string `url:"user_id,omitempty"`
|
||||||
|
|
||||||
// The maximum number of items to return per page in the response.
|
// The maximum number of items to return per page in the response.
|
||||||
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
||||||
// The default is 20.
|
// The default is 20.
|
||||||
First *int `url:"first"`
|
First *int `url:"first,omitempty"`
|
||||||
|
|
||||||
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
||||||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||||||
After *types.Cursor `url:"after"`
|
After *types.Cursor `url:"after,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetModeratorsResponse struct {
|
type GetModeratorsResponse struct {
|
||||||
|
|
|
@ -15,7 +15,7 @@ type GetVIPsParams struct {
|
||||||
// To specify more than one user, include the user_id parameter for each user to get. For example, &user_id=1234&user_id=5678.
|
// To specify more than one user, include the user_id parameter for each user to get. For example, &user_id=1234&user_id=5678.
|
||||||
// The maximum number of IDs that you may specify is 100.
|
// The maximum number of IDs that you may specify is 100.
|
||||||
// Ignores the ID of those users in the list that aren’t VIPs.
|
// Ignores the ID of those users in the list that aren’t VIPs.
|
||||||
UserIDs []string `url:"user_id"`
|
UserIDs []string `url:"user_id,omitempty"`
|
||||||
|
|
||||||
// The ID of the broadcaster whose list of VIPs you want to get. This ID must match the user ID in the access token.
|
// The ID of the broadcaster whose list of VIPs you want to get. This ID must match the user ID in the access token.
|
||||||
BroadcasterID string `url:"broadcaster_id"`
|
BroadcasterID string `url:"broadcaster_id"`
|
||||||
|
@ -23,12 +23,12 @@ type GetVIPsParams struct {
|
||||||
// The maximum number of items to return per page in the response.
|
// The maximum number of items to return per page in the response.
|
||||||
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
||||||
// The default is 20.
|
// The default is 20.
|
||||||
First *int `url:"first"`
|
First *int `url:"first,omitempty"`
|
||||||
|
|
||||||
// The cursor used to get the next page of results.
|
// The cursor used to get the next page of results.
|
||||||
// The Pagination object in the response contains the cursor’s value.
|
// The Pagination object in the response contains the cursor’s value.
|
||||||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||||||
After *types.Cursor `url:"after"`
|
After *types.Cursor `url:"after,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetVIPsResponse struct {
|
type GetVIPsResponse struct {
|
||||||
|
|
|
@ -3,39 +3,38 @@ package polls
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreatePollParams struct {
|
type CreatePollRequest struct {
|
||||||
|
|
||||||
// The ID of the broadcaster that’s running the poll. This ID must match the user ID in the user access token.
|
// The ID of the broadcaster that’s running the poll. This ID must match the user ID in the user access token.
|
||||||
BroadcasterID string `url:"broadcaster_id"`
|
BroadcasterID string `json:"broadcaster_id"`
|
||||||
|
|
||||||
// The question that viewers will vote on. For example, What game should I play next? The question may contain a maximum of 60 characters.
|
// The question that viewers will vote on. For example, What game should I play next? The question may contain a maximum of 60 characters.
|
||||||
Title string `url:"title"`
|
Title string `json:"title"`
|
||||||
|
|
||||||
// A list of choices that viewers may choose from. The list must contain a minimum of 2 choices and up to a maximum of 5 choices.
|
// A list of choices that viewers may choose from. The list must contain a minimum of 2 choices and up to a maximum of 5 choices.
|
||||||
Choices []CreateChoice `url:"choices"`
|
Choices []CreateChoice `json:"choices"`
|
||||||
|
|
||||||
// The length of time (in seconds) that the poll will run for. The minimum is 15 seconds and the maximum is 1800 seconds (30 minutes).
|
// The length of time (in seconds) that the poll will run for. The minimum is 15 seconds and the maximum is 1800 seconds (30 minutes).
|
||||||
Duration int `url:"duration"`
|
Duration int `json:"duration"`
|
||||||
|
|
||||||
// A Boolean value that indicates whether viewers may cast additional votes using Channel Points.
|
// A Boolean value that indicates whether viewers may cast additional votes using Channel Points.
|
||||||
// If true, the viewer may cast more than one vote but each additional vote costs the number of Channel Points specified in channel_points_per_vote.
|
// If true, the viewer may cast more than one vote but each additional vote costs the number of Channel Points specified in channel_points_per_vote.
|
||||||
// The default is false (viewers may cast only one vote). For information about Channel Points, see Channel Points Guide.
|
// The default is false (viewers may cast only one vote). For information about Channel Points, see Channel Points Guide.
|
||||||
ChannelPointsVotingEnabled bool `url:"channel_points_voting_enabled"`
|
ChannelPointsVotingEnabled bool `json:"channel_points_voting_enabled"`
|
||||||
|
|
||||||
// The number of points that the viewer must spend to cast one additional vote. The minimum is 1 and the maximum is 1000000.
|
// The number of points that the viewer must spend to cast one additional vote. The minimum is 1 and the maximum is 1000000.
|
||||||
// Set only if ChannelPointsVotingEnabled is true.
|
// Set only if ChannelPointsVotingEnabled is true.
|
||||||
ChannelPointsPerVote int `url:"channel_points_per_vote"`
|
ChannelPointsPerVote int `json:"channel_points_per_vote"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateChoice struct {
|
type CreateChoice struct {
|
||||||
// One of the choices the viewer may select. The choice may contain a maximum of 25 characters.
|
// One of the choices the viewer may select. The choice may contain a maximum of 25 characters.
|
||||||
Title string `url:"title"`
|
Title string `json:"title"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreatePollResponse struct {
|
type CreatePollResponse struct {
|
||||||
|
@ -48,11 +47,20 @@ type CreatePollResponse struct {
|
||||||
// The poll begins as soon as it’s created. You may run only one poll at a time.
|
// The poll begins as soon as it’s created. You may run only one poll at a time.
|
||||||
//
|
//
|
||||||
// Requires a user access token that includes the channel:manage:polls scope.
|
// Requires a user access token that includes the channel:manage:polls scope.
|
||||||
func (p *Polls) CreatePoll(ctx context.Context, params *CreatePollParams) (*CreatePollResponse, error) {
|
func (p *Polls) CreatePoll(ctx context.Context, body *CreatePollRequest) (*CreatePollResponse, error) {
|
||||||
v, _ := query.Values(params)
|
endpoint := p.baseUrl.ResolveReference(&url.URL{Path: "polls"})
|
||||||
endpoint := p.baseUrl.ResolveReference(&url.URL{Path: "polls", RawQuery: v.Encode()})
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
|
r, w := io.Pipe()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := json.NewEncoder(w).Encode(body); err != nil {
|
||||||
|
w.CloseWithError(err)
|
||||||
|
} else {
|
||||||
|
w.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,16 @@ type GetPollsParams struct {
|
||||||
// A list of IDs that identify the polls to return.
|
// A list of IDs that identify the polls to return.
|
||||||
// To specify more than one ID, include this parameter for each poll you want to get. For example, id=1234&id=5678.
|
// To specify more than one ID, include this parameter for each poll you want to get. For example, id=1234&id=5678.
|
||||||
// You may specify a maximum of 20 IDs.
|
// You may specify a maximum of 20 IDs.
|
||||||
ID []string `url:"id"`
|
ID []string `url:"id,omitempty"`
|
||||||
|
|
||||||
// The maximum number of items to return per page in the response.
|
// The maximum number of items to return per page in the response.
|
||||||
// The minimum page size is 1 item per page and the maximum is 20 items per page.
|
// The minimum page size is 1 item per page and the maximum is 20 items per page.
|
||||||
// The default is 20.
|
// The default is 20.
|
||||||
First *int `url:"first"`
|
First *int `url:"first,omitempty"`
|
||||||
|
|
||||||
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
||||||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||||||
After *types.Cursor `url:"after"`
|
After *types.Cursor `url:"after,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetPollsResponse struct {
|
type GetPollsResponse struct {
|
||||||
|
|
|
@ -12,11 +12,11 @@ type AuthorizeParams struct {
|
||||||
// For information about claims, see Requesting claims: https://dev.twitch.tv/docs/authentication/getting-tokens-oidc/#requesting-claims
|
// For information about claims, see Requesting claims: https://dev.twitch.tv/docs/authentication/getting-tokens-oidc/#requesting-claims
|
||||||
//
|
//
|
||||||
// Only used for OIDC auth flows
|
// Only used for OIDC auth flows
|
||||||
Claims *Claims `url:"claims"`
|
Claims *Claims `url:"claims,omitempty"`
|
||||||
|
|
||||||
// Set to true to force the user to re-authorize your app’s access to their resources.
|
// Set to true to force the user to re-authorize your app’s access to their resources.
|
||||||
// The default is false.
|
// The default is false.
|
||||||
ForceVerify *bool `url:"force_verify"`
|
ForceVerify *bool `url:"force_verify,omitempty"`
|
||||||
|
|
||||||
// Although optional, you are strongly encouraged to pass a nonce string to help
|
// Although optional, you are strongly encouraged to pass a nonce string to help
|
||||||
// prevent Cross-Site Request Forgery (CSRF) attacks. The server returns this string
|
// prevent Cross-Site Request Forgery (CSRF) attacks. The server returns this string
|
||||||
|
@ -25,7 +25,7 @@ type AuthorizeParams struct {
|
||||||
// generated and unique for each OAuth request.
|
// generated and unique for each OAuth request.
|
||||||
//
|
//
|
||||||
// Only used for OIDC auth flows
|
// Only used for OIDC auth flows
|
||||||
Nonce *string `url:"nonce"`
|
Nonce *string `url:"nonce,omitempty"`
|
||||||
|
|
||||||
// Must be set to code for Authorization code grant flow.
|
// Must be set to code for Authorization code grant flow.
|
||||||
// Recommended for Server-to-Server flows. (with backend)
|
// Recommended for Server-to-Server flows. (with backend)
|
||||||
|
@ -45,7 +45,7 @@ type AuthorizeParams struct {
|
||||||
// the URI). If this string doesn’t match the state string that you passed, ignore
|
// the URI). If this string doesn’t match the state string that you passed, ignore
|
||||||
// the response. The state string should be randomly generated and unique for each
|
// the response. The state string should be randomly generated and unique for each
|
||||||
// OAuth request.
|
// OAuth request.
|
||||||
State *string `url:"state"`
|
State *string `url:"state,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthorizeUrl = "https://id.twitch.tv/oauth2/authorize"
|
const AuthorizeUrl = "https://id.twitch.tv/oauth2/authorize"
|
||||||
|
|
Loading…
Reference in New Issue