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

[FEATURE] TikTok Shop API Upgrade to v202309 #31

Merged
merged 15 commits into from
May 15, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class SKU
public int? Length { get; set; }

/// <summary>
/// 获取或设置宽度单位
/// 获取或设置宽度
/// </summary>
[Newtonsoft.Json.JsonProperty("width")]
[System.Text.Json.Serialization.JsonPropertyName("width")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class FailedPackage
/// </summary>
[Newtonsoft.Json.JsonProperty("success_package_list")]
[System.Text.Json.Serialization.JsonPropertyName("success_package_list")]
public string[] SucceededPackageList { get; set; } = default!;
public string[] SucceededPackageIdList { get; set; } = default!;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public abstract class TikTokShopLegacyResponse : CommonResponseBase, ICommonResp
[Newtonsoft.Json.JsonProperty("code")]
[System.Text.Json.Serialization.JsonPropertyName("code")]
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
public virtual int ErrorCode { get; set; }
public virtual int Code { get; set; }

/// <summary>
/// 获取 TikTok Shop API 返回的错误信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("message")]
[System.Text.Json.Serialization.JsonPropertyName("message")]
public virtual string? ErrorMessage { get; set; }
public virtual string? Message { get; set; }

/// <summary>
/// 获取 TikTok Shop API 返回的请求唯一标识。
Expand All @@ -33,13 +33,13 @@ public abstract class TikTokShopLegacyResponse : CommonResponseBase, ICommonResp
/// <summary>
/// 获取一个值,该值指示调用 TikTok API 是否成功。
/// <para>
/// (即 HTTP 状态码为 200,且 <see cref="ErrorCode"/> 值为 0)
/// (即 HTTP 状态码为 200,且 <see cref="Code"/> 值为 0)
/// </para>
/// </summary>
/// <returns></returns>
public override bool IsSuccessful()
{
return GetRawStatus() == 200 && ErrorCode == 0;
return GetRawStatus() == 200 && Code == 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@

namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop
{
public static class TikTokShopClientExecuteShopExtensions
public static class TikTokShopClientExecuteAuthorizationExtensions
{
/// <summary>
/// <para>异步调用 [GET] /shop/get_authorized_shop 接口。</para>
/// <para>异步调用 [GET] /authorization/{version}/shops 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/doc/page/262739 ]]>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/6507ead7b99d5302be949ba9 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.ShopGetAuthorizedShopListResponse> ExecuteShopGetAuthorizedShopListAsync(this TikTokShopClient client, Models.ShopGetAuthorizedShopListRequest request, CancellationToken cancellationToken = default)
public static async Task<Models.AuthorizationGetShopsResponse> ExecuteAuthorizationGetShopsAsync(this TikTokShopClient client, Models.AuthorizationGetShopsRequest 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, "shop", "get_authorized_shop");
.CreateFlurlRequest(request, HttpMethod.Get, "authorization", request.ApiVersion, "shops");

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

namespace SKIT.FlurlHttpClient.ByteDance.TikTokGlobalShop
{
public static class TikTokShopClientExecuteEventExtensions
{
/// <summary>
/// <para>异步调用 [GET] /event/{version}/webhooks 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/6509a3a1c16ffe02b8d64149 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.EventGetWebhooksResponse> ExecuteEventGetWebhooksAsync(this TikTokShopClient client, Models.EventGetWebhooksRequest 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, "event", request.ApiVersion, "webhooks");

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

/// <summary>
/// <para>异步调用 [PUT] /event/{version}/webhooks 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/650aa064defece02be6df919 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.EventUpdateWebhookResponse> ExecuteEventUpdateWebhookAsync(this TikTokShopClient client, Models.EventUpdateWebhookRequest 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.Put, "event", request.ApiVersion, "webhooks");

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

/// <summary>
/// <para>异步调用 [DELETE] /event/{version}/webhooks 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://partner.tiktokshop.com/docv2/page/650aa1eadefece02be6e224a ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.EventDeleteWebhookResponse> ExecuteEventDeleteWebhookAsync(this TikTokShopClient client, Models.EventDeleteWebhookRequest 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.Delete, "event", request.ApiVersion, "webhooks");

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

This file was deleted.

Loading
Loading