diff --git a/Apps.DeepL/Actions/GetUsageAction.cs b/Apps.DeepL/Actions/GetUsageAction.cs new file mode 100644 index 0000000..4a53970 --- /dev/null +++ b/Apps.DeepL/Actions/GetUsageAction.cs @@ -0,0 +1,45 @@ +using Apps.DeepL.Requests; +using Apps.DeepL.Responses; +using Blackbird.Applications.Sdk.Common; +using Blackbird.Applications.Sdk.Common.Actions; +using Blackbird.Applications.Sdk.Common.Invocation; +using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces; +using DeepL; + +namespace Apps.DeepL.Actions; + +[ActionList] +public class GetUsageActionActions : DeepLInvocable +{ + + public GetUsageActionActions(InvocationContext invocationContext) : base( invocationContext ) + { + + } + + [Action("GetUsage", Description = "Get usage information")] + public async Task GetUsage() + { + var result = await Client.GetUsageAsync(); + var response = new GetUsageResponse(); + if (result.Character != null) + { + response.CharacterCount = result.Character.Count; + response.CharacterLimit = result.Character.Limit; + response.CharacterLimitReached = result.Character.LimitReached; + } + if (result.Document != null) + { + response.DocumentCount = result.Document.Count; + response.DocumentLimit = result.Document.Limit; + response.DocumentLimitReached = result.Document.LimitReached; + } + if (result.TeamDocument != null) + { + response.TeamDocumentCount = result.TeamDocument.Count; + response.TeamDocumentLimit = result.TeamDocument.Limit; + response.TeamDocumentLimitReached = result.TeamDocument.LimitReached; + } + return response; + } +} \ No newline at end of file diff --git a/Apps.DeepL/Responses/GetUsageResponse.cs b/Apps.DeepL/Responses/GetUsageResponse.cs new file mode 100644 index 0000000..1d76fd8 --- /dev/null +++ b/Apps.DeepL/Responses/GetUsageResponse.cs @@ -0,0 +1,34 @@ +using Blackbird.Applications.Sdk.Common; + +namespace Apps.DeepL.Responses; + +public class GetUsageResponse +{ + + [Display("Characters used in current billing period")] + public long? CharacterCount { get; set; } + + [Display("Character limit per billing period")] + public long? CharacterLimit { get; set; } + + [Display("Character limit reached?")] + public bool CharacterLimitReached { get; set; } + + [Display("Documents translated current billing period")] + public long? DocumentCount { get; set; } + + [Display("Document limit per billing period")] + public long? DocumentLimit { get; set; } + + [Display("Document limit reached?")] + public bool DocumentLimitReached { get; set; } + + [Display("Team Documents translated current billing period")] + public long? TeamDocumentCount { get; set; } + + [Display("Team Document limit per billing period?")] + public long? TeamDocumentLimit { get; set; } + + [Display("Team Document limit reached?")] + public bool TeamDocumentLimitReached { get; set; } +} \ No newline at end of file