From fce339d8c51330aa82c7d7f8404fd4271d3668f4 Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Thu, 7 Mar 2024 20:52:42 -0500 Subject: [PATCH] fix: Create endpoint make utility to build endpoints --- api/ads/get_ad_schedule.go | 10 ++++++---- api/ads/snooze_next_ad.go | 6 ++++-- api/ads/start_commercial.go | 10 +++++----- api/analytics/get_extension_analytics.go | 9 ++++----- api/analytics/get_game_analytics.go | 9 ++++----- api/bits/get_bits_leaderboard.go | 5 ++--- api/bits/get_cheermotes.go | 6 ++++-- api/bits/get_extension_transactions.go | 5 ++--- api/ccls/get_content_classification_labels.go | 5 ++--- api/channelpoints/create_custom_rewards.go | 6 ++++-- api/channelpoints/delete_custom_reward.go | 5 ++--- api/channelpoints/get_custom_reward.go | 5 ++--- .../get_custom_reward_redemption.go | 5 ++--- api/channelpoints/update_custom_reward.go | 5 ++--- api/channelpoints/update_redemption_status.go | 5 ++--- api/channels/get_channel_editors.go | 6 ++++-- api/channels/get_channel_followers.go | 5 ++--- api/channels/get_channel_information.go | 5 ++--- api/channels/get_followed_channels.go | 5 ++--- api/channels/modify_channel_information.go | 5 +++-- api/charity/get_charity_campaign.go | 5 +++-- api/charity/get_charity_campaign_donations.go | 5 ++--- api/chat/get_channel_chat_badges.go | 6 ++++-- api/chat/get_channel_emotes.go | 6 ++++-- api/chat/get_chat_settings.go | 5 ++--- api/chat/get_chatters.go | 5 ++--- api/chat/get_emote_sets.go | 5 ++--- api/chat/get_global_chat_badges.go | 7 +++---- api/chat/get_global_emotes.go | 7 +++---- api/chat/get_user_chat_color.go | 5 ++--- api/chat/send_chat_announcement.go | 5 ++--- api/chat/send_chat_message.go | 7 +++---- api/chat/send_shoutout.go | 5 ++--- api/chat/update_chat_settings.go | 5 ++--- api/chat/update_user_chat_color.go | 5 ++--- api/conduit/create_conduits.go | 7 +++---- api/conduit/delete_conduit.go | 6 ++++-- api/conduit/get_conduit_shards.go | 5 ++--- api/conduit/get_conduits.go | 7 +++---- api/conduit/update_conduit_shards.go | 6 ++---- api/conduit/update_conduits.go | 7 +++---- api/endpoint/endpoint.go | 19 +++++++++++++++++++ api/entitlements/get_drops_entitlements.go | 9 ++++----- api/entitlements/update_drops_entitlements.go | 11 +++++------ api/eventsub/create_eventsub_subscription.go | 6 +++--- api/eventsub/delete_eventsub_subscription.go | 6 ++++-- api/eventsub/get_eventsub_subscriptions.go | 5 ++--- api/extensions/create_extension_secret.go | 9 ++++----- api/extensions/get_extension_bits_products.go | 9 ++++----- .../get_extension_configuration_segment.go | 9 ++++----- api/extensions/get_extension_live_channels.go | 9 ++++----- api/extensions/get_extension_secrets.go | 10 ++++++---- api/extensions/get_extensions.go | 9 ++++----- api/extensions/get_released_extensions.go | 9 ++++----- api/extensions/send_extension_chat_message.go | 10 ++++++---- .../send_extension_pubsub_message.go | 11 +++++------ .../set_extension_configuration_segment.go | 10 +++++----- .../set_extension_required_configuration.go | 10 ++++++---- .../update_extension_bits_product.go | 11 +++++------ api/games/get_games.go | 9 ++++----- api/games/get_top_games.go | 9 ++++----- api/goals/get_creator_goals.go | 10 ++++++---- api/gueststar/assign_gueststar_slot.go | 5 ++--- api/gueststar/create_gueststar_session.go | 6 ++++-- api/gueststar/delete_gueststar_invite.go | 5 ++--- api/gueststar/delete_gueststar_slot.go | 5 ++--- api/gueststar/end_gueststar_session.go | 5 ++--- .../get_channel_gueststar_settings.go | 5 ++--- api/gueststar/get_gueststar_invites.go | 5 ++--- api/gueststar/get_gueststar_session.go | 5 ++--- api/gueststar/send_gueststar_invite.go | 5 ++--- .../update_channel_gueststar_settings.go | 6 ++++-- api/gueststar/update_gueststar_slot.go | 5 ++--- .../update_gueststar_slot_settings.go | 5 ++--- api/hypetrain/get_hypetrain_events.go | 5 ++--- api/moderation/add_blocked_term.go | 5 ++--- api/moderation/add_channel_moderator.go | 5 ++--- api/moderation/add_channel_vip.go | 5 ++--- api/moderation/ban_user.go | 5 ++--- api/moderation/check_automod_status.go | 10 ++++++---- api/moderation/delete_chat_messages.go | 5 ++--- api/moderation/get_automod_settings.go | 5 ++--- api/moderation/get_banned_users.go | 5 ++--- api/moderation/get_blocked_terms.go | 5 ++--- api/moderation/get_moderated_channels.go | 5 ++--- api/moderation/get_moderators.go | 5 ++--- api/moderation/get_shield_mode_status.go | 5 ++--- api/moderation/get_vips.go | 5 ++--- .../manage_held_automod_messages.go | 6 +++--- api/moderation/remove_blocked_term.go | 5 ++--- api/moderation/remove_channel_moderator.go | 5 ++--- api/moderation/remove_channel_vip.go | 5 ++--- api/moderation/unban_user.go | 5 ++--- api/moderation/update_automod_settings.go | 5 ++--- api/moderation/update_shield_mode_status.go | 5 ++--- api/polls/create_poll.go | 7 +++---- api/polls/end_poll.go | 5 ++--- api/polls/get_polls.go | 5 ++--- api/predictions/create_prediction.go | 9 ++++----- api/predictions/end_prediction.go | 9 ++++----- api/predictions/get_predictions.go | 9 ++++----- api/raids/cancel_a_raid.go | 10 ++++++---- api/raids/start_a_raid.go | 9 ++++----- .../create_channel_stream_schedule_segment.go | 6 ++++-- .../delete_channel_stream_schedule_segment.go | 5 ++--- api/schedule/get_channel_icalendar.go | 9 ++++----- api/schedule/get_channel_stream_schedule.go | 5 ++--- .../update_channel_stream_schedule.go | 5 ++--- .../update_channel_stream_schedule_segment.go | 5 ++--- api/search/search_categories.go | 9 ++++----- api/search/search_channels.go | 9 ++++----- api/streams/create_stream_marker.go | 7 +++---- api/streams/get_followed_streams.go | 5 ++--- api/streams/get_stream_key.go | 6 ++++-- api/streams/get_stream_markers.go | 5 ++--- api/streams/get_streams.go | 5 ++--- api/subscriptions/check_user_subscription.go | 5 ++--- .../get_broadcaster_subscriptions.go | 9 ++++----- api/teams/get_channel_teams.go | 10 ++++++---- api/teams/get_teams.go | 9 ++++----- api/users/block_user.go | 5 ++--- api/users/get_user_active_extensions.go | 5 ++--- api/users/get_user_block_list.go | 5 ++--- api/users/get_user_extensions.go | 7 +++---- api/users/get_users.go | 7 ++----- api/users/unblock_user.go | 6 ++++-- api/users/update_user.go | 5 ++--- api/users/update_user_extensions.go | 7 +++---- api/videos/delete_videos.go | 10 ++++++---- api/videos/get_videos.go | 9 ++++----- api/whispers/send_whisper.go | 5 ++--- 131 files changed, 412 insertions(+), 452 deletions(-) create mode 100644 api/endpoint/endpoint.go diff --git a/api/ads/get_ad_schedule.go b/api/ads/get_ad_schedule.go index 9341019..a007bd4 100644 --- a/api/ads/get_ad_schedule.go +++ b/api/ads/get_ad_schedule.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "time" + + "go.fifitido.net/twitch/api/endpoint" ) type GetAdScheduleResponse struct { @@ -39,15 +41,15 @@ type GetAdScheduleData struct { // // 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. -func (e *Ads) GetAdSchedule(ctx context.Context, broadcasterID string) (*GetAdScheduleResponse, error) { - endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "channels/ads", RawQuery: "broadcaster_id=" + broadcasterID}) +func (a *Ads) GetAdSchedule(ctx context.Context, broadcasterID string) (*GetAdScheduleResponse, error) { + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(a.baseUrl, "channels/ads", v), nil) if err != nil { return nil, err } - res, err := e.client.Do(req) + res, err := a.client.Do(req) if err != nil { return nil, err } diff --git a/api/ads/snooze_next_ad.go b/api/ads/snooze_next_ad.go index 3a867dc..6d6346b 100644 --- a/api/ads/snooze_next_ad.go +++ b/api/ads/snooze_next_ad.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "time" + + "go.fifitido.net/twitch/api/endpoint" ) type SnoozeNextAdResponse struct { @@ -31,9 +33,9 @@ type SnoozeNextAdData struct { // 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. func (e *Ads) SnoozeNextAd(ctx context.Context, broadcasterID string) (*SnoozeNextAdResponse, error) { - endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "channels/ads/schedule/snooze", RawQuery: "broadcaster_id=" + broadcasterID}) + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequest(http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequest(http.MethodPost, endpoint.Make(e.baseUrl, "channels/ads/schedule/snooze", v), nil) if err != nil { return nil, err } diff --git a/api/ads/start_commercial.go b/api/ads/start_commercial.go index 799d895..69fff10 100644 --- a/api/ads/start_commercial.go +++ b/api/ads/start_commercial.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type StartCommercialRequest struct { @@ -42,8 +43,7 @@ type StartCommercialData struct { // NOTE: Only the broadcaster may start a commercial; the broadcaster’s editors and moderators may not start commercials on behalf of the broadcaster. // // Requires a user access token that includes the channel:edit:commercial scope. -func (e *Ads) StartCommercial(ctx context.Context, body *StartCommercialRequest) (*StartCommercialResponse, error) { - endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "channels/commercial"}) +func (a *Ads) StartCommercial(ctx context.Context, body *StartCommercialRequest) (*StartCommercialResponse, error) { r, w := io.Pipe() @@ -55,12 +55,12 @@ func (e *Ads) StartCommercial(ctx context.Context, body *StartCommercialRequest) } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(a.baseUrl, "channels/commercial"), r) if err != nil { return nil, err } - res, err := e.client.Do(req) + res, err := a.client.Do(req) if err != nil { return nil, err } diff --git a/api/analytics/get_extension_analytics.go b/api/analytics/get_extension_analytics.go index 1248295..fbd18bb 100644 --- a/api/analytics/get_extension_analytics.go +++ b/api/analytics/get_extension_analytics.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -81,16 +81,15 @@ type ExtensionAnalyticsReport struct { // Learn More: https://dev.twitch.tv/docs/insights // // Requires a user access token that includes the analytics:read:extensions scope. -func (e *Analytics) GetExtensionAnalytics(ctx context.Context, params GetExtensionAnalyticsParams) (*GetExtensionAnalyticsResponse, error) { +func (a *Analytics) GetExtensionAnalytics(ctx context.Context, params GetExtensionAnalyticsParams) (*GetExtensionAnalyticsResponse, error) { v, _ := query.Values(params) - endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "analytics/extensions", RawQuery: v.Encode()}) - req, err := http.NewRequest(http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequest(http.MethodGet, endpoint.Make(a.baseUrl, "analytics/extensions", v), nil) if err != nil { return nil, err } - res, err := e.client.Do(req) + res, err := a.client.Do(req) if err != nil { return nil, err } diff --git a/api/analytics/get_game_analytics.go b/api/analytics/get_game_analytics.go index 0624c72..55c861c 100644 --- a/api/analytics/get_game_analytics.go +++ b/api/analytics/get_game_analytics.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -82,16 +82,15 @@ type GameAnalyticsReport struct { // Learn more: https://dev.twitch.tv/docs/insights // // Requires a user access token that includes the analytics:read:games scope. -func (e *Analytics) GetGameAnalytics(ctx context.Context, params GetGameAnalyticsParams) (*GetGameAnalyticsResponse, error) { +func (a *Analytics) GetGameAnalytics(ctx context.Context, params GetGameAnalyticsParams) (*GetGameAnalyticsResponse, error) { v, _ := query.Values(params) - endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "analytics/games", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(a.baseUrl, "analytics/games", v), nil) if err != nil { return nil, err } - res, err := e.client.Do(req) + res, err := a.client.Do(req) if err != nil { return nil, err } diff --git a/api/bits/get_bits_leaderboard.go b/api/bits/get_bits_leaderboard.go index e091897..d60e86d 100644 --- a/api/bits/get_bits_leaderboard.go +++ b/api/bits/get_bits_leaderboard.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -71,9 +71,8 @@ type LeaderboardEntry struct { // Requires a user access token that includes the bits:read scope. func (b *Bits) GetBitsLeaderboard(ctx context.Context, params *GetBitsLeaderboardParams) (*GetBitsLeaderboardResponse, error) { v, _ := query.Values(params) - endpoint := b.baseUrl.ResolveReference(&url.URL{Path: "bits/leaderboard", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(b.baseUrl, "bits/leaderboard", v), nil) if err != nil { return nil, err } diff --git a/api/bits/get_cheermotes.go b/api/bits/get_cheermotes.go index 5baf726..5151499 100644 --- a/api/bits/get_cheermotes.go +++ b/api/bits/get_cheermotes.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "time" + + "go.fifitido.net/twitch/api/endpoint" ) type GetCheermotesResponse struct { @@ -83,9 +85,9 @@ type CheermoteImageSizes struct { // // Requires an app access token or user access token. func (b *Bits) GetCheermotes(ctx context.Context, broadcasterID string) (*GetCheermotesResponse, error) { - endpoint := b.baseUrl.ResolveReference(&url.URL{Path: "bits/cheermotes", RawQuery: "broadcaster_id=" + broadcasterID}) + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(b.baseUrl, "bits/cheermotes", v), nil) if err != nil { return nil, err } diff --git a/api/bits/get_extension_transactions.go b/api/bits/get_extension_transactions.go index 646a708..91fdc0d 100644 --- a/api/bits/get_extension_transactions.go +++ b/api/bits/get_extension_transactions.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -98,9 +98,8 @@ type ProductDataCost struct { // Requires an app access token. func (b *Bits) GetExtensionTransactions(ctx context.Context, params *GetExtensionTransactionsParams) (*GetExtensionTransactionsResponse, error) { v, _ := query.Values(params) - endpoint := b.baseUrl.ResolveReference(&url.URL{Path: "extensions/transactions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(b.baseUrl, "extensions/transactions", v), nil) if err != nil { return nil, err } diff --git a/api/ccls/get_content_classification_labels.go b/api/ccls/get_content_classification_labels.go index 67c24ae..6c111ed 100644 --- a/api/ccls/get_content_classification_labels.go +++ b/api/ccls/get_content_classification_labels.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -39,9 +39,8 @@ type ContentClassificationLabelData struct { // Requires an app access token or user access token. func (c *CCLS) GetContentClassificationLabels(ctx context.Context, params GetContentClassificationLabelsParams) (*GetContentClassificationLabelsResponse, error) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "content_classification_labels", v), nil) if err != nil { return nil, err } diff --git a/api/channelpoints/create_custom_rewards.go b/api/channelpoints/create_custom_rewards.go index e7eb57d..b56304a 100644 --- a/api/channelpoints/create_custom_rewards.go +++ b/api/channelpoints/create_custom_rewards.go @@ -7,6 +7,8 @@ import ( "io" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type CreateCustomRewardsRequest struct { @@ -71,7 +73,7 @@ type CreateCustomRewardsResponse struct { // // 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) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards", RawQuery: "broadcaster_id=" + broadcastID}) + v := url.Values{"broadcaster_id": {broadcastID}} r, w := io.Pipe() @@ -83,7 +85,7 @@ func (c *ChannelPoints) CreateCustomRewards(ctx context.Context, broadcastID str } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), r) if err != nil { return nil, err } diff --git a/api/channelpoints/delete_custom_reward.go b/api/channelpoints/delete_custom_reward.go index a8848e4..f2e3df4 100644 --- a/api/channelpoints/delete_custom_reward.go +++ b/api/channelpoints/delete_custom_reward.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type DeleteCustomRewardParams struct { @@ -25,9 +25,8 @@ type DeleteCustomRewardParams struct { // Requires a user access token that includes the channel:manage:redemptions scope. func (c *ChannelPoints) DeleteCustomReward(ctx context.Context, params *DeleteCustomRewardParams) error { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), nil) if err != nil { return err } diff --git a/api/channelpoints/get_custom_reward.go b/api/channelpoints/get_custom_reward.go index 118b8ca..5349186 100644 --- a/api/channelpoints/get_custom_reward.go +++ b/api/channelpoints/get_custom_reward.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetCustomRewardParams struct { @@ -38,9 +38,8 @@ type GetCustomRewardResponse struct { // 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) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), nil) if err != nil { return nil, err } diff --git a/api/channelpoints/get_custom_reward_redemption.go b/api/channelpoints/get_custom_reward_redemption.go index a690630..b202263 100644 --- a/api/channelpoints/get_custom_reward_redemption.go +++ b/api/channelpoints/get_custom_reward_redemption.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -54,9 +54,8 @@ type GetCustomRewardRedemptionResponse struct { // 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) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channel_points/custom_rewards/redemptions", v), nil) if err != nil { return nil, err } diff --git a/api/channelpoints/update_custom_reward.go b/api/channelpoints/update_custom_reward.go index 71381e7..c019e0a 100644 --- a/api/channelpoints/update_custom_reward.go +++ b/api/channelpoints/update_custom_reward.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateCustomRewardParams struct { @@ -83,7 +83,6 @@ type UpdateCustomRewardResponse struct { // 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) { v, _ := query.Values(body) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -95,7 +94,7 @@ func (c *ChannelPoints) UpdateCustomReward(ctx context.Context, params *UpdateCu } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "channel_points/custom_rewards", v), r) if err != nil { return nil, err } diff --git a/api/channelpoints/update_redemption_status.go b/api/channelpoints/update_redemption_status.go index 765dd4b..b2db551 100644 --- a/api/channelpoints/update_redemption_status.go +++ b/api/channelpoints/update_redemption_status.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateRedemptionStatusParams struct { @@ -43,7 +43,6 @@ type UpdateRedemptionStatusResponse struct { // 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) { v, _ := query.Values(body) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channel_points/custom_rewards/redemptions", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -55,7 +54,7 @@ func (c *ChannelPoints) UpdateRedemptionStatus(ctx context.Context, params *Upda } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "channel_points/custom_rewards/redemptions", v), r) if err != nil { return nil, err } diff --git a/api/channels/get_channel_editors.go b/api/channels/get_channel_editors.go index 597e128..0ee5a39 100644 --- a/api/channels/get_channel_editors.go +++ b/api/channels/get_channel_editors.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "time" + + "go.fifitido.net/twitch/api/endpoint" ) type GetChannelEditorsResponse struct { @@ -29,9 +31,9 @@ type ChannelEditor struct { // // Requires a user access token that includes the channel:read:editors scope. func (c *Channels) GetChannelEditors(ctx context.Context, broadcasterID string) (*GetChannelEditorsResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels/editors", RawQuery: "broadcaster_id=" + broadcasterID}) + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channels/editors", v), nil) if err != nil { return nil, err } diff --git a/api/channels/get_channel_followers.go b/api/channels/get_channel_followers.go index d080f84..8750986 100644 --- a/api/channels/get_channel_followers.go +++ b/api/channels/get_channel_followers.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -72,9 +72,8 @@ type ChannelFollower struct { // only the total follower count will be included in the response. func (c *Channels) GetChannelFollowers(ctx context.Context, params *GetChannelFollowersParams) (*GetChannelFollowersResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels/followers", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channels/followers", v), nil) if err != nil { return nil, err } diff --git a/api/channels/get_channel_information.go b/api/channels/get_channel_information.go index 28e2641..1ba7e05 100644 --- a/api/channels/get_channel_information.go +++ b/api/channels/get_channel_information.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" "go.fifitido.net/twitch/api/ccls" + "go.fifitido.net/twitch/api/endpoint" ) type GetChannelInformationParams struct { @@ -71,9 +71,8 @@ type ChannelInformation struct { // Requires an app access token or user access token. func (c *Channels) GetChannelInformation(ctx context.Context, params *GetChannelInformationParams) (*GetChannelInformdationResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "channels", v), nil) if err != nil { return nil, err } diff --git a/api/channels/get_followed_channels.go b/api/channels/get_followed_channels.go index 0f61ed9..9980485 100644 --- a/api/channels/get_followed_channels.go +++ b/api/channels/get_followed_channels.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -63,9 +63,8 @@ type FollowedChannel struct { // Requires a user access token that includes the user:read:follows scope. func (c *Channels) GetFollowedChannels(ctx context.Context, params *GetFollowedChannelsParams) (*GetFollowedChannelsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "users/follows", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "users/follows", v), nil) if err != nil { return nil, err } diff --git a/api/channels/modify_channel_information.go b/api/channels/modify_channel_information.go index f542c56..af85310 100644 --- a/api/channels/modify_channel_information.go +++ b/api/channels/modify_channel_information.go @@ -9,6 +9,7 @@ import ( "net/url" "go.fifitido.net/twitch/api/ccls" + "go.fifitido.net/twitch/api/endpoint" ) type ModifyChannelInformationRequest struct { @@ -55,7 +56,7 @@ type ModifyContentClassificationLabel struct { // // Requires a user access token that includes the channel:manage:broadcast scope. func (c *Channels) ModifyChannelInformation(ctx context.Context, broadcasterID string, body *ModifyChannelInformationRequest) error { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "channels", RawQuery: "broadcaster_id=" + broadcasterID}) + v := url.Values{"broadcaster_id": {broadcasterID}} r, w := io.Pipe() @@ -67,7 +68,7 @@ func (c *Channels) ModifyChannelInformation(ctx context.Context, broadcasterID s } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "channels", v), r) if err != nil { return err } diff --git a/api/charity/get_charity_campaign.go b/api/charity/get_charity_campaign.go index a68fa7b..c0793c7 100644 --- a/api/charity/get_charity_campaign.go +++ b/api/charity/get_charity_campaign.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -56,9 +57,9 @@ type CharityCampaign struct { // // Requires a user access token that includes the channel:read:charity scope. func (c *Charity) GetCharityCampaign(ctx context.Context, broadcasterID string) (*GetCharityCampaignResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "charity/campaigns", RawQuery: "broadcaster_id=" + broadcasterID}) + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "charity/campaigns", v), nil) if err != nil { return nil, err } diff --git a/api/charity/get_charity_campaign_donations.go b/api/charity/get_charity_campaign_donations.go index 198e7db..1c6359b 100644 --- a/api/charity/get_charity_campaign_donations.go +++ b/api/charity/get_charity_campaign_donations.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -61,9 +61,8 @@ type CharityCampaignDonation struct { // Requires a user access token that includes the channel:read:charity scope. func (c *Charity) GetCharityCampaignDonations(ctx context.Context, params *GetCharityCampaignDonationsParams) (*GetCharityCampaignDonationsResponse, error) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "charity/campaigns/donations", v), nil) if err != nil { return nil, err } diff --git a/api/chat/get_channel_chat_badges.go b/api/chat/get_channel_chat_badges.go index 202ecda..85c1811 100644 --- a/api/chat/get_channel_chat_badges.go +++ b/api/chat/get_channel_chat_badges.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type GetChannelChatBadgesResponse struct { @@ -20,9 +22,9 @@ type GetChannelChatBadgesResponse struct { // // Requires an app access token or user access token. func (c *Chat) GetChannelChatBadges(ctx context.Context, broadcasterID string) (*GetChannelChatBadgesResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/badges", RawQuery: "broadcaster_id=" + broadcasterID}) + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/badges", v), nil) if err != nil { return nil, err } diff --git a/api/chat/get_channel_emotes.go b/api/chat/get_channel_emotes.go index a08d951..889d70a 100644 --- a/api/chat/get_channel_emotes.go +++ b/api/chat/get_channel_emotes.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type GetChannelEmotesResponse struct { @@ -89,9 +91,9 @@ type ChannelEmote struct { // // Requires an app access token or user access token. func (c *Chat) GetChannelEmotes(ctx context.Context, broadcasterID string) (*GetChannelEmotesResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/emotes", RawQuery: "broadcaster_id=" + broadcasterID}) + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/emotes", v), nil) if err != nil { return nil, err } diff --git a/api/chat/get_chat_settings.go b/api/chat/get_chat_settings.go index cc3b4c9..41fa0cc 100644 --- a/api/chat/get_chat_settings.go +++ b/api/chat/get_chat_settings.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetChatSettingsParams struct { @@ -36,9 +36,8 @@ type GetChatSettingsResponse struct { // Requires an app access token or user access token. func (c *Chat) GetChatSettings(ctx context.Context, params *GetChatSettingsParams) (*GetChatSettingsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/settings", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/settings", v), nil) if err != nil { return nil, err } diff --git a/api/chat/get_chatters.go b/api/chat/get_chatters.go index 179ef36..e066c5d 100644 --- a/api/chat/get_chatters.go +++ b/api/chat/get_chatters.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -63,9 +63,8 @@ type Chatter struct { // Requires a user access token that includes the moderator:read:chatters scope. func (c *Chat) GetChatters(ctx context.Context, params *GetChattersParams) (*GetChattersResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/chatters", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/chatters", v), nil) if err != nil { return nil, err } diff --git a/api/chat/get_emote_sets.go b/api/chat/get_emote_sets.go index 25ba93c..eff2134 100644 --- a/api/chat/get_emote_sets.go +++ b/api/chat/get_emote_sets.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetEmoteSetsParams struct { @@ -95,9 +95,8 @@ type EmoteSetEmote struct { // Requires an app access token or user access token. func (c *Chat) GetEmoteSets(ctx context.Context, params *GetEmoteSetsParams) (*GetEmoteSetsResponse, error) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/emotes/set", v), nil) if err != nil { return nil, err } diff --git a/api/chat/get_global_chat_badges.go b/api/chat/get_global_chat_badges.go index 0013b12..dd7b61b 100644 --- a/api/chat/get_global_chat_badges.go +++ b/api/chat/get_global_chat_badges.go @@ -5,7 +5,8 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type GetGlobalChatBadgesResponse struct { @@ -18,9 +19,7 @@ type GetGlobalChatBadgesResponse struct { // // Requires an app access token or user access token. func (c *Chat) GetGlobalChatBadges(ctx context.Context) (*GetGlobalChatBadgesResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/badges/global"}) - - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/badges/global"), nil) if err != nil { return nil, err } diff --git a/api/chat/get_global_emotes.go b/api/chat/get_global_emotes.go index bf14ac5..e39088d 100644 --- a/api/chat/get_global_emotes.go +++ b/api/chat/get_global_emotes.go @@ -5,7 +5,8 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type GetGlobalEmotesResponse struct { @@ -65,9 +66,7 @@ type GlobalEmote struct { // // Requires an app access token or user access token. func (c *Chat) GetGlobalEmotes(ctx context.Context) (*GetGlobalEmotesResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/emotes/global"}) - - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/emotes/global"), nil) if err != nil { return nil, err } diff --git a/api/chat/get_user_chat_color.go b/api/chat/get_user_chat_color.go index 731e5f1..4856b8c 100644 --- a/api/chat/get_user_chat_color.go +++ b/api/chat/get_user_chat_color.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetUserChatColorParams struct { @@ -44,9 +44,8 @@ type UserChatColor struct { // Requires an app access token or user access token. func (c *Chat) GetUserChatColor(ctx context.Context, params *GetUserChatColorParams) (*GetUserChatColorResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/color", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/color", v), nil) if err != nil { return nil, err } diff --git a/api/chat/send_chat_announcement.go b/api/chat/send_chat_announcement.go index 1535ff8..79a46c8 100644 --- a/api/chat/send_chat_announcement.go +++ b/api/chat/send_chat_announcement.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -38,7 +38,6 @@ type SendChatAnnouncementRequest struct { // Requires a user access token that includes the moderator:manage:announcements scope. func (c *Chat) SendChatAnnouncement(ctx context.Context, params *SendChatAnnouncementParams, body *SendChatAnnouncementRequest) error { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/announcements", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -50,7 +49,7 @@ func (c *Chat) SendChatAnnouncement(ctx context.Context, params *SendChatAnnounc } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "chat/announcements", v), r) if err != nil { return err } diff --git a/api/chat/send_chat_message.go b/api/chat/send_chat_message.go index d6f976d..19c2d7f 100644 --- a/api/chat/send_chat_message.go +++ b/api/chat/send_chat_message.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type SendChatMessageRequest struct { @@ -54,8 +55,6 @@ type DropReason struct { // If app access token used, then additionally requires user:bot scope from chatting user, // and either channel:bot scope from broadcaster or moderator status. func (c *Chat) SendChatMessage(ctx context.Context, body *SendChatMessageRequest) (*SendChatMessageResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/messages"}) - r, w := io.Pipe() go func() { @@ -66,7 +65,7 @@ func (c *Chat) SendChatMessage(ctx context.Context, body *SendChatMessageRequest } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "chat/messages"), r) if err != nil { return nil, err } diff --git a/api/chat/send_shoutout.go b/api/chat/send_shoutout.go index f79254d..0050773 100644 --- a/api/chat/send_shoutout.go +++ b/api/chat/send_shoutout.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type SendShoutoutParams struct { @@ -39,9 +39,8 @@ type SendShoutoutParams struct { // Requires a user access token that includes the moderator:manage:shoutouts scope. func (c *Chat) SendShoutout(ctx context.Context, params *SendShoutoutParams) error { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/shoutouts", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "chat/shoutouts", v), nil) if err != nil { return err } diff --git a/api/chat/update_chat_settings.go b/api/chat/update_chat_settings.go index b7693f3..ca18a49 100644 --- a/api/chat/update_chat_settings.go +++ b/api/chat/update_chat_settings.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateChatSettingsParams struct { @@ -94,7 +94,6 @@ type UpdateChatSettingsResponse struct { // 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) { v, _ := query.Values(body) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/settings", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -106,7 +105,7 @@ func (c *Chat) UpdateChatSettings(ctx context.Context, params *UpdateChatSetting } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "chat/settings", v), r) if err != nil { return nil, err } diff --git a/api/chat/update_user_chat_color.go b/api/chat/update_user_chat_color.go index c1a6b79..c26282d 100644 --- a/api/chat/update_user_chat_color.go +++ b/api/chat/update_user_chat_color.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateUserChatColorParams struct { @@ -27,9 +27,8 @@ type UpdateUserChatColorParams struct { // Requires a user access token that includes the user:manage:chat_color scope. func (c *Chat) UpdateUserChatColor(ctx context.Context, params *UpdateUserChatColorParams) error { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/color", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(c.baseUrl, "chat/color", v), nil) if err != nil { return err } diff --git a/api/conduit/create_conduits.go b/api/conduit/create_conduits.go index 81984cd..6c1e822 100644 --- a/api/conduit/create_conduits.go +++ b/api/conduit/create_conduits.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type CreateConduitsRequest struct { @@ -22,8 +23,6 @@ type CreateConduitsResponse struct { // // Requires an app access token. func (c *Conduit) CreateConduits(ctx context.Context, body *CreateConduitsRequest) (*CreateConduitsResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits"}) - r, w := io.Pipe() go func() { @@ -34,7 +33,7 @@ func (c *Conduit) CreateConduits(ctx context.Context, body *CreateConduitsReques } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "eventsub/conduits"), r) if err != nil { return nil, err } diff --git a/api/conduit/delete_conduit.go b/api/conduit/delete_conduit.go index 13cb6d6..75f5e51 100644 --- a/api/conduit/delete_conduit.go +++ b/api/conduit/delete_conduit.go @@ -5,6 +5,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) // Deletes a specified conduit. @@ -12,9 +14,9 @@ import ( // // Requires an app access token. func (c *Conduit) DeleteConduit(ctx context.Context, id string) error { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits", RawQuery: "id=" + id}) + v := url.Values{"id": {id}} - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(c.baseUrl, "eventsub/conduits", v), nil) if err != nil { return err } diff --git a/api/conduit/get_conduit_shards.go b/api/conduit/get_conduit_shards.go index 8163813..f82de22 100644 --- a/api/conduit/get_conduit_shards.go +++ b/api/conduit/get_conduit_shards.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -35,9 +35,8 @@ type GetConduitShardsResponse struct { // Requires an app access token. func (c *Conduit) GetConduitShards(ctx context.Context, params *GetConduitShardsParams) (*GetConduitShardsResponse, error) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "eventsub/conduits/shards", v), nil) if err != nil { return nil, err } diff --git a/api/conduit/get_conduits.go b/api/conduit/get_conduits.go index 33c9655..9231313 100644 --- a/api/conduit/get_conduits.go +++ b/api/conduit/get_conduits.go @@ -5,7 +5,8 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type GetConduitsResponse struct { @@ -17,9 +18,7 @@ type GetConduitsResponse struct { // // Requires an app access token. func (c *Conduit) GetConduits(ctx context.Context) (*GetConduitsResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits"}) - - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "eventsub/conduits"), nil) if err != nil { return nil, err } diff --git a/api/conduit/update_conduit_shards.go b/api/conduit/update_conduit_shards.go index 6f2dd1b..88552e5 100644 --- a/api/conduit/update_conduit_shards.go +++ b/api/conduit/update_conduit_shards.go @@ -6,8 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/eventsub" ) @@ -69,8 +69,6 @@ type UpdateConduitShardsError struct { // // Requires an app access token. 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() go func() { @@ -81,7 +79,7 @@ func (c *Conduit) UpdateConduitShards(ctx context.Context, body *UpdateConduitSh } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "eventsub/conduits/shards"), r) if err != nil { return nil, err } diff --git a/api/conduit/update_conduits.go b/api/conduit/update_conduits.go index e851bd6..82157fe 100644 --- a/api/conduit/update_conduits.go +++ b/api/conduit/update_conduits.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type UpdateConduitsRequest struct { @@ -27,8 +28,6 @@ type UpdateConduitsResponse struct { // // Requires an app access token. func (c *Conduit) UpdateConduits(ctx context.Context, body *UpdateConduitsRequest) (*UpdateConduitsResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits"}) - r, w := io.Pipe() go func() { @@ -39,7 +38,7 @@ func (c *Conduit) UpdateConduits(ctx context.Context, body *UpdateConduitsReques } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(c.baseUrl, "eventsub/conduits"), r) if err != nil { return nil, err } diff --git a/api/endpoint/endpoint.go b/api/endpoint/endpoint.go new file mode 100644 index 0000000..6ab1d52 --- /dev/null +++ b/api/endpoint/endpoint.go @@ -0,0 +1,19 @@ +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() + +} diff --git a/api/entitlements/get_drops_entitlements.go b/api/entitlements/get_drops_entitlements.go index 1ae2c99..1d95811 100644 --- a/api/entitlements/get_drops_entitlements.go +++ b/api/entitlements/get_drops_entitlements.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -89,16 +89,15 @@ type Entitlement struct { // 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. -func (c *Entitlements) GetDropsEntitlements(ctx context.Context, params *GetDropsEntitlementsParams) (*GetDropsEntitlementsResponse, error) { +func (e *Entitlements) GetDropsEntitlements(ctx context.Context, params *GetDropsEntitlementsParams) (*GetDropsEntitlementsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "entitlements/drops", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "entitlements/drops", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/entitlements/update_drops_entitlements.go b/api/entitlements/update_drops_entitlements.go index 1a7d850..b664d39 100644 --- a/api/entitlements/update_drops_entitlements.go +++ b/api/entitlements/update_drops_entitlements.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type UpdateDropsEntitlementsRequest struct { @@ -39,9 +40,7 @@ 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. // // Requires an app access token or user access token. The client ID in the access token must own the game. -func (c *Entitlements) UpdateDropsEntitlements(ctx context.Context, request *UpdateDropsEntitlementsRequest) (*UpdateDropsEntitlementsResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "entitlements/drops"}) - +func (e *Entitlements) UpdateDropsEntitlements(ctx context.Context, request *UpdateDropsEntitlementsRequest) (*UpdateDropsEntitlementsResponse, error) { r, w := io.Pipe() go func() { @@ -52,12 +51,12 @@ func (c *Entitlements) UpdateDropsEntitlements(ctx context.Context, request *Upd } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(e.baseUrl, "entitlements/drops"), r) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/eventsub/create_eventsub_subscription.go b/api/eventsub/create_eventsub_subscription.go index 7fee5a3..49ab761 100644 --- a/api/eventsub/create_eventsub_subscription.go +++ b/api/eventsub/create_eventsub_subscription.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type CreateEventSubSubscriptionRequest struct { @@ -51,7 +52,6 @@ type CreateEventSubSubscriptionResponse struct { // 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. func (e *EventSub) CreateEventSubSubscription(ctx context.Context, body *CreateEventSubSubscriptionRequest) (*CreateEventSubSubscriptionResponse, error) { - endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "eventsub/subscriptions"}) r, w := io.Pipe() @@ -63,7 +63,7 @@ func (e *EventSub) CreateEventSubSubscription(ctx context.Context, body *CreateE } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(e.baseUrl, "eventsub/subscriptions"), r) if err != nil { return nil, err } diff --git a/api/eventsub/delete_eventsub_subscription.go b/api/eventsub/delete_eventsub_subscription.go index a1e969c..9cb641a 100644 --- a/api/eventsub/delete_eventsub_subscription.go +++ b/api/eventsub/delete_eventsub_subscription.go @@ -5,6 +5,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) // Deletes an EventSub subscription. @@ -15,9 +17,9 @@ import ( // 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. func (e *EventSub) DeleteEventSubSubscription(ctx context.Context, id string) error { - endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "eventsub/subscriptions", RawQuery: "id=" + id}) + v := url.Values{"id": {id}} - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(e.baseUrl, "eventsub/subscriptions", v), nil) if err != nil { return err } diff --git a/api/eventsub/get_eventsub_subscriptions.go b/api/eventsub/get_eventsub_subscriptions.go index f699127..83bcd91 100644 --- a/api/eventsub/get_eventsub_subscriptions.go +++ b/api/eventsub/get_eventsub_subscriptions.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -58,9 +58,8 @@ type GetEventSubSubscriptionsResponse struct { // 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) { v, _ := query.Values(params) - endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "eventsub/subscriptions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "eventsub/subscriptions", v), nil) if err != nil { return nil, err } diff --git a/api/extensions/create_extension_secret.go b/api/extensions/create_extension_secret.go index 5dd33db..f4ea1c4 100644 --- a/api/extensions/create_extension_secret.go +++ b/api/extensions/create_extension_secret.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type CreateExtensionSecretParams struct { @@ -35,16 +35,15 @@ type CreateExtensionSecretResponse struct { // The signed JWT must include the role, user_id, and exp fields // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // The role field must be set to external. -func (c *Extensions) CreateExtensionSecret(ctx context.Context, params *CreateExtensionSecretParams) (*CreateExtensionSecretResponse, error) { +func (e *Extensions) CreateExtensionSecret(ctx context.Context, params *CreateExtensionSecretParams) (*CreateExtensionSecretResponse, error) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(e.baseUrl, "extensions/jwt/secrets", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/extensions/get_extension_bits_products.go b/api/extensions/get_extension_bits_products.go index 80f404b..f12179c 100644 --- a/api/extensions/get_extension_bits_products.go +++ b/api/extensions/get_extension_bits_products.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetExtensionBitsProductsParams struct { @@ -23,16 +23,15 @@ 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. // // Requires an app access token. The client ID in the app access token must be the extension’s client ID. -func (c *Extensions) GetExtensionBitsProducts(ctx context.Context, params *GetExtensionBitsProductsParams) (*GetExtensionBitsProductsResponse, error) { +func (e *Extensions) GetExtensionBitsProducts(ctx context.Context, params *GetExtensionBitsProductsParams) (*GetExtensionBitsProductsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "bits/extensions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "bits/extensions", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/extensions/get_extension_configuration_segment.go b/api/extensions/get_extension_configuration_segment.go index e63ebfe..0203976 100644 --- a/api/extensions/get_extension_configuration_segment.go +++ b/api/extensions/get_extension_configuration_segment.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetExtensionConfigurationSegmentParams struct { @@ -58,16 +58,15 @@ type ConfigurationSegmentData struct { // The signed JWT must include the role, user_id, and exp fields // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // The role field must be set to external. -func (c *Extensions) GetExtensionConfigurationSegment(ctx context.Context, params *GetExtensionConfigurationSegmentParams) (*GetExtensionConfigurationSegmentResponse, error) { +func (e *Extensions) GetExtensionConfigurationSegment(ctx context.Context, params *GetExtensionConfigurationSegmentParams) (*GetExtensionConfigurationSegmentResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/configurations", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions/configurations", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/extensions/get_extension_live_channels.go b/api/extensions/get_extension_live_channels.go index 22e10b5..db0aab0 100644 --- a/api/extensions/get_extension_live_channels.go +++ b/api/extensions/get_extension_live_channels.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -50,16 +50,15 @@ 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. // // Requires an app access token or user access token. -func (c *Extensions) GetExtensionLiveChannels(ctx context.Context, params *GetExtensionLiveChannelsParams) (*GetExtensionLiveChannelsResponse, error) { +func (e *Extensions) GetExtensionLiveChannels(ctx context.Context, params *GetExtensionLiveChannelsParams) (*GetExtensionLiveChannelsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/live", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions/live", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/extensions/get_extension_secrets.go b/api/extensions/get_extension_secrets.go index 2dbdd8a..567fa58 100644 --- a/api/extensions/get_extension_secrets.go +++ b/api/extensions/get_extension_secrets.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type GetExtensionSecretsResponse struct { @@ -20,15 +22,15 @@ type GetExtensionSecretsResponse struct { // The signed JWT must include the role, user_id, and exp fields // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // The role field must be set to external. -func (c *Extensions) GetExtensionSecrets(ctx context.Context, extensionID string) (*GetExtensionSecretsResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/jwt/secrets", RawQuery: "extension_id=" + extensionID}) +func (e *Extensions) GetExtensionSecrets(ctx context.Context, extensionID string) (*GetExtensionSecretsResponse, error) { + v := url.Values{"extension_id": {extensionID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions/jwt/secrets", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/extensions/get_extensions.go b/api/extensions/get_extensions.go index 923e711..9084b17 100644 --- a/api/extensions/get_extensions.go +++ b/api/extensions/get_extensions.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetExtensionsParams struct { @@ -31,16 +31,15 @@ type GetExtensionsResponse struct { // The signed JWT must include the role, user_id, and exp fields // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // The role field must be set to external. -func (c *Extensions) GetExtensions(ctx context.Context, params *GetExtensionsParams) (*GetExtensionsResponse, error) { +func (e *Extensions) GetExtensions(ctx context.Context, params *GetExtensionsParams) (*GetExtensionsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/extensions/get_released_extensions.go b/api/extensions/get_released_extensions.go index c9d28ff..5d792cd 100644 --- a/api/extensions/get_released_extensions.go +++ b/api/extensions/get_released_extensions.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetReleasedExtensionsParams struct { @@ -26,16 +26,15 @@ type GetReleasedExtensionsResponse struct { // Gets information about a released extension. Returns the extension if its state is Released. // // Requires an app access token or user access token. -func (c *Extensions) GetReleasedExtensions(ctx context.Context, params *GetReleasedExtensionsParams) (*GetReleasedExtensionsResponse, error) { +func (e *Extensions) GetReleasedExtensions(ctx context.Context, params *GetReleasedExtensionsParams) (*GetReleasedExtensionsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/released", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(e.baseUrl, "extensions/released", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/extensions/send_extension_chat_message.go b/api/extensions/send_extension_chat_message.go index 0d6709b..27c522c 100644 --- a/api/extensions/send_extension_chat_message.go +++ b/api/extensions/send_extension_chat_message.go @@ -7,6 +7,8 @@ import ( "io" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type SendExtensionChatMessageRequest struct { @@ -31,8 +33,8 @@ type SendExtensionChatMessageRequest struct { // The signed JWT must include the role, user_id, and exp fields // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // The role field must be set to external. -func (c *Extensions) SendExtensionChatMessage(ctx context.Context, broadcasterID string, body *SendExtensionChatMessageRequest) error { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/chat", RawQuery: "broadcaster_id=" + broadcasterID}) +func (e *Extensions) SendExtensionChatMessage(ctx context.Context, broadcasterID string, body *SendExtensionChatMessageRequest) error { + v := url.Values{"broadcaster_id": {broadcasterID}} r, w := io.Pipe() @@ -44,12 +46,12 @@ func (c *Extensions) SendExtensionChatMessage(ctx context.Context, broadcasterID } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(e.baseUrl, "extensions/chat", v), r) if err != nil { return err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return err } diff --git a/api/extensions/send_extension_pubsub_message.go b/api/extensions/send_extension_pubsub_message.go index c566985..4b6dfda 100644 --- a/api/extensions/send_extension_pubsub_message.go +++ b/api/extensions/send_extension_pubsub_message.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type SendExtensionPubsubMessageRequest struct { @@ -42,9 +43,7 @@ type SendExtensionPubsubMessageRequest struct { // To send the message to a specific channel, set the channel_id field in the JWT to the channel’s 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. -func (c *Extensions) SendExtensionPubsubMessage(ctx context.Context, body *SendExtensionPubsubMessageRequest) error { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/pubsub"}) - +func (e *Extensions) SendExtensionPubsubMessage(ctx context.Context, body *SendExtensionPubsubMessageRequest) error { r, w := io.Pipe() go func() { @@ -55,12 +54,12 @@ func (c *Extensions) SendExtensionPubsubMessage(ctx context.Context, body *SendE } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(e.baseUrl, "extensions/pubsub"), r) if err != nil { return err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return err } diff --git a/api/extensions/set_extension_configuration_segment.go b/api/extensions/set_extension_configuration_segment.go index 39616d1..f19879f 100644 --- a/api/extensions/set_extension_configuration_segment.go +++ b/api/extensions/set_extension_configuration_segment.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type SetExtensionConfigurationSegmentRequest struct { @@ -38,8 +39,7 @@ type SetExtensionConfigurationSegmentRequest struct { // The signed JWT must include the role, user_id, and exp fields // (see JWT Schema: https://dev.twitch.tv/docs/extensions/reference/#jwt-schema). // The role field must be set to external. -func (c *Extensions) SetExtensionConfigurationSegment(ctx context.Context, body *SetExtensionConfigurationSegmentRequest) error { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/configurations"}) +func (e *Extensions) SetExtensionConfigurationSegment(ctx context.Context, body *SetExtensionConfigurationSegmentRequest) error { r, w := io.Pipe() @@ -51,12 +51,12 @@ func (c *Extensions) SetExtensionConfigurationSegment(ctx context.Context, body } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(e.baseUrl, "extensions/configurations"), r) if err != nil { return err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return err } diff --git a/api/extensions/set_extension_required_configuration.go b/api/extensions/set_extension_required_configuration.go index cd74c59..5f30539 100644 --- a/api/extensions/set_extension_required_configuration.go +++ b/api/extensions/set_extension_required_configuration.go @@ -7,6 +7,8 @@ import ( "io" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type SetExtensionRequiredConfigurationRequest struct { @@ -32,8 +34,8 @@ type SetExtensionRequiredConfigurationRequest struct { // The signed JWT must include the role, user_id, and exp fields // (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. -func (c *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broadcasterID string, body *SetExtensionRequiredConfigurationRequest) error { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "extensions/required_configuration", RawQuery: "broadcaster_id=" + broadcasterID}) +func (e *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broadcasterID string, body *SetExtensionRequiredConfigurationRequest) error { + v := url.Values{"broadcaster_id": {broadcasterID}} r, w := io.Pipe() @@ -45,12 +47,12 @@ func (c *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broa } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(e.baseUrl, "extensions/required_configuration", v), r) if err != nil { return err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return err } diff --git a/api/extensions/update_extension_bits_product.go b/api/extensions/update_extension_bits_product.go index 2c51f75..c4bb9f3 100644 --- a/api/extensions/update_extension_bits_product.go +++ b/api/extensions/update_extension_bits_product.go @@ -6,8 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "time" + + "go.fifitido.net/twitch/api/endpoint" ) type UpdateExtensionBitsProductRequest struct { @@ -52,9 +53,7 @@ type UpdateExtensionBitsProductResponse struct { // If the SKU doesn’t 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 extension’s client ID. -func (c *Extensions) UpdateExtensionBitsProduct(ctx context.Context, body *UpdateExtensionBitsProductRequest) (*UpdateExtensionBitsProductResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "bits/extensions"}) - +func (e *Extensions) UpdateExtensionBitsProduct(ctx context.Context, body *UpdateExtensionBitsProductRequest) (*UpdateExtensionBitsProductResponse, error) { r, w := io.Pipe() go func() { @@ -65,12 +64,12 @@ func (c *Extensions) UpdateExtensionBitsProduct(ctx context.Context, body *Updat } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(e.baseUrl, "bits/extensions"), r) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := e.client.Do(req) if err != nil { return nil, err } diff --git a/api/games/get_games.go b/api/games/get_games.go index ce94fae..c0a8ed2 100644 --- a/api/games/get_games.go +++ b/api/games/get_games.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetGamesParams struct { @@ -35,16 +35,15 @@ 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. // // Requires an app access token or user access token. -func (c *Games) GetGames(ctx context.Context, params *GetGamesParams) (*GetGamesResponse, error) { +func (g *Games) GetGames(ctx context.Context, params *GetGamesParams) (*GetGamesResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "games", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "games", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := g.client.Do(req) if err != nil { return nil, err } diff --git a/api/games/get_top_games.go b/api/games/get_top_games.go index 0a860b9..fc81462 100644 --- a/api/games/get_top_games.go +++ b/api/games/get_top_games.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -38,16 +38,15 @@ type GetTopGamesResponse struct { // Gets information about all broadcasts on Twitch. // // Requires an app access token or user access token. -func (c *Games) GetTopGames(ctx context.Context, params *GetTopGamesParams) (*GetTopGamesResponse, error) { +func (g *Games) GetTopGames(ctx context.Context, params *GetTopGamesParams) (*GetTopGamesResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "games/top", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "games/top", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := g.client.Do(req) if err != nil { return nil, err } diff --git a/api/goals/get_creator_goals.go b/api/goals/get_creator_goals.go index a4b08df..ab14f4d 100644 --- a/api/goals/get_creator_goals.go +++ b/api/goals/get_creator_goals.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "time" + + "go.fifitido.net/twitch/api/endpoint" ) type GetCreatorGoalsResponse struct { @@ -82,15 +84,15 @@ type Goal struct { // 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. -func (c *Goals) GetCreatorGoals(ctx context.Context, broadcasterID string) (*GetCreatorGoalsResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "goals", RawQuery: "broadcaster_id=" + broadcasterID}) +func (g *Goals) GetCreatorGoals(ctx context.Context, broadcasterID string) (*GetCreatorGoalsResponse, error) { + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "goals", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := g.client.Do(req) if err != nil { return nil, err } diff --git a/api/gueststar/assign_gueststar_slot.go b/api/gueststar/assign_gueststar_slot.go index 6e14156..fffe51c 100644 --- a/api/gueststar/assign_gueststar_slot.go +++ b/api/gueststar/assign_gueststar_slot.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type AssignGuestStarSlot struct { @@ -35,9 +35,8 @@ type AssignGuestStarSlot struct { // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star func (g *GuestStar) AssignGuestStarSlot(ctx context.Context, params *AssignGuestStarSlot) error { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/slot", v), nil) if err != nil { return err } diff --git a/api/gueststar/create_gueststar_session.go b/api/gueststar/create_gueststar_session.go index 5e042f0..b4dae91 100644 --- a/api/gueststar/create_gueststar_session.go +++ b/api/gueststar/create_gueststar_session.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type CreateGuestStarSessionResponse struct { @@ -18,9 +20,9 @@ type CreateGuestStarSessionResponse struct { // Query parameter broadcaster_id must match the user_id in the User-Access token // Requires OAuth Scope: channel:manage:guest_star func (g *GuestStar) CreateGuestStarSession(ctx context.Context, broadcasterID string) (*CreateGuestStarSessionResponse, error) { - endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/session", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()}) + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/session", v), nil) if err != nil { return nil, err } diff --git a/api/gueststar/delete_gueststar_invite.go b/api/gueststar/delete_gueststar_invite.go index e646c75..d7b93b9 100644 --- a/api/gueststar/delete_gueststar_invite.go +++ b/api/gueststar/delete_gueststar_invite.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type DeleteGuestStarInviteParams struct { @@ -30,9 +30,8 @@ type DeleteGuestStarInviteParams struct { // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star func (g *GuestStar) DeleteGuestStarInvite(ctx context.Context, params *DeleteGuestStarInviteParams) error { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(g.baseUrl, "guest_star/invite", v), nil) if err != nil { return err } diff --git a/api/gueststar/delete_gueststar_slot.go b/api/gueststar/delete_gueststar_slot.go index 82f8f1a..2c5e448 100644 --- a/api/gueststar/delete_gueststar_slot.go +++ b/api/gueststar/delete_gueststar_slot.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type DeleteGuestStarSlotParams struct { @@ -37,9 +37,8 @@ type DeleteGuestStarSlotParams struct { // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star func (g *GuestStar) DeleteGuestStarSlot(ctx context.Context, params *DeleteGuestStarSlotParams) error { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(g.baseUrl, "guest_star/slot", v), nil) if err != nil { return err } diff --git a/api/gueststar/end_gueststar_session.go b/api/gueststar/end_gueststar_session.go index a3d0a8b..7e59f08 100644 --- a/api/gueststar/end_gueststar_session.go +++ b/api/gueststar/end_gueststar_session.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type EndGuestStarSession struct { @@ -30,9 +30,8 @@ type EndGuestStarSessionResponse struct { // Requires OAuth Scope: channel:manage:guest_star func (g *GuestStar) EndGuestStarSession(ctx context.Context, params *EndGuestStarSession) (*EndGuestStarSessionResponse, error) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(g.baseUrl, "guest_star/session", v), nil) if err != nil { return nil, err } diff --git a/api/gueststar/get_channel_gueststar_settings.go b/api/gueststar/get_channel_gueststar_settings.go index eacd17d..3cdf483 100644 --- a/api/gueststar/get_channel_gueststar_settings.go +++ b/api/gueststar/get_channel_gueststar_settings.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetChannelGuestStarSettingsParams struct { @@ -29,9 +29,8 @@ type GetChannelGuestStarSettingsResponse struct { // 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) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/channel_settings", v), nil) if err != nil { return nil, err } diff --git a/api/gueststar/get_gueststar_invites.go b/api/gueststar/get_gueststar_invites.go index 2375608..5847766 100644 --- a/api/gueststar/get_gueststar_invites.go +++ b/api/gueststar/get_gueststar_invites.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetGuestStarInvitesParams struct { @@ -33,9 +33,8 @@ type GetGuestStarInvitesResponse struct { // 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) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/invites", v), nil) if err != nil { return nil, err } diff --git a/api/gueststar/get_gueststar_session.go b/api/gueststar/get_gueststar_session.go index 7b70ab0..1dd549a 100644 --- a/api/gueststar/get_gueststar_session.go +++ b/api/gueststar/get_gueststar_session.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetGuestStarSessionParams struct { @@ -30,9 +30,8 @@ type GetGuestStarSessionResponse struct { // Guests must be either invited or assigned a slot within the session func (g *GuestStar) GetGuestStarSession(ctx context.Context, params *GetGuestStarSessionParams) (*GetGuestStarSessionResponse, error) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(g.baseUrl, "guest_star/session", v), nil) if err != nil { return nil, err } diff --git a/api/gueststar/send_gueststar_invite.go b/api/gueststar/send_gueststar_invite.go index ec09867..e5c558c 100644 --- a/api/gueststar/send_gueststar_invite.go +++ b/api/gueststar/send_gueststar_invite.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type SendGuestStarInviteParams struct { @@ -30,9 +30,8 @@ type SendGuestStarInviteParams struct { // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star func (g *GuestStar) SendGuestStarInvite(ctx context.Context, params *SendGuestStarInviteParams) error { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/invite", v), nil) if err != nil { return err } diff --git a/api/gueststar/update_channel_gueststar_settings.go b/api/gueststar/update_channel_gueststar_settings.go index 53c28aa..9c13f61 100644 --- a/api/gueststar/update_channel_gueststar_settings.go +++ b/api/gueststar/update_channel_gueststar_settings.go @@ -5,6 +5,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type UpdateChannelGuestStarSettingsRequest struct { @@ -39,9 +41,9 @@ type UpdateChannelGuestStarSettingsRequest struct { // Query parameter broadcaster_id must match the user_id in the User-Access token // Requires OAuth Scope: channel:manage:guest_star func (g *GuestStar) UpdateChannelGuestStarSettings(ctx context.Context, BroadcasterID string, body *UpdateChannelGuestStarSettingsRequest) error { - endpoint := g.baseUrl.ResolveReference(&url.URL{Path: "guest_star/channel_settings", RawQuery: url.Values{"broadcaster_id": {BroadcasterID}}.Encode()}) + v := url.Values{"broadcaster_id": {BroadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(g.baseUrl, "guest_star/channel_settings", v), nil) if err != nil { return err } diff --git a/api/gueststar/update_gueststar_slot.go b/api/gueststar/update_gueststar_slot.go index 46228e1..0e03ae9 100644 --- a/api/gueststar/update_gueststar_slot.go +++ b/api/gueststar/update_gueststar_slot.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateGuestStarSlot struct { @@ -33,9 +33,8 @@ type UpdateGuestStarSlot struct { // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star func (g *GuestStar) UpdateGuestStarSlot(ctx context.Context, params *UpdateGuestStarSlot) error { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/slot", v), nil) if err != nil { return err } diff --git a/api/gueststar/update_gueststar_slot_settings.go b/api/gueststar/update_gueststar_slot_settings.go index b5ba135..2419803 100644 --- a/api/gueststar/update_gueststar_slot_settings.go +++ b/api/gueststar/update_gueststar_slot_settings.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateGuestStarSlotSettingsParams struct { @@ -45,9 +45,8 @@ type UpdateGuestStarSlotSettingsParams struct { // Requires OAuth Scope: channel:manage:guest_star or moderator:manage:guest_star func (g *GuestStar) UpdateGuestStarSlotSettings(ctx context.Context, params *UpdateGuestStarSlotSettingsParams) error { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(g.baseUrl, "guest_star/slot_settings", v), nil) if err != nil { return err } diff --git a/api/hypetrain/get_hypetrain_events.go b/api/hypetrain/get_hypetrain_events.go index d65f70a..3583457 100644 --- a/api/hypetrain/get_hypetrain_events.go +++ b/api/hypetrain/get_hypetrain_events.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -119,9 +119,8 @@ type GetHypeTrainEventsResponse struct { // Requires a user access token that includes the channel:read:hype_train scope. func (h *Hypetrain) GetHypeTrainEvents(ctx context.Context, params *GetHypeTrainEventsParams) (*GetHypeTrainEventsResponse, error) { v, _ := query.Values(params) - endpoint := h.baseUrl.ResolveReference(&url.URL{Path: "hypetrain/events", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(h.baseUrl, "hypetrain/events", v), nil) if err != nil { return nil, err } diff --git a/api/moderation/add_blocked_term.go b/api/moderation/add_blocked_term.go index b78d686..a74a6b3 100644 --- a/api/moderation/add_blocked_term.go +++ b/api/moderation/add_blocked_term.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type AddBlockedTermParams struct { @@ -43,7 +43,6 @@ type AddBlockedTermResponse struct { // 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) { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/blocked_terms", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -55,7 +54,7 @@ func (m *Moderation) AddBlockedTerm(ctx context.Context, params *AddBlockedTermP } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/blocked_terms", v), r) if err != nil { return nil, err } diff --git a/api/moderation/add_channel_moderator.go b/api/moderation/add_channel_moderator.go index b3ce228..f81314d 100644 --- a/api/moderation/add_channel_moderator.go +++ b/api/moderation/add_channel_moderator.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type AddChannelModeratorParams struct { @@ -24,9 +24,8 @@ type AddChannelModeratorParams struct { // Requires a user access token that includes the channel:manage:moderators scope. func (m *Moderation) AddChannelModerator(ctx context.Context, params *AddChannelModeratorParams) error { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/moderators", v), nil) if err != nil { return err } diff --git a/api/moderation/add_channel_vip.go b/api/moderation/add_channel_vip.go index a79a67b..47c2ffc 100644 --- a/api/moderation/add_channel_vip.go +++ b/api/moderation/add_channel_vip.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type AddChannelVIPParams struct { @@ -24,9 +24,8 @@ type AddChannelVIPParams struct { // Requires a user access token that includes the channel:manage:vips scope. func (m *Moderation) AddChannelVIP(ctx context.Context, params *AddChannelVIPParams) error { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "channels/vips", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "channels/vips", v), nil) if err != nil { return err } diff --git a/api/moderation/ban_user.go b/api/moderation/ban_user.go index 23c459b..95d6b46 100644 --- a/api/moderation/ban_user.go +++ b/api/moderation/ban_user.go @@ -6,10 +6,10 @@ import ( "fmt" "io" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type BanUserParams struct { @@ -70,7 +70,6 @@ type BanUserResponseData struct { // 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) { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/bans", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -82,7 +81,7 @@ func (m *Moderation) BanUser(ctx context.Context, params *BanUserParams, body *B } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/bans", v), r) if err != nil { return nil, err } diff --git a/api/moderation/check_automod_status.go b/api/moderation/check_automod_status.go index ca93bb3..8667aa0 100644 --- a/api/moderation/check_automod_status.go +++ b/api/moderation/check_automod_status.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type CheckAutoModStatusRequest struct { @@ -51,15 +53,15 @@ type CheckAutoModStatusResponseData struct { // 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. -func (c *Moderation) CheckAutoModStatus(ctx context.Context, broadcasterID string, params *CheckAutoModStatusRequest) (*CheckAutoModStatusResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "modetation/enforcements/status", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()}) +func (m *Moderation) CheckAutoModStatus(ctx context.Context, broadcasterID string, params *CheckAutoModStatusRequest) (*CheckAutoModStatusResponse, error) { + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/enforcements/status", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := m.client.Do(req) if err != nil { return nil, err } diff --git a/api/moderation/delete_chat_messages.go b/api/moderation/delete_chat_messages.go index 1446ed0..92c9311 100644 --- a/api/moderation/delete_chat_messages.go +++ b/api/moderation/delete_chat_messages.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type DeleteChatMessagesParams struct { @@ -34,9 +34,8 @@ type DeleteChatMessagesParams struct { // Requires a user access token that includes the moderator:manage:chat_messages scope. func (m *Moderation) DeleteChatMessages(ctx context.Context, params *DeleteChatMessagesParams) error { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/chat", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/chat", v), nil) if err != nil { return err } diff --git a/api/moderation/get_automod_settings.go b/api/moderation/get_automod_settings.go index c8a2d27..47fcba3 100644 --- a/api/moderation/get_automod_settings.go +++ b/api/moderation/get_automod_settings.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetAutoModSettingsParams struct { @@ -30,9 +30,8 @@ type GetAutoModSettingsResponse struct { // Requires a user access token that includes the moderator:read:automod_settings scope. func (m *Moderation) GetAutoModSettings(ctx context.Context, params *GetAutoModSettingsParams) (*GetAutoModSettingsResponse, error) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/automod/settings", v), nil) if err != nil { return nil, err } diff --git a/api/moderation/get_banned_users.go b/api/moderation/get_banned_users.go index 3a8cd97..3838b17 100644 --- a/api/moderation/get_banned_users.go +++ b/api/moderation/get_banned_users.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -83,9 +83,8 @@ type GetBannedUsersResponseData struct { // 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) { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/banned", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/banned", v), nil) if err != nil { return nil, err } diff --git a/api/moderation/get_blocked_terms.go b/api/moderation/get_blocked_terms.go index 96ecbc9..2ea129b 100644 --- a/api/moderation/get_blocked_terms.go +++ b/api/moderation/get_blocked_terms.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -44,9 +44,8 @@ type GetBlockedTermsResponse struct { // 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) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/blocked_terms", v), nil) if err != nil { return nil, err } diff --git a/api/moderation/get_moderated_channels.go b/api/moderation/get_moderated_channels.go index db8a2a6..0b9499c 100644 --- a/api/moderation/get_moderated_channels.go +++ b/api/moderation/get_moderated_channels.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -51,9 +51,8 @@ type GetModeratedChannelsResponseData struct { // Requires OAuth Scope: user:read:moderated_channels func (m *Moderation) GetModeratedChannels(ctx context.Context, params *GetModeratedChannelsParams) (*GetModeratedChannelsResponse, error) { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/channels", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/channels", v), nil) if err != nil { return nil, err } diff --git a/api/moderation/get_moderators.go b/api/moderation/get_moderators.go index 28865ed..f6de1dd 100644 --- a/api/moderation/get_moderators.go +++ b/api/moderation/get_moderators.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -61,9 +61,8 @@ type GetModeratorsResponseData struct { // 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) { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/moderators", v), nil) if err != nil { return nil, err } diff --git a/api/moderation/get_shield_mode_status.go b/api/moderation/get_shield_mode_status.go index bfc5008..afc9bd1 100644 --- a/api/moderation/get_shield_mode_status.go +++ b/api/moderation/get_shield_mode_status.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetShieldModeStatusParams struct { @@ -31,9 +31,8 @@ type GetShieldModeStatusResponse struct { // 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) { 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/shield_mode", v), nil) if err != nil { return nil, err } diff --git a/api/moderation/get_vips.go b/api/moderation/get_vips.go index 3a3c122..ff5d698 100644 --- a/api/moderation/get_vips.go +++ b/api/moderation/get_vips.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -59,9 +59,8 @@ type GetVIPsResponseData struct { // 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) { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/vips", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/vips", v), nil) if err != nil { return nil, err } diff --git a/api/moderation/manage_held_automod_messages.go b/api/moderation/manage_held_automod_messages.go index 76b1e72..4defe19 100644 --- a/api/moderation/manage_held_automod_messages.go +++ b/api/moderation/manage_held_automod_messages.go @@ -4,7 +4,8 @@ import ( "context" "fmt" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type AutoModAction string @@ -33,9 +34,8 @@ type ManageHeldAutoModMessagesRequest struct { // // Requires a user access token that includes the moderator:manage:automod scope. 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.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/automod/message"), nil) if err != nil { return err } diff --git a/api/moderation/remove_blocked_term.go b/api/moderation/remove_blocked_term.go index 900982d..00a0775 100644 --- a/api/moderation/remove_blocked_term.go +++ b/api/moderation/remove_blocked_term.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type RemoveBlockedTermParams struct { @@ -26,9 +26,8 @@ type RemoveBlockedTermParams struct { // Requires a user access token that includes the moderator:manage:blocked_terms scope. func (m *Moderation) RemoveBlockedTerm(ctx context.Context, params *RemoveBlockedTermParams) error { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/blocks", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/blocks", v), nil) if err != nil { return err } diff --git a/api/moderation/remove_channel_moderator.go b/api/moderation/remove_channel_moderator.go index b976f6e..0979f43 100644 --- a/api/moderation/remove_channel_moderator.go +++ b/api/moderation/remove_channel_moderator.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type RemoveChannelModeratorParams struct { @@ -24,9 +24,8 @@ type RemoveChannelModeratorParams struct { // Requires a user access token that includes the channel:manage:moderators scope. func (m *Moderation) RemoveChannelModerator(ctx context.Context, params *RemoveChannelModeratorParams) error { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/moderators", v), nil) if err != nil { return err } diff --git a/api/moderation/remove_channel_vip.go b/api/moderation/remove_channel_vip.go index 5e678f7..6f2adf5 100644 --- a/api/moderation/remove_channel_vip.go +++ b/api/moderation/remove_channel_vip.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type RemoveChannelVIPParams struct { @@ -27,9 +27,8 @@ type RemoveChannelVIPParams struct { // Requires a user access token that includes the channel:manage:vips scope. func (m *Moderation) RemoveChannelVIP(ctx context.Context, params *RemoveChannelVIPParams) error { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "channels/vips", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "channels/vips", v), nil) if err != nil { return err } diff --git a/api/moderation/unban_user.go b/api/moderation/unban_user.go index 9512b4e..a6784db 100644 --- a/api/moderation/unban_user.go +++ b/api/moderation/unban_user.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UnbanUserParams struct { @@ -28,9 +28,8 @@ type UnbanUserParams struct { // Requires a user access token that includes the moderator:manage:banned_users scope. func (m *Moderation) UnbanUser(ctx context.Context, params *UnbanUserParams) error { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/bans", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/bans", v), nil) if err != nil { return err } diff --git a/api/moderation/update_automod_settings.go b/api/moderation/update_automod_settings.go index 9bde0c5..838a8d6 100644 --- a/api/moderation/update_automod_settings.go +++ b/api/moderation/update_automod_settings.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateAutoModSettingsParams struct { @@ -79,7 +79,6 @@ type UpdateAutoModSettingsResponse struct { // 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) { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/automod/settings", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -91,7 +90,7 @@ func (m *Moderation) UpdateAutoModSettings(ctx context.Context, params *UpdateAu } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(m.baseUrl, "moderation/automod/settings", v), r) if err != nil { return nil, err } diff --git a/api/moderation/update_shield_mode_status.go b/api/moderation/update_shield_mode_status.go index 38c2632..fe40c9a 100644 --- a/api/moderation/update_shield_mode_status.go +++ b/api/moderation/update_shield_mode_status.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateShieldModeStatusParams struct { @@ -38,7 +38,6 @@ type UpdateShieldModeStatusResponse struct { // Requires a user access token that includes the moderator:manage:shield_mode scope. func (m *Moderation) UpdateShieldModeStatus(ctx context.Context, params *UpdateShieldModeStatusParams) (*UpdateShieldModeStatusResponse, error) { v, _ := query.Values(params) - endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/shield_mode", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -50,7 +49,7 @@ func (m *Moderation) UpdateShieldModeStatus(ctx context.Context, params *UpdateS } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(m.baseUrl, "moderation/shield_mode", v), r) if err != nil { return nil, err } diff --git a/api/polls/create_poll.go b/api/polls/create_poll.go index c005aaf..1df5362 100644 --- a/api/polls/create_poll.go +++ b/api/polls/create_poll.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type CreatePollRequest struct { @@ -49,8 +50,6 @@ type CreatePollResponse struct { // // Requires a user access token that includes the channel:manage:polls scope. func (p *Polls) CreatePoll(ctx context.Context, body *CreatePollRequest) (*CreatePollResponse, error) { - endpoint := p.baseUrl.ResolveReference(&url.URL{Path: "polls"}) - r, w := io.Pipe() go func() { @@ -61,7 +60,7 @@ func (p *Polls) CreatePoll(ctx context.Context, body *CreatePollRequest) (*Creat } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(p.baseUrl, "polls"), r) if err != nil { return nil, err } diff --git a/api/polls/end_poll.go b/api/polls/end_poll.go index dfacfeb..b6f1511 100644 --- a/api/polls/end_poll.go +++ b/api/polls/end_poll.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type EndPollParams struct { @@ -30,9 +30,8 @@ type EndPollParams struct { // Requires a user access token that includes the channel:manage:polls scope. func (p *Polls) EndPoll(ctx context.Context, params *EndPollParams) error { v, _ := query.Values(params) - endpoint := p.baseUrl.ResolveReference(&url.URL{Path: "polls", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(p.baseUrl, "polls", v), nil) if err != nil { return err } diff --git a/api/polls/get_polls.go b/api/polls/get_polls.go index b99abf0..79d446d 100644 --- a/api/polls/get_polls.go +++ b/api/polls/get_polls.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -50,9 +50,8 @@ type GetPollsResponse struct { // Requires a user access token that includes the channel:read:polls or channel:manage:polls scope. func (p *Polls) GetPolls(ctx context.Context, params *GetPollsParams) (*GetPollsResponse, error) { v, _ := query.Values(params) - endpoint := p.baseUrl.ResolveReference(&url.URL{Path: "polls", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(p.baseUrl, "polls", v), nil) if err != nil { return nil, err } diff --git a/api/predictions/create_prediction.go b/api/predictions/create_prediction.go index 94faacd..26b6919 100644 --- a/api/predictions/create_prediction.go +++ b/api/predictions/create_prediction.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type CreatePredictionRequest struct { @@ -40,16 +40,15 @@ type CreatePredictionResponse struct { // The prediction runs as soon as it’s created. The broadcaster may run only one prediction at a time. // // Requires a user access token that includes the channel:manage:predictions scope. -func (c *Predictions) CreatePrediction(ctx context.Context, params *CreatePredictionRequest) (*CreatePredictionResponse, error) { +func (p *Predictions) CreatePrediction(ctx context.Context, params *CreatePredictionRequest) (*CreatePredictionResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "predictions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(p.baseUrl, "predictions", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := p.client.Do(req) if err != nil { return nil, err } diff --git a/api/predictions/end_prediction.go b/api/predictions/end_prediction.go index 382507d..761c186 100644 --- a/api/predictions/end_prediction.go +++ b/api/predictions/end_prediction.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type EndPredictionRequest struct { @@ -43,16 +43,15 @@ type EndPredictionResponse struct { // Locks, resolves, or cancels a Channel Points Prediction. // // Requires a user access token that includes the channel:manage:predictions scope. -func (c *Predictions) EndPrediction(ctx context.Context, params *EndPredictionRequest) (*EndPredictionResponse, error) { +func (p *Predictions) EndPrediction(ctx context.Context, params *EndPredictionRequest) (*EndPredictionResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "predictions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(p.baseUrl, "predictions", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := p.client.Do(req) if err != nil { return nil, err } diff --git a/api/predictions/get_predictions.go b/api/predictions/get_predictions.go index e087cbb..0d9e4e3 100644 --- a/api/predictions/get_predictions.go +++ b/api/predictions/get_predictions.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -46,16 +46,15 @@ type GetPredictionsResponse struct { // Gets a list of Channel Points Predictions that the broadcaster created. // // Requires a user access token that includes the channel:read:predictions or channel:manage:predictions scope. -func (c *Predictions) GetPredictions(ctx context.Context, params *GetPredictionsParams) (*GetPredictionsResponse, error) { +func (p *Predictions) GetPredictions(ctx context.Context, params *GetPredictionsParams) (*GetPredictionsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "predictions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(p.baseUrl, "predictions", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := p.client.Do(req) if err != nil { return nil, err } diff --git a/api/raids/cancel_a_raid.go b/api/raids/cancel_a_raid.go index 074f4c3..085a6b8 100644 --- a/api/raids/cancel_a_raid.go +++ b/api/raids/cancel_a_raid.go @@ -5,6 +5,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) // Cancel a pending raid. @@ -16,15 +18,15 @@ import ( // Requires a user access token that includes the channel:manage:raids scope. // // The broadcaster ID must match the user ID in the user access token. -func (c *Raids) CancelARaid(ctx context.Context, broadcasterID string) error { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "raids", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()}) +func (r *Raids) CancelARaid(ctx context.Context, broadcasterID string) error { + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(r.baseUrl, "raids", v), nil) if err != nil { return err } - res, err := c.client.Do(req) + res, err := r.client.Do(req) if err != nil { return err } diff --git a/api/raids/start_a_raid.go b/api/raids/start_a_raid.go index 85a52bd..8f9afd4 100644 --- a/api/raids/start_a_raid.go +++ b/api/raids/start_a_raid.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type StartARaidParams struct { @@ -42,16 +42,15 @@ type StartARaidResponse struct { // Rate Limit: The limit is 10 requests within a 10-minute window. // // Requires a user access token that includes the channel:manage:raids scope. -func (c *Raids) StartARaid(ctx context.Context, params *StartARaidParams) (*StartARaidResponse, error) { +func (r *Raids) StartARaid(ctx context.Context, params *StartARaidParams) (*StartARaidResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "raids", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(r.baseUrl, "raids", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := r.client.Do(req) if err != nil { return nil, err } diff --git a/api/schedule/create_channel_stream_schedule_segment.go b/api/schedule/create_channel_stream_schedule_segment.go index ac3d317..3a02cc2 100644 --- a/api/schedule/create_channel_stream_schedule_segment.go +++ b/api/schedule/create_channel_stream_schedule_segment.go @@ -8,6 +8,8 @@ import ( "net/http" "net/url" "time" + + "go.fifitido.net/twitch/api/endpoint" ) type CreateChannelStreamScheduleSegmentRequest struct { @@ -43,7 +45,7 @@ type CreateChannelStreamScheduleSegmentResponse struct { // // The broadcaster ID must match the user ID in the user access token. func (s *Schedule) CreateChannelStreamScheduleSegment(ctx context.Context, broadcasterId string, body *CreateChannelStreamScheduleSegmentRequest) (*CreateChannelStreamScheduleSegmentResponse, error) { - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "schedule/segment", RawQuery: url.Values{"broadcaster_id": {broadcasterId}}.Encode()}) + v := url.Values{"broadcaster_id": {broadcasterId}} r, w := io.Pipe() @@ -55,7 +57,7 @@ func (s *Schedule) CreateChannelStreamScheduleSegment(ctx context.Context, broad } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(s.baseUrl, "schedule/segment", v), r) if err != nil { return nil, err } diff --git a/api/schedule/delete_channel_stream_schedule_segment.go b/api/schedule/delete_channel_stream_schedule_segment.go index 60e018d..1d69690 100644 --- a/api/schedule/delete_channel_stream_schedule_segment.go +++ b/api/schedule/delete_channel_stream_schedule_segment.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type DeleteChannelStreamScheduleSegmentParams struct { @@ -24,9 +24,8 @@ type DeleteChannelStreamScheduleSegmentParams struct { // Requires a user access token that includes the channel:manage:schedule scope. func (s *Schedule) DeleteChannelStreamScheduleSegment(ctx context.Context, params *DeleteChannelStreamScheduleSegmentParams) error { v, _ := query.Values(params) - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "schedule/segment", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(s.baseUrl, "schedule/segment", v), nil) if err != nil { return err } diff --git a/api/schedule/get_channel_icalendar.go b/api/schedule/get_channel_icalendar.go index 2fb6bdf..19f18ba 100644 --- a/api/schedule/get_channel_icalendar.go +++ b/api/schedule/get_channel_icalendar.go @@ -3,14 +3,13 @@ package schedule import ( "context" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) // Gets the broadcaster’s streaming schedule as an iCalendar. // // The Client-Id and Authorization headers are not required. -func (s *Schedule) GetChannelICalendarURL(ctx context.Context, broadcasterId string) *url.URL { - return s.baseUrl.ResolveReference(&url.URL{ - Path: "schedule/icalendar", - RawQuery: url.Values{"broadcaster_id": {broadcasterId}}.Encode(), - }) +func (s *Schedule) GetChannelICalendarURL(ctx context.Context, broadcasterId string) string { + return endpoint.Make(s.baseUrl, "schedule/icalendar", url.Values{"broadcaster_id": {broadcasterId}}) } diff --git a/api/schedule/get_channel_stream_schedule.go b/api/schedule/get_channel_stream_schedule.go index 66e8f93..e027e1f 100644 --- a/api/schedule/get_channel_stream_schedule.go +++ b/api/schedule/get_channel_stream_schedule.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -51,9 +51,8 @@ type GetChannelStreamScheduleResponse struct { // Requires an app access token or user access token. func (s *Schedule) GetChannelStreamSchedule(ctx context.Context, params *GetChannelStreamScheduleParams) (*GetChannelStreamScheduleResponse, error) { v, _ := query.Values(params) - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "schedule", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "schedule", v), nil) if err != nil { return nil, err } diff --git a/api/schedule/update_channel_stream_schedule.go b/api/schedule/update_channel_stream_schedule.go index 5a0df27..ef2f72d 100644 --- a/api/schedule/update_channel_stream_schedule.go +++ b/api/schedule/update_channel_stream_schedule.go @@ -4,10 +4,10 @@ import ( "context" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateChannelStreamScheduleParams struct { @@ -37,9 +37,8 @@ type UpdateChannelStreamScheduleParams struct { // Requires a user access token that includes the channel:manage:schedule scope. func (s *Schedule) UpdateChannelStreamSchedule(ctx context.Context, params *UpdateChannelStreamScheduleParams) error { v, _ := query.Values(params) - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "schedule/settings", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(s.baseUrl, "schedule/settings", v), nil) if err != nil { return err } diff --git a/api/schedule/update_channel_stream_schedule_segment.go b/api/schedule/update_channel_stream_schedule_segment.go index d220375..10322e8 100644 --- a/api/schedule/update_channel_stream_schedule_segment.go +++ b/api/schedule/update_channel_stream_schedule_segment.go @@ -6,10 +6,10 @@ import ( "fmt" "io" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateChannelStreamScheduleSegmentParams struct { @@ -59,7 +59,6 @@ type UpdateChannelStreamScheduleSegmentResponse struct { // Requires a user access token that includes the channel:manage:schedule scope. func (s *Schedule) UpdateChannelStreamScheduleSegment(ctx context.Context, params *UpdateChannelStreamScheduleSegmentParams, body *UpdateChannelStreamScheduleSegmentRequest) (*UpdateChannelStreamScheduleSegmentResponse, error) { v, _ := query.Values(params) - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "schedule/segment", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -71,7 +70,7 @@ func (s *Schedule) UpdateChannelStreamScheduleSegment(ctx context.Context, param } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(s.baseUrl, "schedule/segment", v), r) if err != nil { return nil, err } diff --git a/api/search/search_categories.go b/api/search/search_categories.go index e8f3e12..a4fdd9d 100644 --- a/api/search/search_categories.go +++ b/api/search/search_categories.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -51,16 +51,15 @@ type SearchCategoriesResponse struct { // The comparison is case insensitive. // // Requires an app access token or user access token. -func (c *Search) SearchCategories(ctx context.Context, params *SearchCategoriesParams) (*SearchCategoriesResponse, error) { +func (s *Search) SearchCategories(ctx context.Context, params *SearchCategoriesParams) (*SearchCategoriesResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "search/categories", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "search/categories", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := s.client.Do(req) if err != nil { return nil, err } diff --git a/api/search/search_channels.go b/api/search/search_channels.go index 1815f6f..b103c9a 100644 --- a/api/search/search_channels.go +++ b/api/search/search_channels.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -85,16 +85,15 @@ type SearchChannelsResponse struct { // By default, the results include both live and offline channels. To get only live channels set the live_only query parameter to true. // // Requires an app access token or user access token. -func (c *Search) SearchChannels(ctx context.Context, params *SearchChannelsParams) (*SearchChannelsResponse, error) { +func (s *Search) SearchChannels(ctx context.Context, params *SearchChannelsParams) (*SearchChannelsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "search/channels", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "search/channels", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := s.client.Do(req) if err != nil { return nil, err } diff --git a/api/streams/create_stream_marker.go b/api/streams/create_stream_marker.go index 1cf8e44..d2061dc 100644 --- a/api/streams/create_stream_marker.go +++ b/api/streams/create_stream_marker.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type CreateStreamMarkerRequest struct { @@ -39,8 +40,6 @@ type CreateStreamMarkerResponse struct { // // Requires a user access token that includes the channel:manage:broadcast scope. func (s *Streams) CreateStreamMarker(ctx context.Context, body *CreateStreamMarkerRequest) (*CreateStreamMarkerResponse, error) { - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "streams/markers"}) - r, w := io.Pipe() go func() { @@ -51,7 +50,7 @@ func (s *Streams) CreateStreamMarker(ctx context.Context, body *CreateStreamMark } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(s.baseUrl, "streams/markers"), r) if err != nil { return nil, err } diff --git a/api/streams/get_followed_streams.go b/api/streams/get_followed_streams.go index b98563d..437bdbc 100644 --- a/api/streams/get_followed_streams.go +++ b/api/streams/get_followed_streams.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -44,9 +44,8 @@ type GetFollowedStreamsResponse struct { // Requires a user access token that includes the user:read:follows scope. func (s *Streams) GetFollowedStreams(ctx context.Context, params *GetFollowedStreamsParams) (*GetFollowedStreamsResponse, error) { v, _ := query.Values(params) - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "streams/followed", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "streams/followed", v), nil) if err != nil { return nil, err } diff --git a/api/streams/get_stream_key.go b/api/streams/get_stream_key.go index 5c69c3c..29c37df 100644 --- a/api/streams/get_stream_key.go +++ b/api/streams/get_stream_key.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type GetStreamKeyResponse struct { @@ -22,9 +24,9 @@ type GetStreamKeyResponse struct { // // The broadcaster ID must match the user ID in the access token. func (s *Streams) GetStreamKey(ctx context.Context, broadcasterID string) (*GetStreamKeyResponse, error) { - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "streams/key", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()}) + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "streams/key", v), nil) if err != nil { return nil, err } diff --git a/api/streams/get_stream_markers.go b/api/streams/get_stream_markers.go index 9dc6135..90ccdcf 100644 --- a/api/streams/get_stream_markers.go +++ b/api/streams/get_stream_markers.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -57,9 +57,8 @@ type GetStreamMarkersResponse struct { // Requires a user access token that includes the user:read:broadcast or channel:manage:broadcast scope. func (s *Streams) GetStreamMarkers(ctx context.Context, params *GetStreamMarkersParams) (*GetStreamMarkersResponse, error) { v, _ := query.Values(params) - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "streams/markers", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "streams/markers", v), nil) if err != nil { return nil, err } diff --git a/api/streams/get_streams.go b/api/streams/get_streams.go index 6f3b2d1..e88e210 100644 --- a/api/streams/get_streams.go +++ b/api/streams/get_streams.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -78,9 +78,8 @@ type GetStreamsResponse struct { // Requires an app access token or user access token. func (s *Streams) GetStreams(ctx context.Context, params *GetStreamsParams) (*GetStreamsResponse, error) { v, _ := query.Values(params) - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "streams", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "streams", v), nil) if err != nil { return nil, err } diff --git a/api/subscriptions/check_user_subscription.go b/api/subscriptions/check_user_subscription.go index 3e62954..562ff96 100644 --- a/api/subscriptions/check_user_subscription.go +++ b/api/subscriptions/check_user_subscription.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type CheckUserSubscriptionParams struct { @@ -63,9 +63,8 @@ type UserSubscription struct { // A Twitch extensions may use an app access token if the broadcaster has granted the user:read:subscriptions scope from within the Twitch Extensions manager. func (s *Subscriptions) CheckUserSubscription(ctx context.Context, params *CheckUserSubscriptionParams) (*CheckUserSubscriptionResponse, error) { v, _ := query.Values(params) - endpoint := s.baseUrl.ResolveReference(&url.URL{Path: "subscriptions/user", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "subscriptions/user", v), nil) if err != nil { return nil, err } diff --git a/api/subscriptions/get_broadcaster_subscriptions.go b/api/subscriptions/get_broadcaster_subscriptions.go index ce6f668..c5de6a5 100644 --- a/api/subscriptions/get_broadcaster_subscriptions.go +++ b/api/subscriptions/get_broadcaster_subscriptions.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -104,16 +104,15 @@ type BroadcasterSubscription struct { // Requires a user access token that includes the channel:read:subscriptions scope. // // A Twitch extensions may use an app access token if the broadcaster has granted the channel:read:subscriptions scope from within the Twitch Extensions manager. -func (c *Subscriptions) GetBroadcasterSubscriptions(ctx context.Context, params *GetBroadcasterSubscriptionsParams) (*GetBroadcasterSubscriptionsResponse, error) { +func (s *Subscriptions) GetBroadcasterSubscriptions(ctx context.Context, params *GetBroadcasterSubscriptionsParams) (*GetBroadcasterSubscriptionsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "subscriptions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(s.baseUrl, "subscriptions", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := s.client.Do(req) if err != nil { return nil, err } diff --git a/api/teams/get_channel_teams.go b/api/teams/get_channel_teams.go index 20b4430..5fc8911 100644 --- a/api/teams/get_channel_teams.go +++ b/api/teams/get_channel_teams.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "time" + + "go.fifitido.net/twitch/api/endpoint" ) type GetChannelTeamsResponse struct { @@ -56,15 +58,15 @@ type ChannelTeam struct { // Gets the list of Twitch teams that the broadcaster is a member of. // // Requires an app access token or user access token. -func (c *Teams) GetChannelTeams(ctx context.Context, broadcasterID string) (*GetChannelTeamsResponse, error) { - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "teams/channel", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()}) +func (t *Teams) GetChannelTeams(ctx context.Context, broadcasterID string) (*GetChannelTeamsResponse, error) { + v := url.Values{"broadcaster_id": {broadcasterID}} - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(t.baseUrl, "teams/channel", v), nil) if err != nil { return nil, err } - res, err := c.client.Do(req) + res, err := t.client.Do(req) if err != nil { return nil, err } diff --git a/api/teams/get_teams.go b/api/teams/get_teams.go index 931210e..3c4ae2d 100644 --- a/api/teams/get_teams.go +++ b/api/teams/get_teams.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetTeamsParams struct { @@ -68,16 +68,15 @@ type Team struct { // Gets information about the specified Twitch team. Read More // // Requires an app access token or user access token. -func (c *Teams) GetTeams(ctx context.Context, params *GetTeamsParams) (*GetTeamsResponse, error) { +func (t *Teams) GetTeams(ctx context.Context, params *GetTeamsParams) (*GetTeamsResponse, error) { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "teams", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(t.baseUrl, "teams", v), nil) if err != nil { return nil, err } - resp, err := c.client.Do(req) + resp, err := t.client.Do(req) if err != nil { return nil, err } diff --git a/api/users/block_user.go b/api/users/block_user.go index 9889a3c..276526a 100644 --- a/api/users/block_user.go +++ b/api/users/block_user.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type BlockUserParams struct { @@ -33,9 +33,8 @@ type BlockUserParams struct { // Requires a user access token that includes the user:manage:blocked_users scope. func (u *Users) BlockUser(ctx context.Context, params *BlockUserParams) error { v, _ := query.Values(params) - endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/blocks", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.Make(u.baseUrl, "users/blocks", v), nil) if err != nil { return err } diff --git a/api/users/get_user_active_extensions.go b/api/users/get_user_active_extensions.go index 453d7d3..89b3521 100644 --- a/api/users/get_user_active_extensions.go +++ b/api/users/get_user_active_extensions.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetUserActiveExtensionsParams struct { @@ -31,9 +31,8 @@ type GetUserActiveExtensionsResponse struct { // Requires an app access token or user access token. func (u *Users) GetUserActiveExtensions(ctx context.Context, params *GetUserActiveExtensionsParams) (*GetUserActiveExtensionsResponse, error) { v, _ := query.Values(params) - endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/extensions", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(u.baseUrl, "users/extensions", v), nil) if err != nil { return nil, err } diff --git a/api/users/get_user_block_list.go b/api/users/get_user_block_list.go index 6ad62c7..d230b6b 100644 --- a/api/users/get_user_block_list.go +++ b/api/users/get_user_block_list.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -46,9 +46,8 @@ type GetUserBlockListResponse struct { // Requires a user access token that includes the user:read:blocked_users scope. func (u *Users) GetUserBlockList(ctx context.Context, params *GetUserBlockListParams) (*GetUserBlockListResponse, error) { v, _ := query.Values(params) - endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/blocks", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(u.baseUrl, "users/blocks", v), nil) if err != nil { return nil, err } diff --git a/api/users/get_user_extensions.go b/api/users/get_user_extensions.go index 5dde947..eced9f6 100644 --- a/api/users/get_user_extensions.go +++ b/api/users/get_user_extensions.go @@ -5,7 +5,8 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type GetUserExtensionsResponse struct { @@ -36,9 +37,7 @@ type GetUserExtensionsResponse struct { // Requires a user access token that includes the user:read:broadcast or user:edit:broadcast scope. // To include inactive extensions, you must include the user:edit:broadcast scope. func (u *Users) GetUserExtensions(ctx context.Context) (*GetUserExtensionsResponse, error) { - endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/extensions/list"}) - - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(u.baseUrl, "users/extensions/list"), nil) if err != nil { return nil, err } diff --git a/api/users/get_users.go b/api/users/get_users.go index 982b0cc..05e86fd 100644 --- a/api/users/get_users.go +++ b/api/users/get_users.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type GetUsersParams struct { @@ -39,11 +39,8 @@ type GetUsersResponse struct { // Requires an app access token or user access token. func (u *Users) GetUsers(ctx context.Context, params *GetUsersParams) (*GetUsersResponse, error) { v, _ := query.Values(params) - endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users", RawQuery: v.Encode()}) - fmt.Printf("endpoint: %s\n", endpoint.String()) - - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(u.baseUrl, "users", v), nil) if err != nil { return nil, err } diff --git a/api/users/unblock_user.go b/api/users/unblock_user.go index 86d57b7..723a830 100644 --- a/api/users/unblock_user.go +++ b/api/users/unblock_user.go @@ -5,6 +5,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) // Removes the user from the broadcaster’s list of blocked users. @@ -12,9 +14,9 @@ import ( // // Requires a user access token that includes the user:manage:blocked_users scope. func (u *Users) UnblockUser(ctx context.Context, targetUserID string) error { - endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/blocks", RawQuery: url.Values{"target_user_id": {targetUserID}}.Encode()}) + v := url.Values{"target_user_id": {targetUserID}} - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(u.baseUrl, "users/blocks", v), nil) if err != nil { return err } diff --git a/api/users/update_user.go b/api/users/update_user.go index 3fa64cd..2deaee2 100644 --- a/api/users/update_user.go +++ b/api/users/update_user.go @@ -5,9 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type UpdateUserParams struct { @@ -29,9 +29,8 @@ type UpdateUserResponse struct { // Requires a user access token that includes the user:edit scope. func (u *Users) UpdateUser(ctx context.Context, params *UpdateUserParams) (*UpdateUserResponse, error) { v, _ := query.Values(params) - endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(u.baseUrl, "users", v), nil) if err != nil { return nil, err } diff --git a/api/users/update_user_extensions.go b/api/users/update_user_extensions.go index c64b199..3e7de96 100644 --- a/api/users/update_user_extensions.go +++ b/api/users/update_user_extensions.go @@ -6,7 +6,8 @@ import ( "fmt" "io" "net/http" - "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type UpdateUserExtensionsRequest struct { @@ -35,8 +36,6 @@ type UpdateUserExtensionsResponse struct { // // Requires a user access token that includes the user:edit:broadcast scope. func (u *Users) UpdateUserExtensions(ctx context.Context, body *UpdateUserExtensionsRequest) (*UpdateUserExtensionsResponse, error) { - endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/extensions"}) - r, w := io.Pipe() go func() { @@ -47,7 +46,7 @@ func (u *Users) UpdateUserExtensions(ctx context.Context, body *UpdateUserExtens } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.Make(u.baseUrl, "users/extensions"), r) if err != nil { return nil, err } diff --git a/api/videos/delete_videos.go b/api/videos/delete_videos.go index a7f3c3a..a098ca2 100644 --- a/api/videos/delete_videos.go +++ b/api/videos/delete_videos.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "net/url" + + "go.fifitido.net/twitch/api/endpoint" ) type DeleteVideosResponse struct { @@ -16,15 +18,15 @@ type DeleteVideosResponse struct { // Deletes one or more videos. You may delete past broadcasts, highlights, or uploads. // // Requires a user access token that includes the channel:manage:videos scope. -func (v *Videos) DeleteVideos(ctx context.Context, ids []string) (*DeleteVideosResponse, error) { - endpoint := v.baseUrl.ResolveReference(&url.URL{Path: "videos", RawQuery: url.Values{"id": ids}.Encode()}) +func (i *Videos) DeleteVideos(ctx context.Context, ids []string) (*DeleteVideosResponse, error) { + v := url.Values{"id": ids} - req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(i.baseUrl, "videos", v), nil) if err != nil { return nil, err } - res, err := v.client.Do(req) + res, err := i.client.Do(req) if err != nil { return nil, err } diff --git a/api/videos/get_videos.go b/api/videos/get_videos.go index 83b906b..6787e2f 100644 --- a/api/videos/get_videos.go +++ b/api/videos/get_videos.go @@ -5,10 +5,10 @@ import ( "encoding/json" "fmt" "net/http" - "net/url" "time" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" "go.fifitido.net/twitch/api/types" ) @@ -184,16 +184,15 @@ type Video struct { // The filters apply only if you get videos by user ID or game ID. // // Requires an app access token or user access token. -func (vid *Videos) GetVideos(ctx context.Context, params *GetVideosParams) (*GetVideosResponse, error) { +func (i *Videos) GetVideos(ctx context.Context, params *GetVideosParams) (*GetVideosResponse, error) { v, _ := query.Values(params) - endpoint := vid.baseUrl.ResolveReference(&url.URL{Path: "videos", RawQuery: v.Encode()}) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(i.baseUrl, "videos", v), nil) if err != nil { return nil, err } - res, err := vid.client.Do(req) + res, err := i.client.Do(req) if err != nil { return nil, err } diff --git a/api/whispers/send_whisper.go b/api/whispers/send_whisper.go index 35c55b1..c6c9941 100644 --- a/api/whispers/send_whisper.go +++ b/api/whispers/send_whisper.go @@ -6,9 +6,9 @@ import ( "fmt" "io" "net/http" - "net/url" "github.com/google/go-querystring/query" + "go.fifitido.net/twitch/api/endpoint" ) type SendWhisperParams struct { @@ -48,7 +48,6 @@ type SendWhisperRequest struct { // Requires a user access token that includes the user:manage:whispers scope. func (c *Whispers) SendWhisper(ctx context.Context, params *SendWhisperParams, body *SendWhisperRequest) error { v, _ := query.Values(params) - endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "whispers", RawQuery: v.Encode()}) r, w := io.Pipe() @@ -60,7 +59,7 @@ func (c *Whispers) SendWhisper(ctx context.Context, params *SendWhisperParams, b } }() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), r) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "whispers", v), r) if err != nil { return err }