Update API

This commit is contained in:
Chris Chen
2022-09-30 09:40:42 -07:00
parent 184db15773
commit b33c0d8286
55 changed files with 3877 additions and 360 deletions
+27
View File
@@ -0,0 +1,27 @@
using System;
using System.Threading.Tasks;
namespace LineMessaging
{
public partial class LineMessagingClient
{
private const string GroupProfileApiPath = "v2/bot/group/{0}/summary";
private const string QuotaApiPath = "/v2/bot/message/quota/consumption";
public async Task<int> GetTotalUsage()
{
return Get<LineUsage>(QuotaApiPath).Result.TotalUsage;
}
public async Task<LineGroupProfile> GetGroupProfile(string groupId)
{
if (string.IsNullOrEmpty(groupId))
{
throw new ArgumentException($"{nameof(groupId)} is null or empty.");
}
return await Get<LineGroupProfile>(string.Format(GroupProfileApiPath, groupId));
}
}
}
+16
View File
@@ -0,0 +1,16 @@
using Newtonsoft.Json;
namespace LineMessaging
{
public class LineUsage
{
[JsonProperty("totalUsage")]
public int TotalUsage { get; set; }
}
public class LineGroupProfile
{
[JsonProperty("groupName")]
public string GroupName { get; set; }
}
}
+14 -3
View File
@@ -11,6 +11,7 @@ namespace LineMessaging
public partial class LineMessagingClient
{
private const string ACCESS_TOKEN = "WFAyMvMEZ86cfMJIAzE+yklUZGpeS/jFYTeL9a9O35QR83oNMmwaUJfyEe48Kegadz0BArDdBoySxs479U1pwTHtlyH+Sm4jqlz8BwukX/Hsa4D1fX03Qn4zFu7TwPFKWFXnZbWq89Yg0iNzjpfTNwdB04t89/1O/w1cDnyilFU=";
private const string ACCESS_TOKEN_SEC = "UTRu3QsV9BjVmusqgWa30j/Vs7JJb59NvIWprv9Yb4ORUOTIIco66groSy7n8TlQbxn/OsA6FsFSQZDwaRPPlyfBYoW+lvv8g7IZhA8otuK57f+ojZbLO0RvkyEyQoy09Kmd7dnr78kHlDOcBq5ATgdB04t89/1O/w1cDnyilFU=";
private static readonly MediaTypeHeaderValue MediaTypeJson = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
private static readonly MediaTypeHeaderValue MediaTypeJpeg = MediaTypeHeaderValue.Parse("image/jpeg");
private static readonly MediaTypeHeaderValue MediaTypePng = MediaTypeHeaderValue.Parse("image/png");
@@ -25,11 +26,21 @@ namespace LineMessaging
Timeout = TimeSpan.FromSeconds(10)
};
private readonly AuthenticationHeaderValue accessTokenHeaderValue;
private AuthenticationHeaderValue accessTokenHeaderValue;
private JsonSerializerSettings serializerSettings;
public LineMessagingClient()
{
string accessToken = ACCESS_TOKEN;
string accessToken = ACCESS_TOKEN_SEC;//ACCESS_TOKEN;
Initialize(accessToken);
}
public LineMessagingClient(string accessToken)
{
Initialize(accessToken);
}
private void Initialize(string accessToken)
{
if (string.IsNullOrEmpty(accessToken))
{
throw new ArgumentException($"{nameof(accessToken)} is null or empty.");
@@ -38,7 +49,7 @@ namespace LineMessaging
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
Formatting=Formatting.Indented
Formatting = Formatting.Indented
};
accessTokenHeaderValue = new AuthenticationHeaderValue("Bearer", accessToken);
}