Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion TwitchLib.Api.Core/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected async Task<KeyValuePair<int, string>> TwitchDeleteAsync(string resourc
return await _rateLimiter.Perform(async () => (await _http.GeneralRequestAsync(url, "DELETE", null, api, clientId, accessToken).ConfigureAwait(false))).ConfigureAwait(false);
}

protected async Task<T> TwitchPostGenericAsync<T>(string resource, ApiVersion api, string payload, List<KeyValuePair<string, string>>? getParams = null, string? accessToken = null, string? clientId = null, string? customBase = null)
protected async Task<T> TwitchPostGenericAsync<T>(string resource, ApiVersion api, string? payload, List<KeyValuePair<string, string>>? getParams = null, string? accessToken = null, string? clientId = null, string? customBase = null)
{
var url = ConstructResourceUrl(resource, getParams, api, customBase);

Expand Down
7 changes: 7 additions & 0 deletions TwitchLib.Api.Core/Exceptions/BadParameterException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public static void ThrowIfNotBetween(int value, int min, int max, [CallerArgumen
throw new BadParameterException($"Parameter '{paramName}' cannot be less than {min}(inclusive) or greater than {max}(inclusive).");
}
}
public static void ThrowIfNotBetween(float value, float min, float max, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
if (value < min || value > max)
{
throw new BadParameterException($"Parameter '{paramName}' cannot be less than {min}(inclusive) or greater than {max}(inclusive).");
}
}

public static void ThrowIfCollectionNullOrEmptyOrGreaterThan<T>(List<T> value, int max, [CallerArgumentExpression(nameof(value))] string? paramName = null)
{
Expand Down
7 changes: 3 additions & 4 deletions TwitchLib.Api.Helix.Models/Clips/CreateClip/CreatedClip.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace TwitchLib.Api.Helix.Models.Clips.CreateClip;

Expand All @@ -13,11 +12,11 @@ public class CreatedClip
/// <para> The URL is valid for up to 24 hours or until the clip is published, whichever comes first.</para>
/// </summary>
[JsonProperty(PropertyName = "edit_url")]
public string EditUrl { get; protected set; }
public string EditUrl { get; protected set; } = null!;

/// <summary>
/// An ID that uniquely identifies the clip.
/// </summary>
[JsonProperty(PropertyName = "id")]
public string Id { get; protected set; }
public string Id { get; protected set; } = null!;
}
38 changes: 38 additions & 0 deletions TwitchLib.Api.Helix.Models/Clips/CreateClip/CreatedClipRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.Generic;

namespace TwitchLib.Api.Helix.Models.Clips.CreateClip;

public class CreatedClipRequest
{
/// <summary>
/// The ID of the broadcaster whose stream you want to create a clip from.
/// </summary>
public string BroadcasterId { get; set; } = null!;

/// <summary>
/// The title of the clip.
/// </summary>
public string? Title { get; set; }

/// <summary>
/// The length of the clip in seconds. Possible values range from 5 to 60 inclusively with a precision of 0.1. The default is 30.
/// </summary>
public float? Duration { get; set; }

/// <inheritdoc/>
public virtual List<KeyValuePair<string, string>> ToParams()
{
var getParams = new List<KeyValuePair<string, string>>
{
new("broadcaster_id", BroadcasterId),
};

if (Title is not null)
getParams.Add(new("title", Title));

if (Duration is not null)
getParams.Add(new("duration", Duration.Value.ToString()));

return getParams;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace TwitchLib.Api.Helix.Models.Clips.CreateClip;

Expand All @@ -12,5 +11,5 @@ public class CreatedClipResponse
/// Contains clip's ID and edit_URL that can be used to edit the clip's title, identify the part of the clip to publish, and publish the clip.
/// </summary>
[JsonProperty(PropertyName = "data")]
public CreatedClip[] CreatedClips { get; protected set; }
public CreatedClip[] CreatedClips { get; protected set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;

namespace TwitchLib.Api.Helix.Models.Clips.CreateClipFromVod;

/// <summary>
/// A Twitch clip created from CreateClipFromVod
/// </summary>
public class CreatedClipFromVod
{
/// <summary>
/// An ID that uniquely identifies the clip.
/// </summary>
[JsonProperty(PropertyName = "id")]
public string Id { get; protected set; } = null!;

/// <summary>
/// <para>A URL that you can use to edit the clip’s title, identify the part of the clip to publish, and publish the clip.</para>
/// <para> The URL is valid for up to 24 hours or until the clip is published, whichever comes first.</para>
/// </summary>
[JsonProperty(PropertyName = "edit_url")]
public string EditUrl { get; protected set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;

namespace TwitchLib.Api.Helix.Models.Clips.CreateClipFromVod;

public class CreatedClipFromVodRequest
{
/// <summary>
/// The user ID of the editor for the channel you want to create a clip for. If using the broadcaster’s auth token, this is the same as broadcaster_id. This must match the user_id in the user access token.
/// </summary>
public string EditorId { get; set; } = null!;

/// <summary>
/// The user ID for the channel you want to create a clip for.
/// </summary>
public string BroadcasterId { get; set; } = null!;

/// <summary>
/// ID of the VOD the user wants to clip.
/// </summary>
public string VodId { get; set; } = null!;

/// <summary>
/// Offset in the VOD to create the clip.
/// </summary>
public int VodOffset { get; set; }

/// <summary>
/// The length of the clip, in seconds. Precision is 0.1. Defaults to 30. Min: 5 seconds, Max: 60 seconds.
/// </summary>
public float? Duration { get; set; }

/// <summary>
/// The title of the clip.
/// </summary>
public string Title { get; set; } = null!;

/// <inheritdoc/>
public virtual List<KeyValuePair<string, string>> ToParams()
{
var getParams = new List<KeyValuePair<string, string>>
{
new("editor_id", EditorId),
new("broadcaster_id", BroadcasterId),
new("vod_offset", VodId),
new("duration", VodOffset.ToString()),
new("title", Title),
};

if (Duration is not null)
{
getParams.Add(new("user_id", Duration.Value.ToString()));
}

return getParams;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;
using TwitchLib.Api.Helix.Models.Clips.CreateClip;

namespace TwitchLib.Api.Helix.Models.Clips.CreateClipFromVod;

/// <summary>
/// Response for CreateClipFromVod which creates a clip from the broadcaster's stream.
/// </summary>
public class CreatedClipFromVodResponse
{
/// <summary>
/// A list containing the created clip.
/// </summary>
[JsonProperty(PropertyName = "data")]
public CreatedClip[] Data { get; protected set; } = null!;
}
30 changes: 15 additions & 15 deletions TwitchLib.Api.Helix.Models/Clips/GetClips/Clip.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace TwitchLib.Api.Helix.Models.Clips.GetClips;

Expand All @@ -12,69 +11,69 @@ public class Clip
/// An ID that uniquely identifies the clip.
/// </summary>
[JsonProperty(PropertyName = "id")]
public string Id { get; protected set; }
public string Id { get; protected set; } = null!;

/// <summary>
/// A URL to the clip.
/// </summary>
[JsonProperty(PropertyName = "url")]
public string Url { get; protected set; }
public string Url { get; protected set; } = null!;

/// <summary>
/// A URL that you can use in an iframe to embed the clip.
/// </summary>
[JsonProperty(PropertyName = "embed_url")]
public string EmbedUrl { get; protected set; }
public string EmbedUrl { get; protected set; } = null!;

/// <summary>
/// An ID that identifies the broadcaster that the video was clipped from.
/// </summary>
[JsonProperty(PropertyName = "broadcaster_id")]
public string BroadcasterId { get; protected set; }
public string BroadcasterId { get; protected set; } = null!;

/// <summary>
/// The broadcaster’s display name.
/// </summary>
[JsonProperty(PropertyName = "broadcaster_name")]
public string BroadcasterName { get; protected set; }
public string BroadcasterName { get; protected set; } = null!;

/// <summary>
/// An ID that identifies the user that created the clip.
/// </summary>
[JsonProperty(PropertyName = "creator_id")]
public string CreatorId { get; protected set; }
public string CreatorId { get; protected set; } = null!;

/// <summary>
/// The display name of the user that created the clip.
/// </summary>
[JsonProperty(PropertyName = "creator_name")]
public string CreatorName { get; protected set; }
public string CreatorName { get; protected set; } = null!;

/// <summary>
/// <para>An ID that identifies the video that the clip came from.</para>
/// <para>This field contains an empty string if the video is not available.</para>
/// </summary>
[JsonProperty(PropertyName = "video_id")]
public string VideoId { get; protected set; }
public string VideoId { get; protected set; } = null!;

/// <summary>
/// The ID of the game that was being played when the clip was created.
/// </summary>
[JsonProperty(PropertyName = "game_id")]
public string GameId { get; protected set; }
public string GameId { get; protected set; } = null!;

/// <summary>
/// <para>The ISO 639-1 two-letter language code that the broadcaster broadcasts in. For example, en for English.</para>
/// <para>The value is other if the broadcaster uses a language that Twitch doesn’t support.</para>
/// </summary>
[JsonProperty(PropertyName = "language")]
public string Language { get; protected set; }
public string Language { get; protected set; } = null!;

/// <summary>
/// The title of the clip.
/// </summary>
[JsonProperty(PropertyName = "title")]
public string Title { get; protected set; }
public string Title { get; protected set; } = null!;

/// <summary>
/// The number of times the clip has been viewed.
Expand All @@ -86,13 +85,13 @@ public class Clip
/// The date and time of when the clip was created. The date and time is in RFC3339 format.
/// </summary>
[JsonProperty(PropertyName = "created_at")]
public string CreatedAt { get; protected set; }
public string CreatedAt { get; protected set; } = null!;

/// <summary>
/// A URL to a thumbnail image of the clip.
/// </summary>
[JsonProperty(PropertyName = "thumbnail_url")]
public string ThumbnailUrl { get; protected set; }
public string ThumbnailUrl { get; protected set; } = null!;

/// <summary>
/// The length of the clip, in seconds. Precision is 0.1.
Expand All @@ -105,6 +104,7 @@ public class Clip
/// <para>Is null if the video is not available or hasn’t been created yet from the live stream (see video_id).</para>
/// <para>Note that there’s a delay between when a clip is created during a broadcast and when the offset is set. During the delay period, vod_offset is null. The delay is indeterminant but is typically minutes long.</para>
/// </summary>
// TODO: breaking change: make nullable
[JsonProperty(PropertyName = "vod_offset")]
public int VodOffset { get; protected set; }

Expand Down
7 changes: 3 additions & 4 deletions TwitchLib.Api.Helix.Models/Clips/GetClips/GetClipsResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using Newtonsoft.Json;
using Newtonsoft.Json;
using TwitchLib.Api.Helix.Models.Common;

namespace TwitchLib.Api.Helix.Models.Clips.GetClips;
Expand All @@ -15,12 +14,12 @@ public class GetClipsResponse
/// <para>For lists returned by id, the list is in the same order as the input IDs.</para>
/// </summary>
[JsonProperty(PropertyName = "data")]
public Clip[] Clips { get; protected set; }
public Clip[] Clips { get; protected set; } = null!;

/// <summary>
/// <para>The information used to page through the list of results.<br/>
/// The object is empty if there are no more pages left to page through.</para>
/// </summary>
[JsonProperty(PropertyName = "pagination")]
public Pagination Pagination { get; protected set; }
public Pagination Pagination { get; protected set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace TwitchLib.Api.Helix.Models.Clips.GetClipsDownload;

Expand All @@ -12,5 +11,5 @@ public class GetClipsDownloadResponse
/// List of clips and their download URLs.
/// </summary>
[JsonProperty(PropertyName = "data")]
public ClipDownload[] Clips { get; protected set; }
public ClipDownload[] Clips { get; protected set; } = null!;
}
Loading
Loading