mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-22 22:15:17 -04:00
New: v4 API (DROP v3 AFTER TESTING PERIOD)
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Reflection;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using Radarr.Http.ClientSchema;
|
||||
using Radarr.Http.REST;
|
||||
|
||||
namespace Radarr.Api.V4
|
||||
{
|
||||
public class ProviderResource<T> : RestResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<Field> Fields { get; set; }
|
||||
public string ImplementationName { get; set; }
|
||||
public string Implementation { get; set; }
|
||||
public string ConfigContract { get; set; }
|
||||
public string InfoLink { get; set; }
|
||||
public ProviderMessage Message { get; set; }
|
||||
public HashSet<int> Tags { get; set; }
|
||||
|
||||
public List<T> Presets { get; set; }
|
||||
}
|
||||
|
||||
public class ProviderResourceMapper<TProviderResource, TProviderDefinition>
|
||||
where TProviderResource : ProviderResource<TProviderResource>, new()
|
||||
where TProviderDefinition : ProviderDefinition, new()
|
||||
{
|
||||
public virtual TProviderResource ToResource(TProviderDefinition definition)
|
||||
{
|
||||
return new TProviderResource
|
||||
{
|
||||
Id = definition.Id,
|
||||
|
||||
Name = definition.Name,
|
||||
ImplementationName = definition.ImplementationName,
|
||||
Implementation = definition.Implementation,
|
||||
ConfigContract = definition.ConfigContract,
|
||||
Message = definition.Message,
|
||||
Tags = definition.Tags,
|
||||
Fields = SchemaBuilder.ToSchema(definition.Settings),
|
||||
|
||||
// radarr/supported is an disambagation page. the # should be a header on the page with appropiate details/link
|
||||
InfoLink = string.Format("https://wiki.servarr.com/radarr/supported#{0}",
|
||||
definition.Implementation.ToLower())
|
||||
};
|
||||
}
|
||||
|
||||
public virtual TProviderDefinition ToModel(TProviderResource resource)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
return default(TProviderDefinition);
|
||||
}
|
||||
|
||||
var definition = new TProviderDefinition
|
||||
{
|
||||
Id = resource.Id,
|
||||
|
||||
Name = resource.Name,
|
||||
ImplementationName = resource.ImplementationName,
|
||||
Implementation = resource.Implementation,
|
||||
ConfigContract = resource.ConfigContract,
|
||||
Message = resource.Message,
|
||||
Tags = resource.Tags
|
||||
};
|
||||
|
||||
var configContract = ReflectionExtensions.CoreAssembly.FindTypeByName(definition.ConfigContract);
|
||||
definition.Settings = (IProviderConfig)SchemaBuilder.ReadFromSchema(resource.Fields, configContract);
|
||||
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user