35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using SWAD.API.Consts.Enums;
|
|
using SWAD.API.Controllers.DTOs;
|
|
using SWAD.API.Models.Config.ApiServices.Structure;
|
|
|
|
namespace SWAD.API.Services.MusicAPI.Api;
|
|
|
|
/// <summary>
|
|
/// Abstract ApiService of music services
|
|
/// </summary>
|
|
public abstract class ApiService
|
|
{
|
|
public ApiServiceData Config { get; protected init; } = null!;
|
|
public MusicService ServiceType { get; protected init; }
|
|
public abstract Task<string?> GetLinkByQuery(TrackDto query);
|
|
public abstract Task<TrackDto> GetQueryObject(string link, string CountryCode = "US");
|
|
protected string GetQuery(TrackDto dto) => $"{dto.Name} - {dto.Artist}";
|
|
|
|
/// <summary>
|
|
/// Get all implemented API Services
|
|
/// </summary>
|
|
/// <returns>API Services types</returns>
|
|
public static IEnumerable<Type> GetAllImplementations()
|
|
{
|
|
var type = typeof(ApiService);
|
|
var types = AppDomain.CurrentDomain.GetAssemblies()
|
|
.SelectMany(s => s.GetTypes())
|
|
.Where(p => type.IsAssignableFrom(p) && !p.IsInterface && !p.IsAbstract);
|
|
return types;
|
|
}
|
|
|
|
protected struct Messages
|
|
{
|
|
public const string AuthFailMessage = "Update token request for service {0} failed";
|
|
}
|
|
} |