mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
get list IDs and ViewUrls from API
This commit is contained in:
parent
3bf304aae4
commit
09e8a58d15
4 changed files with 45 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using RestSharp;
|
||||
|
|
@ -13,16 +14,14 @@ public class Command : IRequest
|
|||
|
||||
public class Handler : AsyncRequestHandler<Command>
|
||||
{
|
||||
private readonly IRestClient _restClient;
|
||||
private readonly IFilterListsApiClient apiClient;
|
||||
|
||||
public Handler(IRestClient restClient)
|
||||
{
|
||||
_restClient = restClient;
|
||||
}
|
||||
public Handler(IFilterListsApiClient apiClient) => this.apiClient = apiClient;
|
||||
|
||||
protected override Task Handle(Command request, CancellationToken cancellationToken)
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
var listsRequest = new RestRequest("lists");
|
||||
var restResponse = await apiClient.ExecuteAsync<IEnumerable<FilterListDto>>(listsRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
8
src/FilterLists.Agent/FilterListDto.cs
Normal file
8
src/FilterLists.Agent/FilterListDto.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
namespace FilterLists.Agent
|
||||
{
|
||||
public class FilterListDto
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ViewUrl { get; private set; }
|
||||
}
|
||||
}
|
||||
28
src/FilterLists.Agent/FilterListsApiClient.cs
Normal file
28
src/FilterLists.Agent/FilterListsApiClient.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using RestSharp;
|
||||
|
||||
namespace FilterLists.Agent
|
||||
{
|
||||
public interface IFilterListsApiClient
|
||||
{
|
||||
Task<TResponse> ExecuteAsync<TResponse>(RestRequest request);
|
||||
}
|
||||
|
||||
public class FilterListsApiClient : IFilterListsApiClient
|
||||
{
|
||||
private const string FilterListsApiBaseUrl = "https://filterlists.com/api/v1";
|
||||
private const string ExceptionMessage = "Error retrieving response from FilterLists API.";
|
||||
private readonly IRestClient restClient;
|
||||
|
||||
public FilterListsApiClient() => restClient = new RestClient(FilterListsApiBaseUrl);
|
||||
|
||||
public async Task<TResponse> ExecuteAsync<TResponse>(RestRequest request)
|
||||
{
|
||||
var response = await restClient.ExecuteTaskAsync<TResponse>(request);
|
||||
if (response.ErrorException == null)
|
||||
return response.Data;
|
||||
throw new ApplicationException(ExceptionMessage, response.ErrorException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
using Autofac.Extensions.DependencyInjection;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using RestSharp;
|
||||
|
||||
//TODO: get raw list urls and IDs
|
||||
//TODO: foreach list, download and persist raw list to disk with standardized name and overwriting the previous version
|
||||
|
|
@ -16,7 +15,6 @@ namespace FilterLists.Agent
|
|||
{
|
||||
public static class Program
|
||||
{
|
||||
private const string FilterListsApiBaseUrl = "https://filterlists.com/api/v1";
|
||||
private static IServiceProvider _serviceProvider;
|
||||
|
||||
public static async Task Main()
|
||||
|
|
@ -35,8 +33,9 @@ private static void RegisterServices()
|
|||
var serviceCollection = new ServiceCollection();
|
||||
var containerBuilder = new ContainerBuilder();
|
||||
|
||||
// register Agent services
|
||||
serviceCollection.AddMediatR(typeof(Program).Assembly);
|
||||
containerBuilder.Register<IRestClient>(c => new RestClient(FilterListsApiBaseUrl)).SingleInstance();
|
||||
containerBuilder.RegisterType<FilterListsApiClient>().AsImplementedInterfaces().SingleInstance();
|
||||
|
||||
containerBuilder.Populate(serviceCollection);
|
||||
var container = containerBuilder.Build();
|
||||
|
|
|
|||
Loading…
Reference in a new issue