2024-02-27 22:13:57 -05:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/ads"
|
|
|
|
"go.fifitido.net/twitch/api/analytics"
|
|
|
|
"go.fifitido.net/twitch/api/bits"
|
2024-02-28 14:03:24 -05:00
|
|
|
"go.fifitido.net/twitch/api/ccls"
|
2024-02-27 22:13:57 -05:00
|
|
|
"go.fifitido.net/twitch/api/channelpoints"
|
|
|
|
"go.fifitido.net/twitch/api/channels"
|
2024-02-27 22:26:57 -05:00
|
|
|
"go.fifitido.net/twitch/api/charity"
|
2024-02-28 10:30:20 -05:00
|
|
|
"go.fifitido.net/twitch/api/chat"
|
2024-02-28 13:50:07 -05:00
|
|
|
"go.fifitido.net/twitch/api/conduit"
|
2024-02-28 14:25:19 -05:00
|
|
|
"go.fifitido.net/twitch/api/entitlements"
|
2024-02-27 22:13:57 -05:00
|
|
|
"go.fifitido.net/twitch/api/eventsub"
|
2024-03-02 22:45:59 -05:00
|
|
|
"go.fifitido.net/twitch/api/extensions"
|
2024-03-02 22:54:58 -05:00
|
|
|
"go.fifitido.net/twitch/api/games"
|
2024-03-02 23:04:11 -05:00
|
|
|
"go.fifitido.net/twitch/api/goals"
|
2024-03-03 14:09:31 -05:00
|
|
|
"go.fifitido.net/twitch/api/gueststar"
|
2024-03-03 14:16:33 -05:00
|
|
|
"go.fifitido.net/twitch/api/hypetrain"
|
2024-03-03 15:14:59 -05:00
|
|
|
"go.fifitido.net/twitch/api/moderation"
|
2024-03-03 15:27:37 -05:00
|
|
|
"go.fifitido.net/twitch/api/polls"
|
2024-03-03 15:50:12 -05:00
|
|
|
"go.fifitido.net/twitch/api/predictions"
|
2024-03-03 16:00:12 -05:00
|
|
|
"go.fifitido.net/twitch/api/raids"
|
2024-03-03 16:30:10 -05:00
|
|
|
"go.fifitido.net/twitch/api/schedule"
|
2024-03-03 16:47:48 -05:00
|
|
|
"go.fifitido.net/twitch/api/search"
|
2024-03-03 17:34:18 -05:00
|
|
|
"go.fifitido.net/twitch/api/streams"
|
2024-03-03 17:47:11 -05:00
|
|
|
"go.fifitido.net/twitch/api/subscriptions"
|
2024-03-03 18:00:22 -05:00
|
|
|
"go.fifitido.net/twitch/api/teams"
|
2024-03-03 18:34:26 -05:00
|
|
|
"go.fifitido.net/twitch/api/users"
|
2024-03-03 21:41:49 -05:00
|
|
|
"go.fifitido.net/twitch/api/videos"
|
2024-03-03 21:46:50 -05:00
|
|
|
"go.fifitido.net/twitch/api/whispers"
|
2024-03-04 18:14:38 -05:00
|
|
|
"go.fifitido.net/twitch/auth"
|
|
|
|
"golang.org/x/oauth2"
|
2024-02-27 22:13:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const HelixBaseUrl = "https://api.twitch.tv/helix"
|
|
|
|
|
|
|
|
type API struct {
|
2024-03-07 19:06:02 -05:00
|
|
|
client *http.Client
|
|
|
|
baseUrl *url.URL
|
2024-03-08 13:08:54 -05:00
|
|
|
Auth *auth.Auth
|
2024-02-27 22:13:57 -05:00
|
|
|
|
|
|
|
Ads *ads.Ads
|
|
|
|
Analytics *analytics.Analytics
|
|
|
|
Bits *bits.Bits
|
|
|
|
Channels *channels.Channels
|
|
|
|
ChannelPoints *channelpoints.ChannelPoints
|
2024-02-27 22:26:57 -05:00
|
|
|
Charity *charity.Charity
|
2024-02-28 10:30:20 -05:00
|
|
|
Chat *chat.Chat
|
2024-02-28 13:50:07 -05:00
|
|
|
Conduit *conduit.Conduit
|
2024-02-28 14:03:24 -05:00
|
|
|
CCLS *ccls.CCLS
|
2024-02-28 14:25:19 -05:00
|
|
|
Entitlements *entitlements.Entitlements
|
2024-03-02 22:45:59 -05:00
|
|
|
Extensions *extensions.Extensions
|
2024-02-27 22:13:57 -05:00
|
|
|
EventSub *eventsub.EventSub
|
2024-03-02 22:54:58 -05:00
|
|
|
Games *games.Games
|
2024-03-02 23:04:11 -05:00
|
|
|
Goals *goals.Goals
|
2024-03-03 14:09:31 -05:00
|
|
|
GuestStar *gueststar.GuestStar
|
2024-03-03 14:16:33 -05:00
|
|
|
Hypetrain *hypetrain.Hypetrain
|
2024-03-03 15:14:59 -05:00
|
|
|
Moderation *moderation.Moderation
|
2024-03-03 15:27:37 -05:00
|
|
|
Polls *polls.Polls
|
2024-03-03 15:50:12 -05:00
|
|
|
Predictions *predictions.Predictions
|
2024-03-03 16:00:12 -05:00
|
|
|
Raids *raids.Raids
|
2024-03-03 16:30:10 -05:00
|
|
|
Schedule *schedule.Schedule
|
2024-03-03 16:47:48 -05:00
|
|
|
Search *search.Search
|
2024-03-03 17:34:18 -05:00
|
|
|
Streams *streams.Streams
|
2024-03-03 17:47:11 -05:00
|
|
|
Subscriptions *subscriptions.Subscriptions
|
2024-03-03 18:00:22 -05:00
|
|
|
Teams *teams.Teams
|
2024-03-03 18:34:26 -05:00
|
|
|
Users *users.Users
|
2024-03-03 21:41:49 -05:00
|
|
|
Videos *videos.Videos
|
2024-03-03 21:46:50 -05:00
|
|
|
Whispers *whispers.Whispers
|
2024-02-27 22:13:57 -05:00
|
|
|
}
|
|
|
|
|
2024-03-08 13:08:54 -05:00
|
|
|
func New(client *http.Client, baseUrl *url.URL, authClient *auth.Auth) *API {
|
2024-02-27 22:13:57 -05:00
|
|
|
return &API{
|
2024-03-07 19:06:02 -05:00
|
|
|
client: client,
|
|
|
|
baseUrl: baseUrl,
|
|
|
|
Auth: authClient,
|
2024-02-27 22:13:57 -05:00
|
|
|
|
|
|
|
Ads: ads.New(client, baseUrl),
|
|
|
|
Analytics: analytics.New(client, baseUrl),
|
|
|
|
Bits: bits.New(client, baseUrl),
|
|
|
|
Channels: channels.New(client, baseUrl),
|
|
|
|
ChannelPoints: channelpoints.New(client, baseUrl),
|
2024-02-27 22:26:57 -05:00
|
|
|
Charity: charity.New(client, baseUrl),
|
2024-02-28 10:30:20 -05:00
|
|
|
Chat: chat.New(client, baseUrl),
|
2024-02-28 13:50:07 -05:00
|
|
|
Conduit: conduit.New(client, baseUrl),
|
2024-02-28 14:03:24 -05:00
|
|
|
CCLS: ccls.New(client, baseUrl),
|
2024-02-28 14:25:19 -05:00
|
|
|
Entitlements: entitlements.New(client, baseUrl),
|
2024-03-02 22:45:59 -05:00
|
|
|
Extensions: extensions.New(client, baseUrl),
|
2024-02-27 22:13:57 -05:00
|
|
|
EventSub: eventsub.New(client, baseUrl),
|
2024-03-02 22:54:58 -05:00
|
|
|
Games: games.New(client, baseUrl),
|
2024-03-02 23:04:11 -05:00
|
|
|
Goals: goals.New(client, baseUrl),
|
2024-03-03 14:09:31 -05:00
|
|
|
GuestStar: gueststar.New(client, baseUrl),
|
2024-03-03 14:16:33 -05:00
|
|
|
Hypetrain: hypetrain.New(client, baseUrl),
|
2024-03-03 15:14:59 -05:00
|
|
|
Moderation: moderation.New(client, baseUrl),
|
2024-03-03 15:27:37 -05:00
|
|
|
Polls: polls.New(client, baseUrl),
|
2024-03-03 15:50:12 -05:00
|
|
|
Predictions: predictions.New(client, baseUrl),
|
2024-03-03 16:00:12 -05:00
|
|
|
Raids: raids.New(client, baseUrl),
|
2024-03-03 16:30:10 -05:00
|
|
|
Schedule: schedule.New(client, baseUrl),
|
2024-03-03 16:47:48 -05:00
|
|
|
Search: search.New(client, baseUrl),
|
2024-03-03 17:34:18 -05:00
|
|
|
Streams: streams.New(client, baseUrl),
|
2024-03-03 17:47:11 -05:00
|
|
|
Subscriptions: subscriptions.New(client, baseUrl),
|
2024-03-03 18:00:22 -05:00
|
|
|
Teams: teams.New(client, baseUrl),
|
2024-03-03 18:34:26 -05:00
|
|
|
Users: users.New(client, baseUrl),
|
2024-03-03 21:41:49 -05:00
|
|
|
Videos: videos.New(client, baseUrl),
|
2024-03-03 21:46:50 -05:00
|
|
|
Whispers: whispers.New(client, baseUrl),
|
2024-02-27 22:13:57 -05:00
|
|
|
}
|
|
|
|
}
|
2024-03-03 16:30:10 -05:00
|
|
|
|
2024-03-07 19:06:02 -05:00
|
|
|
func NewDefault(clientId, clientSecret, redirectUri string) *API {
|
|
|
|
client := &http.Client{
|
|
|
|
Transport: &apiTransport{
|
|
|
|
clientId: clientId,
|
|
|
|
},
|
|
|
|
}
|
2024-03-03 16:50:13 -05:00
|
|
|
baseUrl, _ := url.Parse(HelixBaseUrl)
|
2024-03-08 13:08:54 -05:00
|
|
|
authClient := auth.New(clientId, clientSecret, redirectUri)
|
2024-03-03 16:30:10 -05:00
|
|
|
|
2024-03-04 18:14:38 -05:00
|
|
|
return New(client, baseUrl, authClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *API) WithClient(client *http.Client) *API {
|
2024-03-07 19:06:02 -05:00
|
|
|
return New(client, a.baseUrl, a.Auth)
|
2024-03-04 18:14:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *API) WithAuthToken(token *auth.Token) *API {
|
|
|
|
return a.WithClient(&http.Client{
|
|
|
|
Transport: &oauth2.Transport{
|
2024-03-07 19:06:02 -05:00
|
|
|
Source: a.Auth.TokenSource(token),
|
2024-03-04 18:14:38 -05:00
|
|
|
Base: a.client.Transport,
|
|
|
|
},
|
|
|
|
})
|
2024-03-03 16:30:10 -05:00
|
|
|
}
|