Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SnoozeNextAd, GetAdSchedule, ad related scopes #372

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions TwitchLib.Api.Core.Enums/AuthScopesEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TwitchLib.Api.Core.Enums
{
public enum AuthScopes

Check warning on line 5 in TwitchLib.Api.Core.Enums/AuthScopesEnum.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

Missing XML comment for publicly visible type or member 'AuthScopes'
{
/// <summary>
/// Any scope.
Expand Down Expand Up @@ -48,12 +48,22 @@
/// View Bits information for a channel.
/// </summary>
Bits_Read,

/// <summary>
/// Allows the client’s bot users access to a channel.
/// </summary>
Channel_Bot,

/// <summary>
/// Run commercials on a channel.
/// </summary>
Channel_Edit_Commercial,


/// <summary>
/// Manage ads schedule on a channel.
/// </summary>
Channel_Manage_Ads,

/// <summary>
/// Manage a channel’s broadcast configuration, including updating channel configuration and managing stream markers and stream tags.
/// </summary>
Expand Down Expand Up @@ -108,7 +118,12 @@
/// Add or remove the VIP role from users in your channel.
/// </summary>
Channel_Manage_VIPs,


/// <summary>
/// Read the ads schedule and details on your channel.
/// </summary>
Channel_Read_Ads,

/// <summary>
/// Read charity campaign details and user donations on your channel.
/// </summary>
Expand Down Expand Up @@ -263,7 +278,13 @@
/// View a broadcaster’s shoutouts.
/// </summary>
Moderator_Read_Shoutouts,



/// <summary>
/// Allows client’s bot to act as this user.
/// </summary>
User_Bot,

/// <summary>
/// Manage a user object.
/// </summary>
Expand Down Expand Up @@ -299,6 +320,11 @@
/// View a user’s broadcasting configuration, including Extension configurations.
/// </summary>
User_Read_Broadcast,

/// <summary>
/// View live stream chat and room messages.
/// </summary>
User_Read_Chat,

/// <summary>
/// View a user’s email address.
Expand Down
10 changes: 10 additions & 0 deletions TwitchLib.Api.Core/Common/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static string AuthScopesToString(AuthScopes scope)
AuthScopes.Analytics_Read_Extensions => "analytics:read:extensions",
AuthScopes.Analytics_Read_Games => "analytics:read:games",
AuthScopes.Bits_Read => "bits:read",
AuthScopes.Channel_Bot => "channel:bot",
AuthScopes.Channel_Manage_Ads => "channel:manage:ads",
AuthScopes.Channel_Edit_Commercial => "channel:edit:commercial",
AuthScopes.Channel_Manage_Broadcast => "channel:manage:broadcast",
AuthScopes.Channel_Manage_Extensions => "channel:manage:extensions",
Expand All @@ -46,6 +48,7 @@ public static string AuthScopesToString(AuthScopes scope)
AuthScopes.Channel_Manage_VIPs => "channel:manage:vips",
AuthScopes.Channel_Manage_Guest_Star => "channel:manage:guest_star",
AuthScopes.Channel_Manage_Raids => "channel:manage:raids",
AuthScopes.Channel_Read_Ads => "channel:read:ads",
AuthScopes.Channel_Read_Charity => "channel:read:charity",
AuthScopes.Channel_Read_Editors => "channel:read:editors",
AuthScopes.Channel_Read_Goals => "channel:read:goals",
Expand All @@ -59,10 +62,12 @@ public static string AuthScopesToString(AuthScopes scope)
AuthScopes.Channel_Read_Guest_Star => "channel:read:guest_star",
AuthScopes.Clips_Edit => "clips:edit",
AuthScopes.Moderation_Read => "moderation:read",
AuthScopes.User_Bot => "user:bot",
AuthScopes.User_Edit => "user:edit",
AuthScopes.User_Edit_Follows => "user:edit:follows",
AuthScopes.User_Read_BlockedUsers => "user:read:blocked_users",
AuthScopes.User_Read_Broadcast => "user:read:broadcast",
AuthScopes.User_Read_Chat => "user:read:chat",
AuthScopes.User_Read_Email => "user:read:email",
AuthScopes.User_Read_Follows => "user:read:follows",
AuthScopes.User_Read_Subscriptions => "user:read:subscriptions",
Expand Down Expand Up @@ -110,7 +115,9 @@ public static AuthScopes StringToScope(string scope)
"analytics:read:extensions" => AuthScopes.Analytics_Read_Extensions,
"analytics:read:games" => AuthScopes.Analytics_Read_Games,
"bits:read" => AuthScopes.Bits_Read,
"channel:bot" => AuthScopes.Channel_Bot,
"channel:edit:commercial" => AuthScopes.Channel_Edit_Commercial,
"channel:manage:ads" => AuthScopes.Channel_Manage_Ads,
"channel:manage:broadcast" => AuthScopes.Channel_Manage_Broadcast,
"channel:manage:extensions" => AuthScopes.Channel_Manage_Extensions,
"channel:manage:moderators" => AuthScopes.Channel_Manage_Moderators,
Expand All @@ -122,6 +129,7 @@ public static AuthScopes StringToScope(string scope)
"channel:manage:vips" => AuthScopes.Channel_Manage_VIPs,
"channel:manage:guest_star" => AuthScopes.Channel_Manage_Guest_Star,
"channel:manage:raids" => AuthScopes.Channel_Manage_Raids,
"channel:read:ads" => AuthScopes.Channel_Read_Ads,
"channel:read:charity" => AuthScopes.Channel_Read_Charity,
"channel:read:editors" => AuthScopes.Channel_Read_Editors,
"channel:read:goals" => AuthScopes.Channel_Read_Goals,
Expand All @@ -135,10 +143,12 @@ public static AuthScopes StringToScope(string scope)
"channel:read:guest_star" => AuthScopes.Channel_Read_Guest_Star,
"clips:edit" => AuthScopes.Clips_Edit,
"moderation:read" => AuthScopes.Moderation_Read,
"user:bot" => AuthScopes.User_Bot,
"user:edit" => AuthScopes.User_Edit,
"user:edit:follows" => AuthScopes.User_Edit_Follows,
"user:read:blocked_users" => AuthScopes.User_Read_BlockedUsers,
"user:read:broadcast" => AuthScopes.User_Read_Broadcast,
"user:read:chat" => AuthScopes.User_Read_Chat,
"user:read:email" => AuthScopes.User_Read_Email,
"user:read:follows" => AuthScopes.User_Read_Follows,
"user:read:subscriptions" => AuthScopes.User_Read_Subscriptions,
Expand Down
44 changes: 44 additions & 0 deletions TwitchLib.Api.Helix.Models/Channels/GetAdSchedule/AdSchedule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace TwitchLib.Api.Helix.Models.Channels.GetAdSchedule
{
/// <summary>
/// <para>Contains information related to the channel’s ad schedule.</para>
/// </summary>
public class AdSchedule
{
/// <summary>
/// <para>The number of snoozes available for the broadcaster.</para>
/// </summary>
[JsonProperty(PropertyName = "snooze_count")]
public int SnoozeCount { get; protected set; }
/// <summary>
/// <para>The UTC timestamp when the broadcaster will gain an additional snooze, in RFC3339 format.</para>
/// </summary>
[JsonProperty(PropertyName = "snooze_refresh_at")]
public string SnoozeRefreshAt { get; protected set; }
/// <summary>
/// <para>The UTC timestamp of the broadcaster’s next scheduled ad, in RFC3339 format. Empty if the channel has no ad scheduled or is not live.</para>
/// </summary>
[JsonProperty(PropertyName = "next_ad_at")]
public string NextAdAt { get; protected set; }
/// <summary>
/// <para>The length in seconds of the scheduled upcoming ad break.</para>
/// </summary>
[JsonProperty(PropertyName = "length_seconds")]
Syzuna marked this conversation as resolved.
Show resolved Hide resolved
public int LengthSeconds { get;protected set; }
/// <summary>
/// <para>The UTC timestamp of the broadcaster’s last ad-break, in RFC3339 format. Empty if the channel has not run an ad or is not live.</para>
/// </summary>
[JsonProperty(PropertyName = "last_ad_at")]
public string LastAdAt { get; protected set; }
/// <summary>
/// <para>The amount of pre-roll free time remaining for the channel in seconds. Returns 0 if they are currently not pre-roll free.</para>
/// </summary>
[JsonProperty(PropertyName = "preroll_free_time_seconds")]
public int PrerollFreeTimeSeconds { get; protected set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace TwitchLib.Api.Helix.Models.Channels.GetAdSchedule
{
/// <summary>
/// <para>Response to getting ad schedule</para>
/// </summary>
public class GetAdScheduleResponse
{
/// <summary>
/// <para>A list that contains information related to the channel’s ad schedule.</para>
/// </summary>
[JsonProperty(PropertyName = "snooze_count")]
Syzuna marked this conversation as resolved.
Show resolved Hide resolved
public AdSchedule[] Data { get; protected set; }
}
}
29 changes: 29 additions & 0 deletions TwitchLib.Api.Helix.Models/Channels/SnoozeNextAd/SnoozeNextAd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace TwitchLib.Api.Helix.Models.Channels.SnoozeNextAd
{
/// <summary>
/// <para>Contains information about the channel’s snoozes and next upcoming ad after successfully snoozing.</para>
/// </summary>
public class SnoozeNextAd
{
/// <summary>
/// <para>The number of snoozes available for the broadcaster.</para>
/// </summary>
[JsonProperty(PropertyName = "snooze_count")]
public int SnoozeCount { get; protected set; }
/// <summary>
/// The UTC timestamp when the broadcaster will gain an additional snooze, in RFC3339 format.
/// </summary>
[JsonProperty(PropertyName = "snooze_refresh_at")]
public string SnoozeRefreshAt { get; protected set; }
/// <summary>
/// The UTC timestamp of the broadcaster’s next scheduled ad, in RFC3339 format.
/// </summary>
[JsonProperty(PropertyName = "next_ad_at")]
public string NextAdAt { get; protected set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace TwitchLib.Api.Helix.Models.Channels.SnoozeNextAd
{
/// <summary>
/// <para>Response to attempting to snooze an ad.</para>
/// </summary>
public class SnoozeNextAdResponse
{
/// <summary>
/// <para>A list that contains information about the channel’s snoozes and next upcoming ad after successfully snoozing.</para>
/// </summary>
[JsonProperty(PropertyName = "data")]
public SnoozeNextAd[] Data { get; protected set; }
}
}
47 changes: 47 additions & 0 deletions TwitchLib.Api.Helix/Channels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using TwitchLib.Api.Core.Enums;
using TwitchLib.Api.Core.Exceptions;
using TwitchLib.Api.Core.Interfaces;
using TwitchLib.Api.Helix.Models.Channels.GetAdSchedule;
using TwitchLib.Api.Helix.Models.Channels.GetChannelEditors;
using TwitchLib.Api.Helix.Models.Channels.GetChannelFollowers;
using TwitchLib.Api.Helix.Models.Channels.GetChannelInformation;
using TwitchLib.Api.Helix.Models.Channels.GetChannelVIPs;
using TwitchLib.Api.Helix.Models.Channels.GetFollowedChannels;
using TwitchLib.Api.Helix.Models.Channels.ModifyChannelInformation;
using TwitchLib.Api.Helix.Models.Channels.SnoozeNextAd;

namespace TwitchLib.Api.Helix
{
Expand Down Expand Up @@ -280,5 +282,50 @@ public Task<GetChannelFollowersResponse> GetChannelFollowersAsync(string broadca
}

#endregion

#region GetAdSchedule

/// <summary>
/// Returns ad schedule related information, including snooze, when the last ad was run, when the next ad is scheduled, and if the channel is currently in pre-roll free time.
/// </summary>
/// <param name="broadcasterId">The broadcaster's ID. Ad schedule is relevant to this broadcaster, and so should the auth.</param>
/// <param name="accessToken"> Optional access token to override the use of the stored one in the TwitchAPI instance</param>
/// <returns cref="GetAdScheduleResponse"></returns>
public Task<GetAdScheduleResponse> GetAdScheduleAsync(string broadcasterId, string accessToken = null)
{
if (string.IsNullOrWhiteSpace(broadcasterId))
throw new BadParameterException("broadcasterId must be set");
var getParams = new List<KeyValuePair<string, string>>
{

new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
};

return TwitchGetGenericAsync<GetAdScheduleResponse>("/channels/ads", ApiVersion.Helix, getParams, accessToken);
}

#endregion

#region SnoozeNextAd

/// <summary>
/// If available, pushes back the timestamp of the upcoming automatic mid-roll ad by 5 minutes. This endpoint duplicates the snooze functionality in the creator dashboard’s Ads Manager.
/// </summary>
/// <param name="broadcasterId">The broadcaster's ID. Ad snoozing is relevant to this broadcaster, and so should the auth.</param>
/// <param name="accessToken"> Optional access token to override the use of the stored one in the TwitchAPI instance</param>
/// <returns cref="SnoozeNextAdResponse"></returns>
public Task<SnoozeNextAdResponse> SnoozeNextAd(string broadcasterId, string accessToken = null)
{
if (string.IsNullOrWhiteSpace(broadcasterId))
throw new BadParameterException("broadcasterId must be set");
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
};

return TwitchPostGenericAsync<SnoozeNextAdResponse>("/channels/ads/schedule/snooze", ApiVersion.Helix, null, getParams, accessToken);
}

#endregion
}
}
Loading