-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from bb-io/develop
Develop
- Loading branch information
Showing
7 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Apps.Crowdin.Api.RestSharp; | ||
using Apps.Crowdin.Models.Entities; | ||
using Apps.Crowdin.Models.Request; | ||
using Apps.Crowdin.Models.Request.Project; | ||
using Apps.Crowdin.Models.Response; | ||
using Apps.Crowdin.Utils; | ||
using Blackbird.Applications.Sdk.Common; | ||
using Blackbird.Applications.Sdk.Common.Authentication; | ||
using Blackbird.Applications.Sdk.Common.Dynamic; | ||
using Blackbird.Applications.Sdk.Common.Invocation; | ||
using Crowdin.Api; | ||
using Newtonsoft.Json; | ||
using RestSharp; | ||
|
||
namespace Apps.Crowdin.DataSourceHandlers; | ||
|
||
public class AiPromptIdDataHandler( | ||
InvocationContext invocationContext, | ||
[ActionParameter] ProjectRequest project, | ||
[ActionParameter] UserRequest user) | ||
|
||
: BaseInvocable(invocationContext), IAsyncDataSourceHandler | ||
{ | ||
private AuthenticationCredentialsProvider[] Creds => | ||
InvocationContext.AuthenticationCredentialsProviders.ToArray(); | ||
|
||
public async Task<Dictionary<string, string>> GetDataAsync(DataSourceContext context, | ||
CancellationToken cancellationToken) | ||
{ | ||
if (string.IsNullOrEmpty(project.ProjectId) || string.IsNullOrEmpty(user.UserId)) | ||
throw new("You should input Project ID and User ID first"); | ||
|
||
var client = new CrowdinRestClient(); | ||
|
||
var items = await Paginator.Paginate(async (lim, offset) | ||
=> | ||
{ | ||
var request = | ||
new CrowdinRestRequest( | ||
$"/users/{user.UserId}/ai/prompts?limit={lim}&offset={offset}", | ||
Method.Get, Creds); | ||
request.AddQueryParameter("projectId", project.ProjectId); | ||
request.AddQueryParameter("action", "pre_translate"); | ||
var response = await client.ExecuteAsync(request, cancellationToken: cancellationToken); | ||
return JsonConvert.DeserializeObject<ResponseList<DataResponse<AiPromptEntity>>>(response.Content); | ||
}); | ||
|
||
return items | ||
.Select(x => x.Data) | ||
.Where(x => context.SearchString == null || | ||
x.Name.Contains(context.SearchString, StringComparison.OrdinalIgnoreCase)) | ||
.Take(20) | ||
.ToDictionary(x => x.Id.ToString(), x => x.Name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Apps.Crowdin.Models.Entities | ||
{ | ||
public class AiPromptEntity | ||
{ | ||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Blackbird.Applications.Sdk.Common; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Apps.Crowdin.Models.Request | ||
{ | ||
public class UserRequest | ||
{ | ||
[Display("User ID")] | ||
public string? UserId { get; set; } | ||
} | ||
} |