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
45 changes: 45 additions & 0 deletions Apps.DeepL/Actions/GetUsageAction.cs
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action class is meant to contain actions for a specific entity and not only for one method. So the naming should be like "UsageActions"

{

public GetUsageActionActions(InvocationContext invocationContext) : base( invocationContext )
{

}

[Action("GetUsage", Description = "Get usage information")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action name should follow the same naming convention as a description. So it should be "Get usage"

public async Task<GetUsageResponse> GetUsage()
{
var result = await Client.GetUsageAsync();
var response = new GetUsageResponse();
if (result.Character != null)
Copy link
Contributor

@bZverok bZverok Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check each property for null and then add it to the response. You can just add all the values with nullchecks, it will be null anyway. Worth adding a constructor to GetUsageResponse

{
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;
}
}
34 changes: 34 additions & 0 deletions Apps.DeepL/Responses/GetUsageResponse.cs
Original file line number Diff line number Diff line change
@@ -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; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to our naming conventions only the first word must start with the capital letter. So it should be "Team documents translated current billing period". Same for other properties


[Display("Team Document limit per billing period?")]
public long? TeamDocumentLimit { get; set; }

[Display("Team Document limit reached?")]
public bool TeamDocumentLimitReached { get; set; }
}