Билд
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Knot.Modules.Klipy.Application.Abstractions;
|
||||
|
||||
public interface IKlipyClient
|
||||
{
|
||||
Task<bool> TestConnectionAsync(string apiKey, string appName, CancellationToken ct = default);
|
||||
Task<List<string>> SearchVideosAsync(string apiKey, string appName, string query, int limit, CancellationToken ct = default);
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
namespace Knot.Modules.Klipy;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Knot.Modules.Klipy.Application.Abstractions;
|
||||
using Knot.Modules.Klipy.Infrastructure.External;
|
||||
|
||||
namespace Knot.Modules.Klipy;
|
||||
|
||||
public static class DependencyInjection {
|
||||
public static IServiceCollection AddKlipyModule(this IServiceCollection services) {
|
||||
services.AddHttpClient<IKlipyClient, KlipyClient>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Knot.Modules.Klipy.Application.Abstractions;
|
||||
|
||||
namespace Knot.Modules.Klipy.Infrastructure.External;
|
||||
|
||||
public sealed class KlipyClient : IKlipyClient
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public KlipyClient(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async Task<bool> TestConnectionAsync(string apiKey, string appName, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
// According to docs: https://api.klipy.com/api/v1/{app_key}/gifs/trending
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, $"https://api.klipy.com/api/v1/{appName}/gifs/trending?page=1&per_page=1&customer_id=knot_admin_test");
|
||||
request.Headers.Add("X-KLIPY-API-KEY", apiKey);
|
||||
|
||||
using var response = await _httpClient.SendAsync(request, ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<string>> SearchVideosAsync(string apiKey, string appName, string query, int limit, CancellationToken ct = default)
|
||||
{
|
||||
// To be implemented as needed
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,9 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Shared\Knot.Shared.Kernel\Knot.Shared.Kernel.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Knot.Shared.Infrastructure\Knot.Shared.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Conversations\Knot.Modules.Conversations.csproj" />
|
||||
<ProjectReference Include="..\Auth\Knot.Modules.Auth.csproj" />
|
||||
<ProjectReference Include="..\Stories\Knot.Modules.Stories.csproj" />
|
||||
<ProjectReference Include="..\Settings\Knot.Modules.Settings.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Carter" Version="10.0.0" />
|
||||
<ProjectReference Include="..\Settings\Knot.Modules.Settings.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user