Skip to content

Commit

Permalink
feat(douyinopen): 新增直播数据相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
fudiwei committed Mar 12, 2024
1 parent 5fe1a2b commit 9990f28
Show file tree
Hide file tree
Showing 16 changed files with 823 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Flurl;
using Flurl.Http;

namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen
{
public static class DouyinOpenClientExecuteJSExtensions
{
/// <summary>
/// <para>异步调用 [GET] /js/getticket 接口。</para>
/// <para>异步调用 [GET] /js/getticket/ 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/tools-ability/jsb-management/get-jsb-ticket ]]>
Expand All @@ -26,8 +25,8 @@ public static class DouyinOpenClientExecuteJSExtensions
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "js", "getticket")
.WithHeader("content-type", request.AccessToken);
.CreateFlurlRequest(request, HttpMethod.Get, "js", "getticket/")
.WithHeader("access-token", request.AccessToken);

return await client.SendFlurlRequestAsJsonAsync<Models.JSGetTicketResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Flurl.Http;

namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen
{
public static class DouyinOpenClientExecuteRoomExtensions
{
/// <summary>
/// <para>异步调用 [GET] /room/data/room_id/get/ 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/data-open-service/live-data/live-id ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.RoomDataRoomIdGetResponse> ExecuteRoomDataRoomIdGetAsync(this DouyinOpenClient client, Models.RoomDataRoomIdGetRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "room", "data", "room_id", "get/")
.WithHeader("access-token", request.AccessToken)
.SetQueryParam("open_id", request.OpenId)
.SetQueryParam("start_time", request.StartTimestamp)
.SetQueryParam("end_time", request.EndTimestamp);

return await client.SendFlurlRequestAsJsonAsync<Models.RoomDataRoomIdGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// <para>异步调用 [GET] /room/data/interactive/get/ 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/data-open-service/live-data/live-interactive-data ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.RoomDataInteractiveGetResponse> ExecuteRoomDataInteractiveGetAsync(this DouyinOpenClient client, Models.RoomDataInteractiveGetRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "room", "data", "interactive", "get/")
.WithHeader("access-token", request.AccessToken)
.SetQueryParam("open_id", request.OpenId)
.SetQueryParam("live_id", request.LiveId)
.SetQueryParam("room_id", request.RoomId);

return await client.SendFlurlRequestAsJsonAsync<Models.RoomDataInteractiveGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// <para>异步调用 [GET] /room/data/audience/get/ 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/data-open-service/live-data/live-audience-data ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.RoomDataAudienceGetResponse> ExecuteRoomDataAudienceGetAsync(this DouyinOpenClient client, Models.RoomDataAudienceGetRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "room", "data", "audience", "get/")
.WithHeader("access-token", request.AccessToken)
.SetQueryParam("open_id", request.OpenId)
.SetQueryParam("live_id", request.LiveId)
.SetQueryParam("room_id", request.RoomId);

return await client.SendFlurlRequestAsJsonAsync<Models.RoomDataAudienceGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// <para>异步调用 [GET] /room/data/base/get/ 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/data-open-service/live-data/live-base-data ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.RoomDataBaseGetResponse> ExecuteRoomDataBaseGetAsync(this DouyinOpenClient client, Models.RoomDataBaseGetRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "room", "data", "base", "get/")
.WithHeader("access-token", request.AccessToken)
.SetQueryParam("open_id", request.OpenId)
.SetQueryParam("live_id", request.LiveId)
.SetQueryParam("room_id", request.RoomId);

return await client.SendFlurlRequestAsJsonAsync<Models.RoomDataBaseGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen.Models
namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen.Models
{
/// <summary>
/// <para>表示 [GET] /js/getticket 接口的请求。</para>
/// <para>表示 [GET] /js/getticket/ 接口的请求。</para>
/// </summary>
public class JSGetTicketRequest : DouyinOpenRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen.Models
{
/// <summary>
/// <para>表示 [GET] /js/getticket 接口的响应。</para>
/// <para>表示 [GET] /js/getticket/ 接口的响应。</para>
/// </summary>
public class JSGetTicketResponse : DouyinOpenResponse<JSGetTicketResponse.Types.Data>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen.Models
{
/// <summary>
/// <para>表示 [GET] /room/data/audience/get/ 接口的请求。</para>
/// </summary>
public class RoomDataAudienceGetRequest : DouyinOpenRequest
{
/// <summary>
/// 获取或设置业务线。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public int? LiveId { get; set; }

/// <summary>
/// 获取或设置用户唯一标识。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string OpenId { get; set; } = string.Empty;

/// <summary>
/// 获取或设置直播间 ID。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string RoomId { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen.Models
{
/// <summary>
/// <para>表示 [GET] /room/data/audience/get/ 接口的响应。</para>
/// </summary>
public class RoomDataAudienceGetResponse : DouyinOpenResponse
{
public static class Types
{
public class Data
{
public static class Types
{
public class DataReadyStatusInfo : RoomDataInteractiveGetResponse.Types.Data.Types.DataReadyStatusInfo

Check notice

Code scanning / CodeQL

Class has same name as super class Note

Class has the same name as its base class.
{
}

public class Statistics : RoomDataInteractiveGetResponse.Types.Data.Types.Statistics

Check notice

Code scanning / CodeQL

Class has same name as super class Note

Class has the same name as its base class.
{
}
}

/// <summary>
/// 获取或设置数据就绪状态列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("data_ready_status")]
[System.Text.Json.Serialization.JsonPropertyName("data_ready_status")]
public Types.DataReadyStatusInfo[] DataReadyStatusList { get; set; } = default!;

/// <summary>
/// 获取或设置统计数据列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("stats")]
[System.Text.Json.Serialization.JsonPropertyName("stats")]
public Types.Statistics[] StatisticsList { get; set; } = default!;
}
}

[Newtonsoft.Json.JsonProperty("err_no")]
[System.Text.Json.Serialization.JsonPropertyName("err_no")]
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
public int ErrorNumber { get; set; }

[Newtonsoft.Json.JsonProperty("err_msg")]
[System.Text.Json.Serialization.JsonPropertyName("err_msg")]
public string? ErrorMessage { get; set; }

/// <summary>
/// 获取或设置请求唯一标识。
/// </summary>
[Newtonsoft.Json.JsonProperty("log_id")]
[System.Text.Json.Serialization.JsonPropertyName("log_id")]
public string? LogId { get; set; }

/// <summary>
/// 获取或设置返回数据。
/// </summary>
[Newtonsoft.Json.JsonProperty("data")]
[System.Text.Json.Serialization.JsonPropertyName("data")]
public Types.Data Data { get; set; } = default!;

public override bool IsSuccessful()
{
return GetRawStatus() == 200 && ErrorNumber == 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen.Models
{
/// <summary>
/// <para>表示 [GET] /room/data/base/get/ 接口的请求。</para>
/// </summary>
public class RoomDataBaseGetRequest : DouyinOpenRequest
{
/// <summary>
/// 获取或设置业务线。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public int? LiveId { get; set; }

/// <summary>
/// 获取或设置用户唯一标识。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string OpenId { get; set; } = string.Empty;

/// <summary>
/// 获取或设置直播间 ID。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string RoomId { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen.Models
{
/// <summary>
/// <para>表示 [GET] /room/data/base/get/ 接口的响应。</para>
/// </summary>
public class RoomDataBaseGetResponse : DouyinOpenResponse
{
public static class Types
{
public class Data
{
public static class Types
{
public class DataReadyStatusInfo : RoomDataInteractiveGetResponse.Types.Data.Types.DataReadyStatusInfo

Check notice

Code scanning / CodeQL

Class has same name as super class Note

Class has the same name as its base class.
{
}

public class Statistics : RoomDataInteractiveGetResponse.Types.Data.Types.Statistics

Check notice

Code scanning / CodeQL

Class has same name as super class Note

Class has the same name as its base class.
{
}
}

/// <summary>
/// 获取或设置数据就绪状态列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("data_ready_status")]
[System.Text.Json.Serialization.JsonPropertyName("data_ready_status")]
public Types.DataReadyStatusInfo[] DataReadyStatusList { get; set; } = default!;

/// <summary>
/// 获取或设置统计数据列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("stats")]
[System.Text.Json.Serialization.JsonPropertyName("stats")]
public Types.Statistics[] StatisticsList { get; set; } = default!;
}
}

[Newtonsoft.Json.JsonProperty("err_no")]
[System.Text.Json.Serialization.JsonPropertyName("err_no")]
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
public int ErrorNumber { get; set; }

[Newtonsoft.Json.JsonProperty("err_msg")]
[System.Text.Json.Serialization.JsonPropertyName("err_msg")]
public string? ErrorMessage { get; set; }

/// <summary>
/// 获取或设置请求唯一标识。
/// </summary>
[Newtonsoft.Json.JsonProperty("log_id")]
[System.Text.Json.Serialization.JsonPropertyName("log_id")]
public string? LogId { get; set; }

/// <summary>
/// 获取或设置返回数据。
/// </summary>
[Newtonsoft.Json.JsonProperty("data")]
[System.Text.Json.Serialization.JsonPropertyName("data")]
public Types.Data Data { get; set; } = default!;

public override bool IsSuccessful()
{
return GetRawStatus() == 200 && ErrorNumber == 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace SKIT.FlurlHttpClient.ByteDance.DouyinOpen.Models
{
/// <summary>
/// <para>表示 [GET] /room/data/interactive/get/ 接口的请求。</para>
/// </summary>
public class RoomDataInteractiveGetRequest : DouyinOpenRequest
{
/// <summary>
/// 获取或设置业务线。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public int? LiveId { get; set; }

/// <summary>
/// 获取或设置用户唯一标识。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string OpenId { get; set; } = string.Empty;

/// <summary>
/// 获取或设置直播间 ID。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string RoomId { get; set; } = string.Empty;
}
}
Loading

0 comments on commit 9990f28

Please sign in to comment.