-
Notifications
You must be signed in to change notification settings - Fork 1
Add GetUsageAction #20
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| { | ||
|
|
||
| public GetUsageActionActions(InvocationContext invocationContext) : base( invocationContext ) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| [Action("GetUsage", Description = "Get usage information")] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| 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; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; } | ||
| } | ||
There was a problem hiding this comment.
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"