Compare commits

..

No commits in common. "main" and "v1.0.0" have entirely different histories.
main ... v1.0.0

143 changed files with 631 additions and 1529 deletions

View File

@ -1,11 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
## [1.2.1] - 2024-03-08
### 🐛 Bug Fixes
- *(devenv)* Fix version variable in release script
<!-- generated by git-cliff -->

5
api.go
View File

@ -2,8 +2,9 @@ package twitch
import ( import (
"go.fifitido.net/twitch/api" "go.fifitido.net/twitch/api"
"go.fifitido.net/twitch/auth"
) )
func NewAPI(clientId, clientSecret, redirectUri string) *api.API { func NewAPI(authClient *auth.Client) *api.API {
return api.NewDefault(clientId, clientSecret, redirectUri) return api.NewDefault(authClient)
} }

View File

@ -3,12 +3,9 @@ package ads
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetAdScheduleResponse struct { type GetAdScheduleResponse struct {
@ -41,25 +38,21 @@ type GetAdScheduleData struct {
// //
// Requires a user access token that includes the channel:read:ads scope. // Requires a user access token that includes the channel:read:ads scope.
// The user_id in the user access token must match the broadcaster_id. // The user_id in the user access token must match the broadcaster_id.
func (a *Ads) GetAdSchedule(ctx context.Context, broadcasterID string) (*GetAdScheduleResponse, error) { func (e *Ads) GetAdSchedule(ctx context.Context, broadcasterID string) (*GetAdScheduleResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "channels/ads", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(a.baseUrl, "channels/ads", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := a.client.Do(req) res, err := e.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get ad schedule (%d)", res.StatusCode)
}
var data GetAdScheduleResponse var data GetAdScheduleResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,9 @@ package ads
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
"go.fifitido.net/twitch/api/endpoint"
) )
type SnoozeNextAdResponse struct { type SnoozeNextAdResponse struct {
@ -33,9 +30,9 @@ type SnoozeNextAdData struct {
// Requires a user access token that includes the channel:manage:ads scope. // Requires a user access token that includes the channel:manage:ads scope.
// The user_id in the user access token must match the broadcaster_id. // The user_id in the user access token must match the broadcaster_id.
func (e *Ads) SnoozeNextAd(ctx context.Context, broadcasterID string) (*SnoozeNextAdResponse, error) { func (e *Ads) SnoozeNextAd(ctx context.Context, broadcasterID string) (*SnoozeNextAdResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "channels/ads/schedule/snooze", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequest(http.MethodPost, endpoint.Make(e.baseUrl, "channels/ads/schedule/snooze", v), nil) req, err := http.NewRequest(http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -44,12 +41,8 @@ func (e *Ads) SnoozeNextAd(ctx context.Context, broadcasterID string) (*SnoozeNe
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to snooze next ad (%d)", res.StatusCode)
}
var data SnoozeNextAdResponse var data SnoozeNextAdResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,11 +3,9 @@ package ads
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type StartCommercialRequest struct { type StartCommercialRequest struct {
@ -43,7 +41,8 @@ type StartCommercialData struct {
// NOTE: Only the broadcaster may start a commercial; the broadcasters editors and moderators may not start commercials on behalf of the broadcaster. // NOTE: Only the broadcaster may start a commercial; the broadcasters editors and moderators may not start commercials on behalf of the broadcaster.
// //
// Requires a user access token that includes the channel:edit:commercial scope. // Requires a user access token that includes the channel:edit:commercial scope.
func (a *Ads) StartCommercial(ctx context.Context, body *StartCommercialRequest) (*StartCommercialResponse, error) { func (e *Ads) StartCommercial(ctx context.Context, body *StartCommercialRequest) (*StartCommercialResponse, error) {
endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "channels/commercial"})
r, w := io.Pipe() r, w := io.Pipe()
@ -55,22 +54,18 @@ func (a *Ads) StartCommercial(ctx context.Context, body *StartCommercialRequest)
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(a.baseUrl, "channels/commercial"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := a.client.Do(req) res, err := e.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to start commercial (%d)", res.StatusCode)
}
var data StartCommercialResponse var data StartCommercialResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,11 @@ package analytics
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -81,25 +80,22 @@ type ExtensionAnalyticsReport struct {
// Learn More: https://dev.twitch.tv/docs/insights // Learn More: https://dev.twitch.tv/docs/insights
// //
// Requires a user access token that includes the analytics:read:extensions scope. // Requires a user access token that includes the analytics:read:extensions scope.
func (a *Analytics) GetExtensionAnalytics(ctx context.Context, params GetExtensionAnalyticsParams) (*GetExtensionAnalyticsResponse, error) { func (e *Analytics) GetExtensionAnalytics(ctx context.Context, params GetExtensionAnalyticsParams) (*GetExtensionAnalyticsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "analytics/extensions", RawQuery: v.Encode()})
req, err := http.NewRequest(http.MethodGet, endpoint.Make(a.baseUrl, "analytics/extensions", v), nil) req, err := http.NewRequest(http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := a.client.Do(req) res, err := e.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get extension analytics (%d)", res.StatusCode)
}
var data GetExtensionAnalyticsResponse var data GetExtensionAnalyticsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,11 @@ package analytics
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -82,25 +81,22 @@ type GameAnalyticsReport struct {
// Learn more: https://dev.twitch.tv/docs/insights // Learn more: https://dev.twitch.tv/docs/insights
// //
// Requires a user access token that includes the analytics:read:games scope. // Requires a user access token that includes the analytics:read:games scope.
func (a *Analytics) GetGameAnalytics(ctx context.Context, params GetGameAnalyticsParams) (*GetGameAnalyticsResponse, error) { func (e *Analytics) GetGameAnalytics(ctx context.Context, params GetGameAnalyticsParams) (*GetGameAnalyticsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "analytics/games", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(a.baseUrl, "analytics/games", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := a.client.Do(req) res, err := e.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get game analytics (%d)", res.StatusCode)
}
var data GetGameAnalyticsResponse var data GetGameAnalyticsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -39,9 +39,9 @@ import (
const HelixBaseUrl = "https://api.twitch.tv/helix" const HelixBaseUrl = "https://api.twitch.tv/helix"
type API struct { type API struct {
client *http.Client client *http.Client
baseUrl *url.URL baseUrl *url.URL
Auth *auth.Auth authClient *auth.Client
Ads *ads.Ads Ads *ads.Ads
Analytics *analytics.Analytics Analytics *analytics.Analytics
@ -73,11 +73,11 @@ type API struct {
Whispers *whispers.Whispers Whispers *whispers.Whispers
} }
func New(client *http.Client, baseUrl *url.URL, authClient *auth.Auth) *API { func New(client *http.Client, baseUrl *url.URL, authClient *auth.Client) *API {
return &API{ return &API{
client: client, client: client,
baseUrl: baseUrl, baseUrl: baseUrl,
Auth: authClient, authClient: authClient,
Ads: ads.New(client, baseUrl), Ads: ads.New(client, baseUrl),
Analytics: analytics.New(client, baseUrl), Analytics: analytics.New(client, baseUrl),
@ -110,26 +110,21 @@ func New(client *http.Client, baseUrl *url.URL, authClient *auth.Auth) *API {
} }
} }
func NewDefault(clientId, clientSecret, redirectUri string) *API { func NewDefault(authClient *auth.Client) *API {
client := &http.Client{ client := &http.Client{}
Transport: &apiTransport{
clientId: clientId,
},
}
baseUrl, _ := url.Parse(HelixBaseUrl) baseUrl, _ := url.Parse(HelixBaseUrl)
authClient := auth.NewWithClient(clientId, clientSecret, redirectUri, client)
return New(client, baseUrl, authClient) return New(client, baseUrl, authClient)
} }
func (a *API) WithClient(client *http.Client) *API { func (a *API) WithClient(client *http.Client) *API {
return New(client, a.baseUrl, a.Auth) return New(client, a.baseUrl, a.authClient)
} }
func (a *API) WithAuthToken(token *auth.Token) *API { func (a *API) WithAuthToken(token *auth.Token) *API {
return a.WithClient(&http.Client{ return a.WithClient(&http.Client{
Transport: &oauth2.Transport{ Transport: &oauth2.Transport{
Source: a.Auth.TokenSource(token), Source: a.authClient.TokenSource(token),
Base: a.client.Transport, Base: a.client.Transport,
}, },
}) })

View File

@ -3,12 +3,11 @@ package bits
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -71,8 +70,9 @@ type LeaderboardEntry struct {
// Requires a user access token that includes the bits:read scope. // Requires a user access token that includes the bits:read scope.
func (b *Bits) GetBitsLeaderboard(ctx context.Context, params *GetBitsLeaderboardParams) (*GetBitsLeaderboardResponse, error) { func (b *Bits) GetBitsLeaderboard(ctx context.Context, params *GetBitsLeaderboardParams) (*GetBitsLeaderboardResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := b.baseUrl.ResolveReference(&url.URL{Path: "bits/leaderboard", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(b.baseUrl, "bits/leaderboard", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -81,12 +81,8 @@ func (b *Bits) GetBitsLeaderboard(ctx context.Context, params *GetBitsLeaderboar
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to get bits leaderboard (%d)", res.StatusCode)
}
var data GetBitsLeaderboardResponse var data GetBitsLeaderboardResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,12 +3,9 @@ package bits
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetCheermotesResponse struct { type GetCheermotesResponse struct {
@ -85,9 +82,9 @@ type CheermoteImageSizes struct {
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (b *Bits) GetCheermotes(ctx context.Context, broadcasterID string) (*GetCheermotesResponse, error) { func (b *Bits) GetCheermotes(ctx context.Context, broadcasterID string) (*GetCheermotesResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := b.baseUrl.ResolveReference(&url.URL{Path: "bits/cheermotes", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(b.baseUrl, "bits/cheermotes", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -96,12 +93,8 @@ func (b *Bits) GetCheermotes(ctx context.Context, broadcasterID string) (*GetChe
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to get cheermotes (%d)", res.StatusCode)
}
var data GetCheermotesResponse var data GetCheermotesResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,12 +3,11 @@ package bits
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -98,8 +97,9 @@ type ProductDataCost struct {
// Requires an app access token. // Requires an app access token.
func (b *Bits) GetExtensionTransactions(ctx context.Context, params *GetExtensionTransactionsParams) (*GetExtensionTransactionsResponse, error) { func (b *Bits) GetExtensionTransactions(ctx context.Context, params *GetExtensionTransactionsParams) (*GetExtensionTransactionsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := b.baseUrl.ResolveReference(&url.URL{Path: "extensions/transactions", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(b.baseUrl, "extensions/transactions", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -108,12 +108,8 @@ func (b *Bits) GetExtensionTransactions(ctx context.Context, params *GetExtensio
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to get extension transactions (%d)", res.StatusCode)
}
var data GetExtensionTransactionsResponse var data GetExtensionTransactionsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,11 +3,10 @@ package ccls
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -39,8 +38,9 @@ type ContentClassificationLabelData struct {
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *CCLS) GetContentClassificationLabels(ctx context.Context, params GetContentClassificationLabelsParams) (*GetContentClassificationLabelsResponse, error) { func (c *CCLS) GetContentClassificationLabels(ctx context.Context, params GetContentClassificationLabelsParams) (*GetContentClassificationLabelsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "content_classification_labels", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "content_classification_labels", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -51,11 +51,6 @@ func (c *CCLS) GetContentClassificationLabels(ctx context.Context, params GetCon
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get content classification labels (%d)", res.StatusCode)
}
var data GetContentClassificationLabelsResponse var data GetContentClassificationLabelsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,9 @@ package channelpoints
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type CreateCustomRewardsRequest struct { type CreateCustomRewardsRequest struct {
@ -73,7 +70,7 @@ type CreateCustomRewardsResponse struct {
// //
// Requires a user access token that includes the channel:manage:redemptions scope. // Requires a user access token that includes the channel:manage:redemptions scope.
func (c *ChannelPoints) CreateCustomRewards(ctx context.Context, broadcastID string, body *CreateCustomRewardsRequest) (*CreateCustomRewardsResponse, error) { func (c *ChannelPoints) CreateCustomRewards(ctx context.Context, broadcastID string, body *CreateCustomRewardsRequest) (*CreateCustomRewardsResponse, error) {
v := url.Values{"broadcaster_id": {broadcastID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards", RawQuery: "broadcaster_id=" + broadcastID})
r, w := io.Pipe() r, w := io.Pipe()
@ -85,7 +82,7 @@ func (c *ChannelPoints) CreateCustomRewards(ctx context.Context, broadcastID str
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -94,12 +91,8 @@ func (c *ChannelPoints) CreateCustomRewards(ctx context.Context, broadcastID str
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to create custom rewards (%d)", res.StatusCode)
}
var data CreateCustomRewardsResponse var data CreateCustomRewardsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -2,11 +2,10 @@ package channelpoints
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type DeleteCustomRewardParams struct { type DeleteCustomRewardParams struct {
@ -25,8 +24,9 @@ type DeleteCustomRewardParams struct {
// Requires a user access token that includes the channel:manage:redemptions scope. // Requires a user access token that includes the channel:manage:redemptions scope.
func (c *ChannelPoints) DeleteCustomReward(ctx context.Context, params *DeleteCustomRewardParams) error { func (c *ChannelPoints) DeleteCustomReward(ctx context.Context, params *DeleteCustomRewardParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -35,12 +35,8 @@ func (c *ChannelPoints) DeleteCustomReward(ctx context.Context, params *DeleteCu
if err != nil { if err != nil {
return err return err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return fmt.Errorf("failed to delete custom reward (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,10 @@ package channelpoints
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetCustomRewardParams struct { type GetCustomRewardParams struct {
@ -38,8 +37,9 @@ type GetCustomRewardResponse struct {
// Requires a user access token that includes the channel:read:redemptions or channel:manage:redemptions scope. // Requires a user access token that includes the channel:read:redemptions or channel:manage:redemptions scope.
func (c *ChannelPoints) GetCustomReward(ctx context.Context, params *GetCustomRewardParams) (*GetCustomRewardResponse, error) { func (c *ChannelPoints) GetCustomReward(ctx context.Context, params *GetCustomRewardParams) (*GetCustomRewardResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -48,12 +48,8 @@ func (c *ChannelPoints) GetCustomReward(ctx context.Context, params *GetCustomRe
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to get custom rewards (%d)", res.StatusCode)
}
var data GetCustomRewardResponse var data GetCustomRewardResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,11 +3,10 @@ package channelpoints
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -54,8 +53,9 @@ type GetCustomRewardRedemptionResponse struct {
// Requires a user access token that includes the channel:read:redemptions or channel:manage:redemptions scope. // Requires a user access token that includes the channel:read:redemptions or channel:manage:redemptions scope.
func (c *ChannelPoints) GetCustomRewardRedemption(ctx context.Context, params *GetCustomRewardRedemptionParams) (*GetCustomRewardRedemptionResponse, error) { func (c *ChannelPoints) GetCustomRewardRedemption(ctx context.Context, params *GetCustomRewardRedemptionParams) (*GetCustomRewardRedemptionResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards/redemptions", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channel_points/custom_rewards/redemptions", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -64,12 +64,8 @@ func (c *ChannelPoints) GetCustomRewardRedemption(ctx context.Context, params *G
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to get custom reward redemptions (%d)", res.StatusCode)
}
var data GetCustomRewardRedemptionResponse var data GetCustomRewardRedemptionResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,12 +3,11 @@ package channelpoints
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateCustomRewardParams struct { type UpdateCustomRewardParams struct {
@ -83,6 +82,7 @@ type UpdateCustomRewardResponse struct {
// Requires a user access token that includes the channel:manage:redemptions scope. // Requires a user access token that includes the channel:manage:redemptions scope.
func (c *ChannelPoints) UpdateCustomReward(ctx context.Context, params *UpdateCustomRewardParams, body *UpdateCustomRewardRequest) (*UpdateCustomRewardResponse, error) { func (c *ChannelPoints) UpdateCustomReward(ctx context.Context, params *UpdateCustomRewardParams, body *UpdateCustomRewardRequest) (*UpdateCustomRewardResponse, error) {
v, _ := query.Values(body) v, _ := query.Values(body)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards", RawQuery: v.Encode()})
r, w := io.Pipe() r, w := io.Pipe()
@ -94,7 +94,7 @@ func (c *ChannelPoints) UpdateCustomReward(ctx context.Context, params *UpdateCu
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -103,12 +103,8 @@ func (c *ChannelPoints) UpdateCustomReward(ctx context.Context, params *UpdateCu
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to update custom reward (%d)", res.StatusCode)
}
var data UpdateCustomRewardResponse var data UpdateCustomRewardResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,12 +3,11 @@ package channelpoints
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateRedemptionStatusParams struct { type UpdateRedemptionStatusParams struct {
@ -43,6 +42,7 @@ type UpdateRedemptionStatusResponse struct {
// Requires a user access token that includes the channel:manage:redemptions scope. // Requires a user access token that includes the channel:manage:redemptions scope.
func (c *ChannelPoints) UpdateRedemptionStatus(ctx context.Context, params *UpdateRedemptionStatusParams, body *UpdateRedemptionStatusRequest) (*UpdateRedemptionStatusResponse, error) { func (c *ChannelPoints) UpdateRedemptionStatus(ctx context.Context, params *UpdateRedemptionStatusParams, body *UpdateRedemptionStatusRequest) (*UpdateRedemptionStatusResponse, error) {
v, _ := query.Values(body) v, _ := query.Values(body)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards/redemptions", RawQuery: v.Encode()})
r, w := io.Pipe() r, w := io.Pipe()
@ -54,7 +54,7 @@ func (c *ChannelPoints) UpdateRedemptionStatus(ctx context.Context, params *Upda
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "channel_points/custom_rewards/redemptions", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -63,12 +63,8 @@ func (c *ChannelPoints) UpdateRedemptionStatus(ctx context.Context, params *Upda
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to update redemption status (%d)", res.StatusCode)
}
var data UpdateRedemptionStatusResponse var data UpdateRedemptionStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,12 +3,9 @@ package channels
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetChannelEditorsResponse struct { type GetChannelEditorsResponse struct {
@ -31,9 +28,9 @@ type ChannelEditor struct {
// //
// Requires a user access token that includes the channel:read:editors scope. // Requires a user access token that includes the channel:read:editors scope.
func (c *Channels) GetChannelEditors(ctx context.Context, broadcasterID string) (*GetChannelEditorsResponse, error) { func (c *Channels) GetChannelEditors(ctx context.Context, broadcasterID string) (*GetChannelEditorsResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels/editors", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channels/editors", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -42,12 +39,8 @@ func (c *Channels) GetChannelEditors(ctx context.Context, broadcasterID string)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to get channel editors (%d)", res.StatusCode)
}
var data GetChannelEditorsResponse var data GetChannelEditorsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,12 +3,11 @@ package channels
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -19,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,omitempty"` UserID *string `url:"user_id"`
// The broadcasters ID. Returns the list of users that follow this broadcaster. // The broadcasters ID. Returns the list of users that follow this broadcaster.
BroadcasterID string `url:"broadcaster_id"` BroadcasterID string `url:"broadcaster_id"`
@ -72,8 +71,9 @@ type ChannelFollower struct {
// only the total follower count will be included in the response. // only the total follower count will be included in the response.
func (c *Channels) GetChannelFollowers(ctx context.Context, params *GetChannelFollowersParams) (*GetChannelFollowersResponse, error) { func (c *Channels) GetChannelFollowers(ctx context.Context, params *GetChannelFollowersParams) (*GetChannelFollowersResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels/followers", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channels/followers", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -82,12 +82,8 @@ func (c *Channels) GetChannelFollowers(ctx context.Context, params *GetChannelFo
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to get channel followers (%d)", res.StatusCode)
}
var data GetChannelFollowersResponse var data GetChannelFollowersResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,12 +3,11 @@ package channels
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/ccls" "go.fifitido.net/twitch/api/ccls"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetChannelInformationParams struct { type GetChannelInformationParams struct {
@ -71,8 +70,9 @@ type ChannelInformation struct {
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *Channels) GetChannelInformation(ctx context.Context, params *GetChannelInformationParams) (*GetChannelInformdationResponse, error) { func (c *Channels) GetChannelInformation(ctx context.Context, params *GetChannelInformationParams) (*GetChannelInformdationResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channels", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -81,12 +81,8 @@ func (c *Channels) GetChannelInformation(ctx context.Context, params *GetChannel
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300 defer res.Body.Close()
if !statusOK {
return nil, fmt.Errorf("failed to get channel information (%d)", res.StatusCode)
}
var data GetChannelInformdationResponse var data GetChannelInformdationResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,12 +3,11 @@ package channels
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -63,8 +62,9 @@ type FollowedChannel struct {
// Requires a user access token that includes the user:read:follows scope. // Requires a user access token that includes the user:read:follows scope.
func (c *Channels) GetFollowedChannels(ctx context.Context, params *GetFollowedChannelsParams) (*GetFollowedChannelsResponse, error) { func (c *Channels) GetFollowedChannels(ctx context.Context, params *GetFollowedChannelsParams) (*GetFollowedChannelsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "users/follows", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "users/follows", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -76,11 +76,6 @@ func (c *Channels) GetFollowedChannels(ctx context.Context, params *GetFollowedC
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get followed channels (%d)", res.StatusCode)
}
var data GetFollowedChannelsResponse var data GetFollowedChannelsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,13 +3,11 @@ package channels
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/ccls" "go.fifitido.net/twitch/api/ccls"
"go.fifitido.net/twitch/api/endpoint"
) )
type ModifyChannelInformationRequest struct { type ModifyChannelInformationRequest struct {
@ -56,7 +54,7 @@ type ModifyContentClassificationLabel struct {
// //
// Requires a user access token that includes the channel:manage:broadcast scope. // Requires a user access token that includes the channel:manage:broadcast scope.
func (c *Channels) ModifyChannelInformation(ctx context.Context, broadcasterID string, body *ModifyChannelInformationRequest) error { func (c *Channels) ModifyChannelInformation(ctx context.Context, broadcasterID string, body *ModifyChannelInformationRequest) error {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels", RawQuery: "broadcaster_id=" + broadcasterID})
r, w := io.Pipe() r, w := io.Pipe()
@ -68,21 +66,14 @@ func (c *Channels) ModifyChannelInformation(ctx context.Context, broadcasterID s
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "channels", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil { if err != nil {
return err return err
} }
res, err := c.client.Do(req) if _, err := c.client.Do(req); err != nil {
if err != nil {
return err return err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to modify channel information (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,9 @@ package charity
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -57,9 +55,9 @@ type CharityCampaign struct {
// //
// Requires a user access token that includes the channel:read:charity scope. // Requires a user access token that includes the channel:read:charity scope.
func (c *Charity) GetCharityCampaign(ctx context.Context, broadcasterID string) (*GetCharityCampaignResponse, error) { func (c *Charity) GetCharityCampaign(ctx context.Context, broadcasterID string) (*GetCharityCampaignResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "charity/campaigns", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "charity/campaigns", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -71,11 +69,6 @@ func (c *Charity) GetCharityCampaign(ctx context.Context, broadcasterID string)
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get charity campaign (%d)", res.StatusCode)
}
var data GetCharityCampaignResponse var data GetCharityCampaignResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package charity
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -61,8 +60,9 @@ type CharityCampaignDonation struct {
// Requires a user access token that includes the channel:read:charity scope. // Requires a user access token that includes the channel:read:charity scope.
func (c *Charity) GetCharityCampaignDonations(ctx context.Context, params *GetCharityCampaignDonationsParams) (*GetCharityCampaignDonationsResponse, error) { func (c *Charity) GetCharityCampaignDonations(ctx context.Context, params *GetCharityCampaignDonationsParams) (*GetCharityCampaignDonationsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "charity/campaigns/donations", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "charity/campaigns/donations", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -71,12 +71,6 @@ func (c *Charity) GetCharityCampaignDonations(ctx context.Context, params *GetCh
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get charity campaign donations (%d)", res.StatusCode)
}
var respBody GetCharityCampaignDonationsResponse var respBody GetCharityCampaignDonationsResponse
if err := json.NewDecoder(res.Body).Decode(&respBody); err != nil { if err := json.NewDecoder(res.Body).Decode(&respBody); err != nil {

View File

@ -3,11 +3,8 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetChannelChatBadgesResponse struct { type GetChannelChatBadgesResponse struct {
@ -22,9 +19,9 @@ type GetChannelChatBadgesResponse struct {
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *Chat) GetChannelChatBadges(ctx context.Context, broadcasterID string) (*GetChannelChatBadgesResponse, error) { func (c *Chat) GetChannelChatBadges(ctx context.Context, broadcasterID string) (*GetChannelChatBadgesResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/badges", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/badges", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -35,11 +32,6 @@ func (c *Chat) GetChannelChatBadges(ctx context.Context, broadcasterID string) (
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get channel chat badges (%d)", res.StatusCode)
}
var data GetChannelChatBadgesResponse var data GetChannelChatBadgesResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,8 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetChannelEmotesResponse struct { type GetChannelEmotesResponse struct {
@ -91,26 +88,21 @@ type ChannelEmote struct {
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *Chat) GetChannelEmotes(ctx context.Context, broadcasterID string) (*GetChannelEmotesResponse, error) { func (c *Chat) GetChannelEmotes(ctx context.Context, broadcasterID string) (*GetChannelEmotesResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/emotes", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/emotes", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := c.client.Do(req) resp, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer resp.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get channel emotes (%d)", res.StatusCode)
}
var response GetChannelEmotesResponse var response GetChannelEmotesResponse
if err := json.NewDecoder(res.Body).Decode(&response); err != nil { if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
return nil, err return nil, err
} }

View File

@ -3,11 +3,10 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetChatSettingsParams struct { type GetChatSettingsParams struct {
@ -36,8 +35,9 @@ type GetChatSettingsResponse struct {
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *Chat) GetChatSettings(ctx context.Context, params *GetChatSettingsParams) (*GetChatSettingsResponse, error) { func (c *Chat) GetChatSettings(ctx context.Context, params *GetChatSettingsParams) (*GetChatSettingsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/settings", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/settings", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -48,11 +48,6 @@ func (c *Chat) GetChatSettings(ctx context.Context, params *GetChatSettingsParam
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get chat settings (%d)", res.StatusCode)
}
var data GetChatSettingsResponse var data GetChatSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -63,25 +62,21 @@ type Chatter struct {
// Requires a user access token that includes the moderator:read:chatters scope. // Requires a user access token that includes the moderator:read:chatters scope.
func (c *Chat) GetChatters(ctx context.Context, params *GetChattersParams) (*GetChattersResponse, error) { func (c *Chat) GetChatters(ctx context.Context, params *GetChattersParams) (*GetChattersResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/chatters", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/chatters", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := c.client.Do(req) resp, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer resp.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get chatters (%d)", res.StatusCode)
}
var response GetChattersResponse var response GetChattersResponse
if err := json.NewDecoder(res.Body).Decode(&response); err != nil { if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
return nil, err return nil, err
} }

View File

@ -3,11 +3,10 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetEmoteSetsParams struct { type GetEmoteSetsParams struct {
@ -95,8 +94,9 @@ type EmoteSetEmote struct {
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *Chat) GetEmoteSets(ctx context.Context, params *GetEmoteSetsParams) (*GetEmoteSetsResponse, error) { func (c *Chat) GetEmoteSets(ctx context.Context, params *GetEmoteSetsParams) (*GetEmoteSetsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/emotes/set", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/emotes/set", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -107,11 +107,6 @@ func (c *Chat) GetEmoteSets(ctx context.Context, params *GetEmoteSetsParams) (*G
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get emote sets (%d)", res.StatusCode)
}
var data GetEmoteSetsResponse var data GetEmoteSetsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,10 +3,8 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetGlobalChatBadgesResponse struct { type GetGlobalChatBadgesResponse struct {
@ -19,7 +17,9 @@ type GetGlobalChatBadgesResponse struct {
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *Chat) GetGlobalChatBadges(ctx context.Context) (*GetGlobalChatBadgesResponse, error) { func (c *Chat) GetGlobalChatBadges(ctx context.Context) (*GetGlobalChatBadgesResponse, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/badges/global"), nil) endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/badges/global"})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -30,11 +30,6 @@ func (c *Chat) GetGlobalChatBadges(ctx context.Context) (*GetGlobalChatBadgesRes
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get global chat badges (%d)", res.StatusCode)
}
var data GetGlobalChatBadgesResponse var data GetGlobalChatBadgesResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,10 +3,8 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetGlobalEmotesResponse struct { type GetGlobalEmotesResponse struct {
@ -66,7 +64,9 @@ type GlobalEmote struct {
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *Chat) GetGlobalEmotes(ctx context.Context) (*GetGlobalEmotesResponse, error) { func (c *Chat) GetGlobalEmotes(ctx context.Context) (*GetGlobalEmotesResponse, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/emotes/global"), nil) endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/emotes/global"})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -77,11 +77,6 @@ func (c *Chat) GetGlobalEmotes(ctx context.Context) (*GetGlobalEmotesResponse, e
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get global emotes (%d)", res.StatusCode)
}
var data GetGlobalEmotesResponse var data GetGlobalEmotesResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetUserChatColorParams struct { type GetUserChatColorParams struct {
@ -44,8 +43,9 @@ type UserChatColor struct {
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (c *Chat) GetUserChatColor(ctx context.Context, params *GetUserChatColorParams) (*GetUserChatColorResponse, error) { func (c *Chat) GetUserChatColor(ctx context.Context, params *GetUserChatColorParams) (*GetUserChatColorResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/color", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/color", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,11 +56,6 @@ func (c *Chat) GetUserChatColor(ctx context.Context, params *GetUserChatColorPar
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get user chat color (%d)", res.StatusCode)
}
var data GetUserChatColorResponse var data GetUserChatColorResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,11 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -38,6 +37,7 @@ type SendChatAnnouncementRequest struct {
// Requires a user access token that includes the moderator:manage:announcements scope. // Requires a user access token that includes the moderator:manage:announcements scope.
func (c *Chat) SendChatAnnouncement(ctx context.Context, params *SendChatAnnouncementParams, body *SendChatAnnouncementRequest) error { func (c *Chat) SendChatAnnouncement(ctx context.Context, params *SendChatAnnouncementParams, body *SendChatAnnouncementRequest) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/announcements", RawQuery: v.Encode()})
r, w := io.Pipe() r, w := io.Pipe()
@ -49,7 +49,7 @@ func (c *Chat) SendChatAnnouncement(ctx context.Context, params *SendChatAnnounc
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "chat/announcements", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return err return err
} }
@ -60,10 +60,5 @@ func (c *Chat) SendChatAnnouncement(ctx context.Context, params *SendChatAnnounc
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to send chat announcement (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,9 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type SendChatMessageRequest struct { type SendChatMessageRequest struct {
@ -55,6 +53,8 @@ type DropReason struct {
// If app access token used, then additionally requires user:bot scope from chatting user, // If app access token used, then additionally requires user:bot scope from chatting user,
// and either channel:bot scope from broadcaster or moderator status. // and either channel:bot scope from broadcaster or moderator status.
func (c *Chat) SendChatMessage(ctx context.Context, body *SendChatMessageRequest) (*SendChatMessageResponse, error) { func (c *Chat) SendChatMessage(ctx context.Context, body *SendChatMessageRequest) (*SendChatMessageResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/messages"})
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
@ -65,7 +65,7 @@ func (c *Chat) SendChatMessage(ctx context.Context, body *SendChatMessageRequest
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "chat/messages"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -76,11 +76,6 @@ func (c *Chat) SendChatMessage(ctx context.Context, body *SendChatMessageRequest
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to send chat message (%d)", res.StatusCode)
}
var data SendChatMessageResponse var data SendChatMessageResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,10 @@ package chat
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type SendShoutoutParams struct { type SendShoutoutParams struct {
@ -39,8 +38,9 @@ type SendShoutoutParams struct {
// Requires a user access token that includes the moderator:manage:shoutouts scope. // Requires a user access token that includes the moderator:manage:shoutouts scope.
func (c *Chat) SendShoutout(ctx context.Context, params *SendShoutoutParams) error { func (c *Chat) SendShoutout(ctx context.Context, params *SendShoutoutParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/shoutouts", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "chat/shoutouts", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -51,10 +51,5 @@ func (c *Chat) SendShoutout(ctx context.Context, params *SendShoutoutParams) err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to send shoutout (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,12 +3,11 @@ package chat
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateChatSettingsParams struct { type UpdateChatSettingsParams struct {
@ -94,6 +93,7 @@ type UpdateChatSettingsResponse struct {
// Requires a user access token that includes the moderator:manage:chat_settings scope. // Requires a user access token that includes the moderator:manage:chat_settings scope.
func (c *Chat) UpdateChatSettings(ctx context.Context, params *UpdateChatSettingsParams, body *UpdateChatSettingsRequest) (*UpdateChatSettingsResponse, error) { func (c *Chat) UpdateChatSettings(ctx context.Context, params *UpdateChatSettingsParams, body *UpdateChatSettingsRequest) (*UpdateChatSettingsResponse, error) {
v, _ := query.Values(body) v, _ := query.Values(body)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/settings", RawQuery: v.Encode()})
r, w := io.Pipe() r, w := io.Pipe()
@ -105,7 +105,7 @@ func (c *Chat) UpdateChatSettings(ctx context.Context, params *UpdateChatSetting
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "chat/settings", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -116,11 +116,6 @@ func (c *Chat) UpdateChatSettings(ctx context.Context, params *UpdateChatSetting
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to update chat settings (%d)", res.StatusCode)
}
var data UpdateChatSettingsResponse var data UpdateChatSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,10 @@ package chat
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateUserChatColorParams struct { type UpdateUserChatColorParams struct {
@ -27,8 +26,9 @@ type UpdateUserChatColorParams struct {
// Requires a user access token that includes the user:manage:chat_color scope. // Requires a user access token that includes the user:manage:chat_color scope.
func (c *Chat) UpdateUserChatColor(ctx context.Context, params *UpdateUserChatColorParams) error { func (c *Chat) UpdateUserChatColor(ctx context.Context, params *UpdateUserChatColorParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/color", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(c.baseUrl, "chat/color", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -39,10 +39,5 @@ func (c *Chat) UpdateUserChatColor(ctx context.Context, params *UpdateUserChatCo
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to update user chat color (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,9 @@ package conduit
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type CreateConduitsRequest struct { type CreateConduitsRequest struct {
@ -23,6 +21,8 @@ type CreateConduitsResponse struct {
// //
// Requires an app access token. // Requires an app access token.
func (c *Conduit) CreateConduits(ctx context.Context, body *CreateConduitsRequest) (*CreateConduitsResponse, error) { func (c *Conduit) CreateConduits(ctx context.Context, body *CreateConduitsRequest) (*CreateConduitsResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits"})
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
@ -33,7 +33,7 @@ func (c *Conduit) CreateConduits(ctx context.Context, body *CreateConduitsReques
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "eventsub/conduits"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -44,11 +44,6 @@ func (c *Conduit) CreateConduits(ctx context.Context, body *CreateConduitsReques
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to create conduit (%d)", res.StatusCode)
}
var data CreateConduitsResponse var data CreateConduitsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,8 @@ package conduit
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
// Deletes a specified conduit. // Deletes a specified conduit.
@ -14,9 +11,9 @@ import (
// //
// Requires an app access token. // Requires an app access token.
func (c *Conduit) DeleteConduit(ctx context.Context, id string) error { func (c *Conduit) DeleteConduit(ctx context.Context, id string) error {
v := url.Values{"id": {id}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits", RawQuery: "id=" + id})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(c.baseUrl, "eventsub/conduits", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -27,10 +24,5 @@ func (c *Conduit) DeleteConduit(ctx context.Context, id string) error {
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to delete conduit (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,10 @@ package conduit
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -35,8 +34,9 @@ type GetConduitShardsResponse struct {
// Requires an app access token. // Requires an app access token.
func (c *Conduit) GetConduitShards(ctx context.Context, params *GetConduitShardsParams) (*GetConduitShardsResponse, error) { func (c *Conduit) GetConduitShards(ctx context.Context, params *GetConduitShardsParams) (*GetConduitShardsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits/shards", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "eventsub/conduits/shards", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -47,11 +47,6 @@ func (c *Conduit) GetConduitShards(ctx context.Context, params *GetConduitShards
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get conduit shards (%d)", res.StatusCode)
}
var data GetConduitShardsResponse var data GetConduitShardsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,10 +3,8 @@ package conduit
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetConduitsResponse struct { type GetConduitsResponse struct {
@ -18,7 +16,9 @@ type GetConduitsResponse struct {
// //
// Requires an app access token. // Requires an app access token.
func (c *Conduit) GetConduits(ctx context.Context) (*GetConduitsResponse, error) { func (c *Conduit) GetConduits(ctx context.Context) (*GetConduitsResponse, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "eventsub/conduits"), nil) endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits"})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -29,11 +29,6 @@ func (c *Conduit) GetConduits(ctx context.Context) (*GetConduitsResponse, error)
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get conduits (%d)", res.StatusCode)
}
var data GetConduitsResponse var data GetConduitsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package conduit
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/eventsub" "go.fifitido.net/twitch/api/eventsub"
) )
@ -69,6 +68,8 @@ type UpdateConduitShardsError struct {
// //
// Requires an app access token. // Requires an app access token.
func (c *Conduit) UpdateConduitShards(ctx context.Context, body *UpdateConduitShardsRequest) (*UpdateConduitShardsResponse, error) { func (c *Conduit) UpdateConduitShards(ctx context.Context, body *UpdateConduitShardsRequest) (*UpdateConduitShardsResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits/shards"})
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
@ -79,7 +80,7 @@ func (c *Conduit) UpdateConduitShards(ctx context.Context, body *UpdateConduitSh
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "eventsub/conduits/shards"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -90,11 +91,6 @@ func (c *Conduit) UpdateConduitShards(ctx context.Context, body *UpdateConduitSh
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to update conduit shards (%d)", res.StatusCode)
}
var data UpdateConduitShardsResponse var data UpdateConduitShardsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,9 @@ package conduit
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateConduitsRequest struct { type UpdateConduitsRequest struct {
@ -28,6 +26,8 @@ type UpdateConduitsResponse struct {
// //
// Requires an app access token. // Requires an app access token.
func (c *Conduit) UpdateConduits(ctx context.Context, body *UpdateConduitsRequest) (*UpdateConduitsResponse, error) { func (c *Conduit) UpdateConduits(ctx context.Context, body *UpdateConduitsRequest) (*UpdateConduitsResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits"})
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
@ -38,7 +38,7 @@ func (c *Conduit) UpdateConduits(ctx context.Context, body *UpdateConduitsReques
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "eventsub/conduits"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -49,11 +49,6 @@ func (c *Conduit) UpdateConduits(ctx context.Context, body *UpdateConduitsReques
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to update conduit (%d)", res.StatusCode)
}
var data UpdateConduitsResponse var data UpdateConduitsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -1,19 +0,0 @@
package endpoint
import (
"net/url"
"strings"
)
func Make(baseUrl *url.URL, path string, vals ...url.Values) string {
var sb strings.Builder
sb.WriteString(baseUrl.String())
sb.WriteString("/")
sb.WriteString(path)
if len(vals) > 0 {
sb.WriteString("?")
sb.WriteString(vals[0].Encode())
}
return sb.String()
}

View File

@ -3,12 +3,11 @@ package entitlements
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -89,24 +88,19 @@ type Entitlement struct {
// User | game_id | The request returns all entitlements that the specified game granted to the user identified in the access token. // User | game_id | The request returns all entitlements that the specified game granted to the user identified in the access token.
// //
// Requires an app access token or user access token. The client ID in the access token must own the game. // Requires an app access token or user access token. The client ID in the access token must own the game.
func (e *Entitlements) GetDropsEntitlements(ctx context.Context, params *GetDropsEntitlementsParams) (*GetDropsEntitlementsResponse, error) { func (c *Entitlements) GetDropsEntitlements(ctx context.Context, params *GetDropsEntitlementsParams) (*GetDropsEntitlementsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "entitlements/drops", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "entitlements/drops", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get drops entitlements (%d)", res.StatusCode)
}
var data GetDropsEntitlementsResponse var data GetDropsEntitlementsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,11 +3,9 @@ package entitlements
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateDropsEntitlementsRequest struct { type UpdateDropsEntitlementsRequest struct {
@ -40,7 +38,9 @@ type UpdateDropsEntitlementsData struct {
// User | Updates all entitlements owned by the user in the access token and where the benefits are owned by the organization in the access token. // User | Updates all entitlements owned by the user in the access token and where the benefits are owned by the organization in the access token.
// //
// Requires an app access token or user access token. The client ID in the access token must own the game. // Requires an app access token or user access token. The client ID in the access token must own the game.
func (e *Entitlements) UpdateDropsEntitlements(ctx context.Context, request *UpdateDropsEntitlementsRequest) (*UpdateDropsEntitlementsResponse, error) { func (c *Entitlements) UpdateDropsEntitlements(ctx context.Context, request *UpdateDropsEntitlementsRequest) (*UpdateDropsEntitlementsResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "entitlements/drops"})
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
@ -51,21 +51,15 @@ func (e *Entitlements) UpdateDropsEntitlements(ctx context.Context, request *Upd
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(e.baseUrl, "entitlements/drops"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to update drops entitlements (%d)", res.StatusCode)
}
var data UpdateDropsEntitlementsResponse var data UpdateDropsEntitlementsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -3,11 +3,9 @@ package eventsub
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type CreateEventSubSubscriptionRequest struct { type CreateEventSubSubscriptionRequest struct {
@ -52,6 +50,7 @@ type CreateEventSubSubscriptionResponse struct {
// If you use Conduits to receive events, the request must specify an app access token. // If you use Conduits to receive events, the request must specify an app access token.
// The request will fail if you use a user access token. // The request will fail if you use a user access token.
func (e *EventSub) CreateEventSubSubscription(ctx context.Context, body *CreateEventSubSubscriptionRequest) (*CreateEventSubSubscriptionResponse, error) { func (e *EventSub) CreateEventSubSubscription(ctx context.Context, body *CreateEventSubSubscriptionRequest) (*CreateEventSubSubscriptionResponse, error) {
endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "eventsub/subscriptions"})
r, w := io.Pipe() r, w := io.Pipe()
@ -63,7 +62,7 @@ func (e *EventSub) CreateEventSubSubscription(ctx context.Context, body *CreateE
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(e.baseUrl, "eventsub/subscriptions"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -75,11 +74,6 @@ func (e *EventSub) CreateEventSubSubscription(ctx context.Context, body *CreateE
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to create EventSub subscription (%d)", res.StatusCode)
}
var data CreateEventSubSubscriptionResponse var data CreateEventSubSubscriptionResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,8 @@ package eventsub
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
// Deletes an EventSub subscription. // Deletes an EventSub subscription.
@ -17,23 +14,16 @@ import (
// If you use WebSockets to receive events, the request must specify a user access token. // If you use WebSockets to receive events, the request must specify a user access token.
// The request will fail if you use an app access token. The token may include any scopes. // The request will fail if you use an app access token. The token may include any scopes.
func (e *EventSub) DeleteEventSubSubscription(ctx context.Context, id string) error { func (e *EventSub) DeleteEventSubSubscription(ctx context.Context, id string) error {
v := url.Values{"id": {id}} endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "eventsub/subscriptions", RawQuery: "id=" + id})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(e.baseUrl, "eventsub/subscriptions", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
res, err := e.client.Do(req) if _, err := e.client.Do(req); err != nil {
if err != nil {
return err return err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to delete EventSub subscription (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,10 @@ package eventsub
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -58,8 +57,9 @@ type GetEventSubSubscriptionsResponse struct {
// The request will fail if you use an app access token. The token may include any scopes. // The request will fail if you use an app access token. The token may include any scopes.
func (e *EventSub) GetEventSubSubscriptions(ctx context.Context, params *GetEventSubSubscriptionsParams) (*GetEventSubSubscriptionsResponse, error) { func (e *EventSub) GetEventSubSubscriptions(ctx context.Context, params *GetEventSubSubscriptionsParams) (*GetEventSubSubscriptionsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "eventsub/subscriptions", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "eventsub/subscriptions", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -71,11 +71,6 @@ func (e *EventSub) GetEventSubSubscriptions(ctx context.Context, params *GetEven
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get EventSub subscriptions (%d)", res.StatusCode)
}
var data GetEventSubSubscriptionsResponse var data GetEventSubSubscriptionsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type CreateExtensionSecretParams struct { type CreateExtensionSecretParams struct {
@ -18,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,omitempty"` Delay *int `url:"delay"`
} }
type CreateExtensionSecretResponse struct { type CreateExtensionSecretResponse struct {
@ -35,25 +34,21 @@ type CreateExtensionSecretResponse struct {
// The signed JWT must include the role, user_id, and exp fields // The signed JWT must include the role, user_id, and exp fields
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
// The role field must be set to external. // The role field must be set to external.
func (e *Extensions) CreateExtensionSecret(ctx context.Context, params *CreateExtensionSecretParams) (*CreateExtensionSecretResponse, error) { func (c *Extensions) CreateExtensionSecret(ctx context.Context, params *CreateExtensionSecretParams) (*CreateExtensionSecretResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/jwt/secrets", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(e.baseUrl, "extensions/jwt/secrets", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to create extension secret (%d)", res.StatusCode)
}
var data CreateExtensionSecretResponse var data CreateExtensionSecretResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetExtensionBitsProductsParams struct { type GetExtensionBitsProductsParams struct {
@ -23,25 +22,21 @@ type GetExtensionBitsProductsResponse struct {
// Gets the list of Bits products that belongs to the extension. The client ID in the app access token identifies the extension. // Gets the list of Bits products that belongs to the extension. The client ID in the app access token identifies the extension.
// //
// Requires an app access token. The client ID in the app access token must be the extensions client ID. // Requires an app access token. The client ID in the app access token must be the extensions client ID.
func (e *Extensions) GetExtensionBitsProducts(ctx context.Context, params *GetExtensionBitsProductsParams) (*GetExtensionBitsProductsResponse, error) { func (c *Extensions) GetExtensionBitsProducts(ctx context.Context, params *GetExtensionBitsProductsParams) (*GetExtensionBitsProductsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "bits/extensions", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "bits/extensions", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get extension bits products (%d)", res.StatusCode)
}
var data GetExtensionBitsProductsResponse var data GetExtensionBitsProductsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetExtensionConfigurationSegmentParams struct { type GetExtensionConfigurationSegmentParams struct {
@ -58,25 +57,21 @@ type ConfigurationSegmentData struct {
// The signed JWT must include the role, user_id, and exp fields // The signed JWT must include the role, user_id, and exp fields
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
// The role field must be set to external. // The role field must be set to external.
func (e *Extensions) GetExtensionConfigurationSegment(ctx context.Context, params *GetExtensionConfigurationSegmentParams) (*GetExtensionConfigurationSegmentResponse, error) { func (c *Extensions) GetExtensionConfigurationSegment(ctx context.Context, params *GetExtensionConfigurationSegmentParams) (*GetExtensionConfigurationSegmentResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/configurations", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions/configurations", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get extension configuration segment (%d)", res.StatusCode)
}
var data GetExtensionConfigurationSegmentResponse var data GetExtensionConfigurationSegmentResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -50,25 +49,21 @@ type ExtensionLiveChannel struct {
// It may take a few minutes for the list to include or remove broadcasters that have recently gone live or stopped broadcasting. // It may take a few minutes for the list to include or remove broadcasters that have recently gone live or stopped broadcasting.
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (e *Extensions) GetExtensionLiveChannels(ctx context.Context, params *GetExtensionLiveChannelsParams) (*GetExtensionLiveChannelsResponse, error) { func (c *Extensions) GetExtensionLiveChannels(ctx context.Context, params *GetExtensionLiveChannelsParams) (*GetExtensionLiveChannelsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/live", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions/live", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get extension live channels (%d)", res.StatusCode)
}
var response GetExtensionLiveChannelsResponse var response GetExtensionLiveChannelsResponse
if err := json.NewDecoder(res.Body).Decode(&response); err != nil { if err := json.NewDecoder(res.Body).Decode(&response); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,8 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetExtensionSecretsResponse struct { type GetExtensionSecretsResponse struct {
@ -22,25 +19,20 @@ type GetExtensionSecretsResponse struct {
// The signed JWT must include the role, user_id, and exp fields // The signed JWT must include the role, user_id, and exp fields
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
// The role field must be set to external. // The role field must be set to external.
func (e *Extensions) GetExtensionSecrets(ctx context.Context, extensionID string) (*GetExtensionSecretsResponse, error) { func (c *Extensions) GetExtensionSecrets(ctx context.Context, extensionID string) (*GetExtensionSecretsResponse, error) {
v := url.Values{"extension_id": {extensionID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/jwt/secrets", RawQuery: "extension_id=" + extensionID})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions/jwt/secrets", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get extension secrets (%d)", res.StatusCode)
}
var data GetExtensionSecretsResponse var data GetExtensionSecretsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetExtensionsParams struct { type GetExtensionsParams struct {
@ -31,25 +30,21 @@ type GetExtensionsResponse struct {
// The signed JWT must include the role, user_id, and exp fields // The signed JWT must include the role, user_id, and exp fields
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
// The role field must be set to external. // The role field must be set to external.
func (e *Extensions) GetExtensions(ctx context.Context, params *GetExtensionsParams) (*GetExtensionsResponse, error) { func (c *Extensions) GetExtensions(ctx context.Context, params *GetExtensionsParams) (*GetExtensionsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get extensions (%d)", res.StatusCode)
}
var data GetExtensionsResponse var data GetExtensionsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetReleasedExtensionsParams struct { type GetReleasedExtensionsParams struct {
@ -26,25 +25,21 @@ type GetReleasedExtensionsResponse struct {
// Gets information about a released extension. Returns the extension if its state is Released. // Gets information about a released extension. Returns the extension if its state is Released.
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (e *Extensions) GetReleasedExtensions(ctx context.Context, params *GetReleasedExtensionsParams) (*GetReleasedExtensionsResponse, error) { func (c *Extensions) GetReleasedExtensions(ctx context.Context, params *GetReleasedExtensionsParams) (*GetReleasedExtensionsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/released", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions/released", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get released extensions (%d)", res.StatusCode)
}
var data GetReleasedExtensionsResponse var data GetReleasedExtensionsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,9 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type SendExtensionChatMessageRequest struct { type SendExtensionChatMessageRequest struct {
@ -33,8 +30,8 @@ type SendExtensionChatMessageRequest struct {
// The signed JWT must include the role, user_id, and exp fields // The signed JWT must include the role, user_id, and exp fields
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
// The role field must be set to external. // The role field must be set to external.
func (e *Extensions) SendExtensionChatMessage(ctx context.Context, broadcasterID string, body *SendExtensionChatMessageRequest) error { func (c *Extensions) SendExtensionChatMessage(ctx context.Context, broadcasterID string, body *SendExtensionChatMessageRequest) error {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/chat", RawQuery: "broadcaster_id=" + broadcasterID})
r, w := io.Pipe() r, w := io.Pipe()
@ -46,21 +43,16 @@ func (e *Extensions) SendExtensionChatMessage(ctx context.Context, broadcasterID
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(e.baseUrl, "extensions/chat", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return err return err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return err return err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to send extension chat message (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,9 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type SendExtensionPubsubMessageRequest struct { type SendExtensionPubsubMessageRequest struct {
@ -43,7 +41,9 @@ type SendExtensionPubsubMessageRequest struct {
// To send the message to a specific channel, set the channel_id field in the JWT to the channels ID and set the pubsub_perms.send array to broadcast. // To send the message to a specific channel, set the channel_id field in the JWT to the channels ID and set the pubsub_perms.send array to broadcast.
// //
// To send the message to all channels on which your extension is active, set the channel_id field to all and set the pubsub_perms.send array to global. // To send the message to all channels on which your extension is active, set the channel_id field to all and set the pubsub_perms.send array to global.
func (e *Extensions) SendExtensionPubsubMessage(ctx context.Context, body *SendExtensionPubsubMessageRequest) error { func (c *Extensions) SendExtensionPubsubMessage(ctx context.Context, body *SendExtensionPubsubMessageRequest) error {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/pubsub"})
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
@ -54,21 +54,16 @@ func (e *Extensions) SendExtensionPubsubMessage(ctx context.Context, body *SendE
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(e.baseUrl, "extensions/pubsub"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return err return err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return err return err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to send extension pubsub message (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,9 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type SetExtensionConfigurationSegmentRequest struct { type SetExtensionConfigurationSegmentRequest struct {
@ -39,7 +37,8 @@ type SetExtensionConfigurationSegmentRequest struct {
// The signed JWT must include the role, user_id, and exp fields // The signed JWT must include the role, user_id, and exp fields
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
// The role field must be set to external. // The role field must be set to external.
func (e *Extensions) SetExtensionConfigurationSegment(ctx context.Context, body *SetExtensionConfigurationSegmentRequest) error { func (c *Extensions) SetExtensionConfigurationSegment(ctx context.Context, body *SetExtensionConfigurationSegmentRequest) error {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/configurations"})
r, w := io.Pipe() r, w := io.Pipe()
@ -51,21 +50,16 @@ func (e *Extensions) SetExtensionConfigurationSegment(ctx context.Context, body
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(e.baseUrl, "extensions/configurations"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), r)
if err != nil { if err != nil {
return err return err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return err return err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to set extension configuration segment: %s", res.Status)
}
return nil return nil
} }

View File

@ -3,12 +3,9 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type SetExtensionRequiredConfigurationRequest struct { type SetExtensionRequiredConfigurationRequest struct {
@ -34,8 +31,8 @@ type SetExtensionRequiredConfigurationRequest struct {
// The signed JWT must include the role, user_id, and exp fields // The signed JWT must include the role, user_id, and exp fields
// (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema).
// Set the role field to external and the user_id field to the ID of the user that owns the extension. // Set the role field to external and the user_id field to the ID of the user that owns the extension.
func (e *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broadcasterID string, body *SetExtensionRequiredConfigurationRequest) error { func (c *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broadcasterID string, body *SetExtensionRequiredConfigurationRequest) error {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/required_configuration", RawQuery: "broadcaster_id=" + broadcasterID})
r, w := io.Pipe() r, w := io.Pipe()
@ -47,21 +44,16 @@ func (e *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broa
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(e.baseUrl, "extensions/required_configuration", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), r)
if err != nil { if err != nil {
return err return err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return err return err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to set extension required configuration (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,12 +3,10 @@ package extensions
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"time" "time"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateExtensionBitsProductRequest struct { type UpdateExtensionBitsProductRequest struct {
@ -53,7 +51,9 @@ type UpdateExtensionBitsProductResponse struct {
// If the SKU doesnt exist, the product is added. You may update all fields except the sku field. // If the SKU doesnt exist, the product is added. You may update all fields except the sku field.
// //
// Requires an app access token. The client ID in the app access token must match the extensions client ID. // Requires an app access token. The client ID in the app access token must match the extensions client ID.
func (e *Extensions) UpdateExtensionBitsProduct(ctx context.Context, body *UpdateExtensionBitsProductRequest) (*UpdateExtensionBitsProductResponse, error) { func (c *Extensions) UpdateExtensionBitsProduct(ctx context.Context, body *UpdateExtensionBitsProductRequest) (*UpdateExtensionBitsProductResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "bits/extensions"})
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
@ -64,22 +64,17 @@ func (e *Extensions) UpdateExtensionBitsProduct(ctx context.Context, body *Updat
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(e.baseUrl, "bits/extensions"), r) req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := e.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to update extension bits product (%d)", res.StatusCode)
}
var data UpdateExtensionBitsProductResponse var data UpdateExtensionBitsProductResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package games
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetGamesParams struct { type GetGamesParams struct {
@ -35,25 +34,21 @@ type GetGamesResponse struct {
// You may get up to 100 categories or games by specifying their ID or name. You may specify all IDs, all names, or a combination of IDs and names. If you specify a combination of IDs and names, the total number of IDs and names must not exceed 100. // You may get up to 100 categories or games by specifying their ID or name. You may specify all IDs, all names, or a combination of IDs and names. If you specify a combination of IDs and names, the total number of IDs and names must not exceed 100.
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (g *Games) GetGames(ctx context.Context, params *GetGamesParams) (*GetGamesResponse, error) { func (c *Games) GetGames(ctx context.Context, params *GetGamesParams) (*GetGamesResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "games", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "games", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := g.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get games (%d)", res.StatusCode)
}
var data GetGamesResponse var data GetGamesResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package games
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -38,25 +37,21 @@ type GetTopGamesResponse struct {
// Gets information about all broadcasts on Twitch. // Gets information about all broadcasts on Twitch.
// //
// Requires an app access token or user access token. // Requires an app access token or user access token.
func (g *Games) GetTopGames(ctx context.Context, params *GetTopGamesParams) (*GetTopGamesResponse, error) { func (c *Games) GetTopGames(ctx context.Context, params *GetTopGamesParams) (*GetTopGamesResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "games/top", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "games/top", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := g.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get top games (%d)", res.StatusCode)
}
var data GetTopGamesResponse var data GetTopGamesResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,9 @@ package goals
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetCreatorGoalsResponse struct { type GetCreatorGoalsResponse struct {
@ -84,25 +81,20 @@ type Goal struct {
// using the channel.goal.progress subscription type. Read More: https://dev.twitch.tv/docs/api/goals#requesting-event-notifications // using the channel.goal.progress subscription type. Read More: https://dev.twitch.tv/docs/api/goals#requesting-event-notifications
// //
// Requires a user access token that includes the channel:read:goals scope. // Requires a user access token that includes the channel:read:goals scope.
func (g *Goals) GetCreatorGoals(ctx context.Context, broadcasterID string) (*GetCreatorGoalsResponse, error) { func (c *Goals) GetCreatorGoals(ctx context.Context, broadcasterID string) (*GetCreatorGoalsResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "goals", RawQuery: "broadcaster_id=" + broadcasterID})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "goals", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := g.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get creator goals (%d)", res.StatusCode)
}
var data GetCreatorGoalsResponse var data GetCreatorGoalsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,10 @@ package gueststar
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type AssignGuestStarSlot struct { type AssignGuestStarSlot struct {
@ -35,8 +34,9 @@ type AssignGuestStarSlot struct {
// Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star
func (g *GuestStar) AssignGuestStarSlot(ctx context.Context, params *AssignGuestStarSlot) error { func (g *GuestStar) AssignGuestStarSlot(ctx context.Context, params *AssignGuestStarSlot) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/slot", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/slot", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -47,10 +47,5 @@ func (g *GuestStar) AssignGuestStarSlot(ctx context.Context, params *AssignGuest
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to assign guest star slot (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,8 @@ package gueststar
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type CreateGuestStarSessionResponse struct { type CreateGuestStarSessionResponse struct {
@ -20,9 +17,9 @@ type CreateGuestStarSessionResponse struct {
// Query parameter broadcaster_id must match the user_id in the User-Access token // Query parameter broadcaster_id must match the user_id in the User-Access token
// Requires OAuth Scope: channel:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star
func (g *GuestStar) CreateGuestStarSession(ctx context.Context, broadcasterID string) (*CreateGuestStarSessionResponse, error) { func (g *GuestStar) CreateGuestStarSession(ctx context.Context, broadcasterID string) (*CreateGuestStarSessionResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/session", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/session", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -33,11 +30,6 @@ func (g *GuestStar) CreateGuestStarSession(ctx context.Context, broadcasterID st
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to create guest star session (%d)", res.StatusCode)
}
var data CreateGuestStarSessionResponse var data CreateGuestStarSessionResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,10 @@ package gueststar
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type DeleteGuestStarInviteParams struct { type DeleteGuestStarInviteParams struct {
@ -30,8 +29,9 @@ type DeleteGuestStarInviteParams struct {
// Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star
func (g *GuestStar) DeleteGuestStarInvite(ctx context.Context, params *DeleteGuestStarInviteParams) error { func (g *GuestStar) DeleteGuestStarInvite(ctx context.Context, params *DeleteGuestStarInviteParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/invite", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(g.baseUrl, "guest_star/invite", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -42,10 +42,5 @@ func (g *GuestStar) DeleteGuestStarInvite(ctx context.Context, params *DeleteGue
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to delete guest star invite (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,10 @@ package gueststar
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type DeleteGuestStarSlotParams struct { type DeleteGuestStarSlotParams struct {
@ -28,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,omitempty"` ShouldReinviteGuest *bool `url:"should_reinvite_guest"`
} }
// 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.
@ -37,8 +36,9 @@ type DeleteGuestStarSlotParams struct {
// Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star
func (g *GuestStar) DeleteGuestStarSlot(ctx context.Context, params *DeleteGuestStarSlotParams) error { func (g *GuestStar) DeleteGuestStarSlot(ctx context.Context, params *DeleteGuestStarSlotParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/slot", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(g.baseUrl, "guest_star/slot", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -49,10 +49,5 @@ func (g *GuestStar) DeleteGuestStarSlot(ctx context.Context, params *DeleteGuest
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to delete guest star slot (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,10 @@ package gueststar
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type EndGuestStarSession struct { type EndGuestStarSession struct {
@ -30,8 +29,9 @@ type EndGuestStarSessionResponse struct {
// Requires OAuth Scope: channel:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star
func (g *GuestStar) EndGuestStarSession(ctx context.Context, params *EndGuestStarSession) (*EndGuestStarSessionResponse, error) { func (g *GuestStar) EndGuestStarSession(ctx context.Context, params *EndGuestStarSession) (*EndGuestStarSessionResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/session", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(g.baseUrl, "guest_star/session", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -42,11 +42,6 @@ func (g *GuestStar) EndGuestStarSession(ctx context.Context, params *EndGuestSta
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to end guest star session (%d)", res.StatusCode)
}
var data EndGuestStarSessionResponse var data EndGuestStarSessionResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package gueststar
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetChannelGuestStarSettingsParams struct { type GetChannelGuestStarSettingsParams struct {
@ -29,8 +28,9 @@ type GetChannelGuestStarSettingsResponse struct {
// Requires OAuth Scope: channel:read:guest_star, channel:manage:guest_star, moderator:read:guest_star or moderator:manage:guest_star // Requires OAuth Scope: channel:read:guest_star, channel:manage:guest_star, moderator:read:guest_star or moderator:manage:guest_star
func (g *GuestStar) GetChannelGuestStarSettings(ctx context.Context, params *GetChannelGuestStarSettingsParams) (*GetChannelGuestStarSettingsResponse, error) { func (g *GuestStar) GetChannelGuestStarSettings(ctx context.Context, params *GetChannelGuestStarSettingsParams) (*GetChannelGuestStarSettingsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/channel_settings", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/channel_settings", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -41,11 +41,6 @@ func (g *GuestStar) GetChannelGuestStarSettings(ctx context.Context, params *Get
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get channel guest star settings (%d)", res.StatusCode)
}
var data GetChannelGuestStarSettingsResponse var data GetChannelGuestStarSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package gueststar
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetGuestStarInvitesParams struct { type GetGuestStarInvitesParams struct {
@ -33,8 +32,9 @@ type GetGuestStarInvitesResponse struct {
// Requires OAuth Scope: channel:read:guest_star, channel:manage:guest_star, moderator:read:guest_star or moderator:manage:guest_star // Requires OAuth Scope: channel:read:guest_star, channel:manage:guest_star, moderator:read:guest_star or moderator:manage:guest_star
func (g *GuestStar) GetGuestStarInvites(ctx context.Context, params *GetGuestStarInvitesParams) (*GetGuestStarInvitesResponse, error) { func (g *GuestStar) GetGuestStarInvites(ctx context.Context, params *GetGuestStarInvitesParams) (*GetGuestStarInvitesResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/invites", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/invites", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -45,11 +45,6 @@ func (g *GuestStar) GetGuestStarInvites(ctx context.Context, params *GetGuestSta
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get guest star invites (%d)", res.StatusCode)
}
var data GetGuestStarInvitesResponse var data GetGuestStarInvitesResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package gueststar
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetGuestStarSessionParams struct { type GetGuestStarSessionParams struct {
@ -30,8 +29,9 @@ type GetGuestStarSessionResponse struct {
// Guests must be either invited or assigned a slot within the session // Guests must be either invited or assigned a slot within the session
func (g *GuestStar) GetGuestStarSession(ctx context.Context, params *GetGuestStarSessionParams) (*GetGuestStarSessionResponse, error) { func (g *GuestStar) GetGuestStarSession(ctx context.Context, params *GetGuestStarSessionParams) (*GetGuestStarSessionResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/session", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/session", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -42,11 +42,6 @@ func (g *GuestStar) GetGuestStarSession(ctx context.Context, params *GetGuestSta
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get guest star session (%d)", res.StatusCode)
}
var data GetGuestStarSessionResponse var data GetGuestStarSessionResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,10 @@ package gueststar
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type SendGuestStarInviteParams struct { type SendGuestStarInviteParams struct {
@ -30,8 +29,9 @@ type SendGuestStarInviteParams struct {
// Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star
func (g *GuestStar) SendGuestStarInvite(ctx context.Context, params *SendGuestStarInviteParams) error { func (g *GuestStar) SendGuestStarInvite(ctx context.Context, params *SendGuestStarInviteParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/invite", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/invite", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -42,10 +42,5 @@ func (g *GuestStar) SendGuestStarInvite(ctx context.Context, params *SendGuestSt
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to send guest star invite (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,8 @@ package gueststar
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateChannelGuestStarSettingsRequest struct { type UpdateChannelGuestStarSettingsRequest struct {
@ -41,9 +38,9 @@ type UpdateChannelGuestStarSettingsRequest struct {
// Query parameter broadcaster_id must match the user_id in the User-Access token // Query parameter broadcaster_id must match the user_id in the User-Access token
// Requires OAuth Scope: channel:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star
func (g *GuestStar) UpdateChannelGuestStarSettings(ctx context.Context, BroadcasterID string, body *UpdateChannelGuestStarSettingsRequest) error { func (g *GuestStar) UpdateChannelGuestStarSettings(ctx context.Context, BroadcasterID string, body *UpdateChannelGuestStarSettingsRequest) error {
v := url.Values{"broadcaster_id": {BroadcasterID}} endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/channel_settings", RawQuery: url.Values{"broadcaster_id": {BroadcasterID}}.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(g.baseUrl, "guest_star/channel_settings", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -54,10 +51,5 @@ func (g *GuestStar) UpdateChannelGuestStarSettings(ctx context.Context, Broadcas
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to update channel guest star settings (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,10 @@ package gueststar
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateGuestStarSlot struct { type UpdateGuestStarSlot struct {
@ -33,8 +32,9 @@ type UpdateGuestStarSlot struct {
// Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star
func (g *GuestStar) UpdateGuestStarSlot(ctx context.Context, params *UpdateGuestStarSlot) error { func (g *GuestStar) UpdateGuestStarSlot(ctx context.Context, params *UpdateGuestStarSlot) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/slot", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/slot", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -45,10 +45,5 @@ func (g *GuestStar) UpdateGuestStarSlot(ctx context.Context, params *UpdateGuest
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to update guest star slot (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,10 @@ package gueststar
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateGuestStarSlotSettingsParams struct { type UpdateGuestStarSlotSettingsParams struct {
@ -25,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,omitempty"` IsAudioEnabled *bool `url:"is_audio_enabled"`
// 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,omitempty"` IsVideoEnabled *bool `url:"is_video_enabled"`
// 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,omitempty"` IsLive *bool `url:"is_live"`
// 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,omitempty"` Volume *int `url:"volume"`
} }
// 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.
@ -45,8 +44,9 @@ type UpdateGuestStarSlotSettingsParams struct {
// Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star
func (g *GuestStar) UpdateGuestStarSlotSettings(ctx context.Context, params *UpdateGuestStarSlotSettingsParams) error { func (g *GuestStar) UpdateGuestStarSlotSettings(ctx context.Context, params *UpdateGuestStarSlotSettingsParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/slot_settings", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/slot_settings", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -57,10 +57,5 @@ func (g *GuestStar) UpdateGuestStarSlotSettings(ctx context.Context, params *Upd
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to update guest star slot settings (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,12 +3,11 @@ package hypetrain
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -20,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,omitempty"` First *int `url:"first"`
// The cursor used to get the next page of results. The Pagination object in the response contains the cursors value. // The cursor used to get the next page of results. The Pagination object in the response contains the cursors 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,omitempty"` After *types.Cursor `url:"after"`
} }
type Event struct { type Event struct {
@ -119,8 +118,9 @@ type GetHypeTrainEventsResponse struct {
// Requires a user access token that includes the channel:read:hype_train scope. // Requires a user access token that includes the channel:read:hype_train scope.
func (h *Hypetrain) GetHypeTrainEvents(ctx context.Context, params *GetHypeTrainEventsParams) (*GetHypeTrainEventsResponse, error) { func (h *Hypetrain) GetHypeTrainEvents(ctx context.Context, params *GetHypeTrainEventsParams) (*GetHypeTrainEventsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := h.baseUrl.ResolveReference(&url.URL{Path: "hypetrain/events", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(h.baseUrl, "hypetrain/events", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -131,11 +131,6 @@ func (h *Hypetrain) GetHypeTrainEvents(ctx context.Context, params *GetHypeTrain
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get Hype Train events (%d)", res.StatusCode)
}
var data GetHypeTrainEventsResponse var data GetHypeTrainEventsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,11 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type AddBlockedTermParams struct { type AddBlockedTermParams struct {
@ -43,6 +42,7 @@ type AddBlockedTermResponse struct {
// Requires a user access token that includes the moderator:manage:blocked_terms scope. // Requires a user access token that includes the moderator:manage:blocked_terms scope.
func (m *Moderation) AddBlockedTerm(ctx context.Context, params *AddBlockedTermParams, body *AddBlockedTermRequest) (*AddBlockedTermResponse, error) { func (m *Moderation) AddBlockedTerm(ctx context.Context, params *AddBlockedTermParams, body *AddBlockedTermRequest) (*AddBlockedTermResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/blocked_terms", RawQuery: v.Encode()})
r, w := io.Pipe() r, w := io.Pipe()
@ -54,7 +54,7 @@ func (m *Moderation) AddBlockedTerm(ctx context.Context, params *AddBlockedTermP
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/blocked_terms", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -65,11 +65,6 @@ func (m *Moderation) AddBlockedTerm(ctx context.Context, params *AddBlockedTermP
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to add blocked term (%d)", res.StatusCode)
}
var data AddBlockedTermResponse var data AddBlockedTermResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,10 @@ package moderation
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type AddChannelModeratorParams struct { type AddChannelModeratorParams struct {
@ -24,8 +23,9 @@ type AddChannelModeratorParams struct {
// Requires a user access token that includes the channel:manage:moderators scope. // Requires a user access token that includes the channel:manage:moderators scope.
func (m *Moderation) AddChannelModerator(ctx context.Context, params *AddChannelModeratorParams) error { func (m *Moderation) AddChannelModerator(ctx context.Context, params *AddChannelModeratorParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/moderators", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -36,10 +36,5 @@ func (m *Moderation) AddChannelModerator(ctx context.Context, params *AddChannel
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to add channel moderator (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,10 @@ package moderation
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type AddChannelVIPParams struct { type AddChannelVIPParams struct {
@ -24,8 +23,9 @@ type AddChannelVIPParams struct {
// Requires a user access token that includes the channel:manage:vips scope. // Requires a user access token that includes the channel:manage:vips scope.
func (m *Moderation) AddChannelVIP(ctx context.Context, params *AddChannelVIPParams) error { func (m *Moderation) AddChannelVIP(ctx context.Context, params *AddChannelVIPParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "channels/vips", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "channels/vips", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -36,10 +36,5 @@ func (m *Moderation) AddChannelVIP(ctx context.Context, params *AddChannelVIPPar
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to add channel VIP (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,13 +3,12 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type BanUserParams struct { type BanUserParams struct {
@ -70,6 +69,7 @@ type BanUserResponseData struct {
// Requires a user access token that includes the moderator:manage:banned_users scope. // Requires a user access token that includes the moderator:manage:banned_users scope.
func (m *Moderation) BanUser(ctx context.Context, params *BanUserParams, body *BanUserRequest) (*BanUserResponse, error) { func (m *Moderation) BanUser(ctx context.Context, params *BanUserParams, body *BanUserRequest) (*BanUserResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/bans", RawQuery: v.Encode()})
r, w := io.Pipe() r, w := io.Pipe()
@ -81,7 +81,7 @@ func (m *Moderation) BanUser(ctx context.Context, params *BanUserParams, body *B
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/bans", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -92,11 +92,6 @@ func (m *Moderation) BanUser(ctx context.Context, params *BanUserParams, body *B
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to ban user (%d)", res.StatusCode)
}
var data BanUserResponse var data BanUserResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,8 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url" "net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type CheckAutoModStatusRequest struct { type CheckAutoModStatusRequest struct {
@ -53,25 +50,20 @@ type CheckAutoModStatusResponseData struct {
// The rate limit headers in the response represent the Twitch rate limits and not the above limits. // The rate limit headers in the response represent the Twitch rate limits and not the above limits.
// //
// Requires a user access token that includes the moderation:read scope. // Requires a user access token that includes the moderation:read scope.
func (m *Moderation) CheckAutoModStatus(ctx context.Context, broadcasterID string, params *CheckAutoModStatusRequest) (*CheckAutoModStatusResponse, error) { func (c *Moderation) CheckAutoModStatus(ctx context.Context, broadcasterID string, params *CheckAutoModStatusRequest) (*CheckAutoModStatusResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}} endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "modetation/enforcements/status", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/enforcements/status", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res, err := m.client.Do(req) res, err := c.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to check automod status (%d)", res.StatusCode)
}
var data CheckAutoModStatusResponse var data CheckAutoModStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,10 @@ package moderation
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type DeleteChatMessagesParams struct { type DeleteChatMessagesParams struct {
@ -34,8 +33,9 @@ type DeleteChatMessagesParams struct {
// Requires a user access token that includes the moderator:manage:chat_messages scope. // Requires a user access token that includes the moderator:manage:chat_messages scope.
func (m *Moderation) DeleteChatMessages(ctx context.Context, params *DeleteChatMessagesParams) error { func (m *Moderation) DeleteChatMessages(ctx context.Context, params *DeleteChatMessagesParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/chat", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/chat", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -46,10 +46,5 @@ func (m *Moderation) DeleteChatMessages(ctx context.Context, params *DeleteChatM
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to delete chat messages (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,11 +3,10 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetAutoModSettingsParams struct { type GetAutoModSettingsParams struct {
@ -30,8 +29,9 @@ type GetAutoModSettingsResponse struct {
// Requires a user access token that includes the moderator:read:automod_settings scope. // Requires a user access token that includes the moderator:read:automod_settings scope.
func (m *Moderation) GetAutoModSettings(ctx context.Context, params *GetAutoModSettingsParams) (*GetAutoModSettingsResponse, error) { func (m *Moderation) GetAutoModSettings(ctx context.Context, params *GetAutoModSettingsParams) (*GetAutoModSettingsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/automod/settings", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/automod/settings", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -42,11 +42,6 @@ func (m *Moderation) GetAutoModSettings(ctx context.Context, params *GetAutoModS
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get automod settings (%d)", res.StatusCode)
}
var data GetAutoModSettingsResponse var data GetAutoModSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,11 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"time" "time"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -23,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,omitempty"` UserID []string `url:"user_id"`
// 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,omitempty"` First *int `url:"first"`
// The cursor used to get the next page of results. The Pagination object in the response contains the cursors value. // The cursor used to get the next page of results. The Pagination object in the response contains the cursors 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,omitempty"` After *types.Cursor `url:"after"`
// The cursor used to get the previous page of results. The Pagination object in the response contains the cursors value. // The cursor used to get the previous page of results. The Pagination object in the response contains the cursors 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,omitempty"` Before *types.Cursor `url:"before"`
} }
type GetBannedUsersResponse struct { type GetBannedUsersResponse struct {
@ -83,8 +82,9 @@ type GetBannedUsersResponseData struct {
// Requires a user access token that includes the moderation:read or moderator:manage:banned_users scope. // Requires a user access token that includes the moderation:read or moderator:manage:banned_users scope.
func (m *Moderation) GetBannedUsers(ctx context.Context, params *GetBannedUsersParams) (*GetBannedUsersResponse, error) { func (m *Moderation) GetBannedUsers(ctx context.Context, params *GetBannedUsersParams) (*GetBannedUsersResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/banned", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/banned", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -95,11 +95,6 @@ func (m *Moderation) GetBannedUsers(ctx context.Context, params *GetBannedUsersP
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get banned users (%d)", res.StatusCode)
}
var data GetBannedUsersResponse var data GetBannedUsersResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -22,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,omitempty"` First *int `url:"first"`
// The cursor used to get the next page of results. The Pagination object in the response contains the cursors value. // The cursor used to get the next page of results. The Pagination object in the response contains the cursors value.
After *types.Cursor `url:"after,omitempty"` After *types.Cursor `url:"after"`
} }
type GetBlockedTermsResponse struct { type GetBlockedTermsResponse struct {
@ -44,8 +43,9 @@ type GetBlockedTermsResponse struct {
// Requires a user access token that includes the moderator:read:blocked_terms or moderator:manage:blocked_terms scope. // Requires a user access token that includes the moderator:read:blocked_terms or moderator:manage:blocked_terms scope.
func (m *Moderation) GetBlockedTerms(ctx context.Context, params *GetBlockedTermsParams) (*GetBlockedTermsResponse, error) { func (m *Moderation) GetBlockedTerms(ctx context.Context, params *GetBlockedTermsParams) (*GetBlockedTermsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/blocked_terms", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/blocked_terms", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,11 +56,6 @@ func (m *Moderation) GetBlockedTerms(ctx context.Context, params *GetBlockedTerm
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get blocked terms (%d)", res.StatusCode)
}
var data GetBlockedTermsResponse var data GetBlockedTermsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -16,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 cursors value. // The cursor used to get the next page of results. The Pagination object in the response contains the cursors value.
After *types.Cursor `url:"after,omitempty"` After *types.Cursor `url:"after"`
// 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,omitempty"` First *int `url:"first"`
} }
type GetModeratedChannelsResponse struct { type GetModeratedChannelsResponse struct {
@ -51,8 +50,9 @@ type GetModeratedChannelsResponseData struct {
// Requires OAuth Scope: user:read:moderated_channels // Requires OAuth Scope: user:read:moderated_channels
func (m *Moderation) GetModeratedChannels(ctx context.Context, params *GetModeratedChannelsParams) (*GetModeratedChannelsResponse, error) { func (m *Moderation) GetModeratedChannels(ctx context.Context, params *GetModeratedChannelsParams) (*GetModeratedChannelsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/channels", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/channels", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -63,11 +63,6 @@ func (m *Moderation) GetModeratedChannels(ctx context.Context, params *GetModera
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get moderated channels (%d)", res.StatusCode)
}
var data GetModeratedChannelsResponse var data GetModeratedChannelsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -22,16 +21,16 @@ type GetModeratorsParams struct {
// //
// The returned list includes only the users from the list who are moderators in the broadcasters channel. // The returned list includes only the users from the list who are moderators in the broadcasters 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,omitempty"` UserID []string `url:"user_id"`
// 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,omitempty"` First *int `url:"first"`
// The cursor used to get the next page of results. The Pagination object in the response contains the cursors value. // The cursor used to get the next page of results. The Pagination object in the response contains the cursors 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,omitempty"` After *types.Cursor `url:"after"`
} }
type GetModeratorsResponse struct { type GetModeratorsResponse struct {
@ -61,8 +60,9 @@ type GetModeratorsResponseData struct {
// If your app also adds and removes moderators, you can use the channel:manage:moderators scope instead. // If your app also adds and removes moderators, you can use the channel:manage:moderators scope instead.
func (m *Moderation) GetModerators(ctx context.Context, params *GetModeratorsParams) (*GetModeratorsResponse, error) { func (m *Moderation) GetModerators(ctx context.Context, params *GetModeratorsParams) (*GetModeratorsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/moderators", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -73,11 +73,6 @@ func (m *Moderation) GetModerators(ctx context.Context, params *GetModeratorsPar
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get moderators (%d)", res.StatusCode)
}
var data GetModeratorsResponse var data GetModeratorsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type GetShieldModeStatusParams struct { type GetShieldModeStatusParams struct {
@ -31,8 +30,9 @@ type GetShieldModeStatusResponse struct {
// Requires a user access token that includes the moderator:read:shield_mode or moderator:manage:shield_mode scope. // Requires a user access token that includes the moderator:read:shield_mode or moderator:manage:shield_mode scope.
func (m *Moderation) GetShieldModeStatus(ctx context.Context, params *GetShieldModeStatusParams) (*GetShieldModeStatusResponse, error) { func (m *Moderation) GetShieldModeStatus(ctx context.Context, params *GetShieldModeStatusParams) (*GetShieldModeStatusResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/shield_mode", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/shield_mode", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -43,11 +43,6 @@ func (m *Moderation) GetShieldModeStatus(ctx context.Context, params *GetShieldM
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get shield mode status (%d)", res.StatusCode)
}
var data GetShieldModeStatusResponse var data GetShieldModeStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,11 +3,10 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
"go.fifitido.net/twitch/api/types" "go.fifitido.net/twitch/api/types"
) )
@ -16,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 arent VIPs. // Ignores the ID of those users in the list that arent VIPs.
UserIDs []string `url:"user_id,omitempty"` UserIDs []string `url:"user_id"`
// 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"`
@ -24,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,omitempty"` First *int `url:"first"`
// 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 cursors value. // The Pagination object in the response contains the cursors 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,omitempty"` After *types.Cursor `url:"after"`
} }
type GetVIPsResponse struct { type GetVIPsResponse struct {
@ -59,8 +58,9 @@ type GetVIPsResponseData struct {
// If your app also adds and removes VIP status, you can use the channel:manage:vips scope instead. // If your app also adds and removes VIP status, you can use the channel:manage:vips scope instead.
func (m *Moderation) GetVIPs(ctx context.Context, params GetVIPsParams) (*GetVIPsResponse, error) { func (m *Moderation) GetVIPs(ctx context.Context, params GetVIPsParams) (*GetVIPsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/vips", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/vips", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -69,12 +69,6 @@ func (m *Moderation) GetVIPs(ctx context.Context, params GetVIPsParams) (*GetVIP
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get VIPs (%d)", res.StatusCode)
}
var data GetVIPsResponse var data GetVIPsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {

View File

@ -2,10 +2,8 @@ package moderation
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
) )
type AutoModAction string type AutoModAction string
@ -34,8 +32,9 @@ type ManageHeldAutoModMessagesRequest struct {
// //
// Requires a user access token that includes the moderator:manage:automod scope. // Requires a user access token that includes the moderator:manage:automod scope.
func (m *Moderation) ManageHeldAutoModMessages(ctx context.Context, body *ManageHeldAutoModMessagesRequest) error { func (m *Moderation) ManageHeldAutoModMessages(ctx context.Context, body *ManageHeldAutoModMessagesRequest) error {
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/automod/message"})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/automod/message"), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -46,10 +45,5 @@ func (m *Moderation) ManageHeldAutoModMessages(ctx context.Context, body *Manage
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to manage held AutoMod messages (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,10 @@ package moderation
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type RemoveBlockedTermParams struct { type RemoveBlockedTermParams struct {
@ -26,8 +25,9 @@ type RemoveBlockedTermParams struct {
// Requires a user access token that includes the moderator:manage:blocked_terms scope. // Requires a user access token that includes the moderator:manage:blocked_terms scope.
func (m *Moderation) RemoveBlockedTerm(ctx context.Context, params *RemoveBlockedTermParams) error { func (m *Moderation) RemoveBlockedTerm(ctx context.Context, params *RemoveBlockedTermParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/blocks", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/blocks", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -38,10 +38,5 @@ func (m *Moderation) RemoveBlockedTerm(ctx context.Context, params *RemoveBlocke
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to remove blocked term (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,10 @@ package moderation
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type RemoveChannelModeratorParams struct { type RemoveChannelModeratorParams struct {
@ -24,8 +23,9 @@ type RemoveChannelModeratorParams struct {
// Requires a user access token that includes the channel:manage:moderators scope. // Requires a user access token that includes the channel:manage:moderators scope.
func (m *Moderation) RemoveChannelModerator(ctx context.Context, params *RemoveChannelModeratorParams) error { func (m *Moderation) RemoveChannelModerator(ctx context.Context, params *RemoveChannelModeratorParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/moderators", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -36,10 +36,5 @@ func (m *Moderation) RemoveChannelModerator(ctx context.Context, params *RemoveC
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to remove channel moderator (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,10 @@ package moderation
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type RemoveChannelVIPParams struct { type RemoveChannelVIPParams struct {
@ -27,8 +26,9 @@ type RemoveChannelVIPParams struct {
// Requires a user access token that includes the channel:manage:vips scope. // Requires a user access token that includes the channel:manage:vips scope.
func (m *Moderation) RemoveChannelVIP(ctx context.Context, params *RemoveChannelVIPParams) error { func (m *Moderation) RemoveChannelVIP(ctx context.Context, params *RemoveChannelVIPParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "channels/vips", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "channels/vips", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -39,10 +39,5 @@ func (m *Moderation) RemoveChannelVIP(ctx context.Context, params *RemoveChannel
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to remove channel VIP (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -2,11 +2,10 @@ package moderation
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UnbanUserParams struct { type UnbanUserParams struct {
@ -28,8 +27,9 @@ type UnbanUserParams struct {
// Requires a user access token that includes the moderator:manage:banned_users scope. // Requires a user access token that includes the moderator:manage:banned_users scope.
func (m *Moderation) UnbanUser(ctx context.Context, params *UnbanUserParams) error { func (m *Moderation) UnbanUser(ctx context.Context, params *UnbanUserParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/bans", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/bans", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -40,10 +40,5 @@ func (m *Moderation) UnbanUser(ctx context.Context, params *UnbanUserParams) err
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to unban user (%d)", res.StatusCode)
}
return nil return nil
} }

View File

@ -3,12 +3,11 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateAutoModSettingsParams struct { type UpdateAutoModSettingsParams struct {
@ -79,6 +78,7 @@ type UpdateAutoModSettingsResponse struct {
// Requires a user access token that includes the moderator:manage:automod_settings scope. // Requires a user access token that includes the moderator:manage:automod_settings scope.
func (m *Moderation) UpdateAutoModSettings(ctx context.Context, params *UpdateAutoModSettingsParams, body *UpdateAutoModSettingsRequest) (*UpdateAutoModSettingsResponse, error) { func (m *Moderation) UpdateAutoModSettings(ctx context.Context, params *UpdateAutoModSettingsParams, body *UpdateAutoModSettingsRequest) (*UpdateAutoModSettingsResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/automod/settings", RawQuery: v.Encode()})
r, w := io.Pipe() r, w := io.Pipe()
@ -90,7 +90,7 @@ func (m *Moderation) UpdateAutoModSettings(ctx context.Context, params *UpdateAu
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(m.baseUrl, "moderation/automod/settings", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -101,11 +101,6 @@ func (m *Moderation) UpdateAutoModSettings(ctx context.Context, params *UpdateAu
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to update automod settings (%d)", res.StatusCode)
}
var data UpdateAutoModSettingsResponse var data UpdateAutoModSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,12 +3,11 @@ package moderation
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type UpdateShieldModeStatusParams struct { type UpdateShieldModeStatusParams struct {
@ -38,6 +37,7 @@ type UpdateShieldModeStatusResponse struct {
// Requires a user access token that includes the moderator:manage:shield_mode scope. // Requires a user access token that includes the moderator:manage:shield_mode scope.
func (m *Moderation) UpdateShieldModeStatus(ctx context.Context, params *UpdateShieldModeStatusParams) (*UpdateShieldModeStatusResponse, error) { func (m *Moderation) UpdateShieldModeStatus(ctx context.Context, params *UpdateShieldModeStatusParams) (*UpdateShieldModeStatusResponse, error) {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/shield_mode", RawQuery: v.Encode()})
r, w := io.Pipe() r, w := io.Pipe()
@ -49,7 +49,7 @@ func (m *Moderation) UpdateShieldModeStatus(ctx context.Context, params *UpdateS
} }
}() }()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(m.baseUrl, "moderation/shield_mode", v), r) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -60,11 +60,6 @@ func (m *Moderation) UpdateShieldModeStatus(ctx context.Context, params *UpdateS
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to update shield mode status (%d)", res.StatusCode)
}
var data UpdateShieldModeStatusResponse var data UpdateShieldModeStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -3,40 +3,39 @@ package polls
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io"
"net/http" "net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint" "github.com/google/go-querystring/query"
) )
type CreatePollRequest struct { type CreatePollParams struct {
// The ID of the broadcaster thats running the poll. This ID must match the user ID in the user access token. // The ID of the broadcaster thats running the poll. This ID must match the user ID in the user access token.
BroadcasterID string `json:"broadcaster_id"` BroadcasterID string `url:"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 `json:"title"` Title string `url:"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 `json:"choices"` Choices []CreateChoice `url:"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 `json:"duration"` Duration int `url:"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 `json:"channel_points_voting_enabled"` ChannelPointsVotingEnabled bool `url:"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 `json:"channel_points_per_vote"` ChannelPointsPerVote int `url:"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 `json:"title"` Title string `url:"title"`
} }
type CreatePollResponse struct { type CreatePollResponse struct {
@ -49,18 +48,11 @@ type CreatePollResponse struct {
// The poll begins as soon as its created. You may run only one poll at a time. // The poll begins as soon as its 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, body *CreatePollRequest) (*CreatePollResponse, error) { func (p *Polls) CreatePoll(ctx context.Context, params *CreatePollParams) (*CreatePollResponse, error) {
r, w := io.Pipe() v, _ := query.Values(params)
endpoint := p.baseUrl.ResolveReference(&url.URL{Path: "polls", RawQuery: v.Encode()})
go func() { req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err := json.NewEncoder(w).Encode(body); err != nil {
w.CloseWithError(err)
} else {
w.Close()
}
}()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(p.baseUrl, "polls"), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -71,11 +63,6 @@ func (p *Polls) CreatePoll(ctx context.Context, body *CreatePollRequest) (*Creat
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to create poll (%d)", res.StatusCode)
}
var data CreatePollResponse var data CreatePollResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil { if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err return nil, err

View File

@ -2,11 +2,10 @@ package polls
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/url"
"github.com/google/go-querystring/query" "github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
) )
type EndPollParams struct { type EndPollParams struct {
@ -30,8 +29,9 @@ type EndPollParams struct {
// 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) EndPoll(ctx context.Context, params *EndPollParams) error { func (p *Polls) EndPoll(ctx context.Context, params *EndPollParams) error {
v, _ := query.Values(params) v, _ := query.Values(params)
endpoint := p.baseUrl.ResolveReference(&url.URL{Path: "polls", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(p.baseUrl, "polls", v), nil) req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), nil)
if err != nil { if err != nil {
return err return err
} }
@ -42,10 +42,5 @@ func (p *Polls) EndPoll(ctx context.Context, params *EndPollParams) error {
} }
defer res.Body.Close() defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to end poll (%d)", res.StatusCode)
}
return nil return nil
} }

Some files were not shown because too many files have changed in this diff Show More