From 4a6778c6097f07a67b6178e97843c5877d9daeec Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Mon, 25 May 2015 00:47:48 +0200 Subject: [PATCH] HDBits fixup. --- .../HDBitsFixture.cs} | 31 +++++++++--------- .../NzbDrone.Core.Test.csproj | 2 +- .../Indexers/HDBits/{HdBits.cs => HDBits.cs} | 13 ++++---- .../HDBits/{HdBitsApi.cs => HDBitsApi.cs} | 6 ++-- .../{HdBitsParser.cs => HDBitsParser.cs} | 32 +++++++++---------- ...Generator.cs => HDBitsRequestGenerator.cs} | 9 +++--- .../{HdBitsSettings.cs => HDBitsSettings.cs} | 12 +++---- src/NzbDrone.Core/NzbDrone.Core.csproj | 10 +++--- 8 files changed, 56 insertions(+), 59 deletions(-) rename src/NzbDrone.Core.Test/IndexerTests/{HdBitsTests/HdBitsFixture.cs => HDBitsTests/HDBitsFixture.cs} (80%) rename src/NzbDrone.Core/Indexers/HDBits/{HdBits.cs => HDBits.cs} (73%) rename src/NzbDrone.Core/Indexers/HDBits/{HdBitsApi.cs => HDBitsApi.cs} (98%) rename src/NzbDrone.Core/Indexers/HDBits/{HdBitsParser.cs => HDBitsParser.cs} (81%) rename src/NzbDrone.Core/Indexers/HDBits/{HdBitsRequestGenerator.cs => HDBitsRequestGenerator.cs} (96%) rename src/NzbDrone.Core/Indexers/HDBits/{HdBitsSettings.cs => HDBitsSettings.cs} (83%) diff --git a/src/NzbDrone.Core.Test/IndexerTests/HdBitsTests/HdBitsFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/HDBitsTests/HDBitsFixture.cs similarity index 80% rename from src/NzbDrone.Core.Test/IndexerTests/HdBitsTests/HdBitsFixture.cs rename to src/NzbDrone.Core.Test/IndexerTests/HDBitsTests/HDBitsFixture.cs index 73375d644..d25ecde3c 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/HdBitsTests/HdBitsFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/HDBitsTests/HDBitsFixture.cs @@ -1,20 +1,21 @@ -using Moq; +using System; +using System.Linq; +using System.Text; +using FluentAssertions; +using Moq; using NUnit.Framework; using NzbDrone.Common.Http; +using NzbDrone.Common.Serializer; using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.HDBits; -using NzbDrone.Core.Test.Framework; -using FluentAssertions; -using System.Linq; using NzbDrone.Core.Parser.Model; -using System; -using System.Text; +using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; -namespace NzbDrone.Core.Test.IndexerTests.HdBitsTests +namespace NzbDrone.Core.Test.IndexerTests.HDBitsTests { [TestFixture] - public class HdBitsFixture : CoreTest + public class HDBitsFixture : CoreTest { [SetUp] public void Setup() @@ -22,12 +23,12 @@ namespace NzbDrone.Core.Test.IndexerTests.HdBitsTests Subject.Definition = new IndexerDefinition() { Name = "HdBits", - Settings = new HdBitsSettings() { ApiKey = "fakekey" } + Settings = new HDBitsSettings() { ApiKey = "fakekey" } }; } [Test] - public void TestSimpleResponse() + public void should_parse_recent_feed_from_HDBits() { var responseJson = ReadAllText(@"Files/Indexers/HdBits/RecentFeed.json"); @@ -49,19 +50,17 @@ namespace NzbDrone.Core.Test.IndexerTests.HdBitsTests first.InfoUrl.Should().Be("https://hdbits.org/details.php?id=257142"); first.PublishDate.Should().Be(DateTime.Parse("2015-04-04T20:30:46+0000")); first.Size.Should().Be(1718009717); + first.InfoHash.Should().Be("EABC50AEF9F53CEDED84ADF14144D3368E586F3A"); first.MagnetUrl.Should().BeNullOrEmpty(); first.Peers.Should().Be(47); first.Seeders.Should().Be(46); } [Test] - public void TestBadPasskey() + public void should_warn_on_wrong_passkey() { - var responseJson = @" -{ - ""status"": 5, - ""message"": ""Invalid authentication credentials"" -}"; + var responseJson = new { status = 5, message = "Invalid authentication credentials" }.ToJson(); + Mocker.GetMock() .Setup(v => v.Execute(It.IsAny())) .Returns(r => new HttpResponse(r, new HttpHeader(), diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index de4f2a133..788f44fd0 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -204,7 +204,7 @@ - + diff --git a/src/NzbDrone.Core/Indexers/HDBits/HdBits.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBits.cs similarity index 73% rename from src/NzbDrone.Core/Indexers/HDBits/HdBits.cs rename to src/NzbDrone.Core/Indexers/HDBits/HDBits.cs index fa5af64a4..49458f969 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HdBits.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBits.cs @@ -1,19 +1,20 @@ -using NLog; +using System; +using NLog; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Parser; -using System; namespace NzbDrone.Core.Indexers.HDBits { - public class HdBits : HttpIndexerBase + public class HDBits : HttpIndexerBase { + public override string Name { get { return "HDBits"; } } public override DownloadProtocol Protocol { get { return DownloadProtocol.Torrent; } } public override bool SupportsRss { get { return true; } } public override bool SupportsSearch { get { return true; } } public override int PageSize { get { return 30; } } - public HdBits(IHttpClient httpClient, + public HDBits(IHttpClient httpClient, IConfigService configService, IParsingService parsingService, Logger logger) @@ -22,12 +23,12 @@ namespace NzbDrone.Core.Indexers.HDBits public override IIndexerRequestGenerator GetRequestGenerator() { - return new HdBitsRequestGenerator() { Settings = Settings }; + return new HDBitsRequestGenerator() { Settings = Settings }; } public override IParseIndexerResponse GetParser() { - return new HdBitsParser(Settings); + return new HDBitsParser(Settings); } } } diff --git a/src/NzbDrone.Core/Indexers/HDBits/HdBitsApi.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsApi.cs similarity index 98% rename from src/NzbDrone.Core/Indexers/HDBits/HdBitsApi.cs rename to src/NzbDrone.Core/Indexers/HDBits/HDBitsApi.cs index 307983908..d88bf39a7 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HdBitsApi.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsApi.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; -using System; +using System; +using Newtonsoft.Json; namespace NzbDrone.Core.Indexers.HDBits { @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Indexers.HDBits } } - public class HdBitsResponse + public class HDBitsResponse { [JsonProperty(Required = Required.Always)] public StatusCode Status { get; set; } diff --git a/src/NzbDrone.Core/Indexers/HDBits/HdBitsParser.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsParser.cs similarity index 81% rename from src/NzbDrone.Core/Indexers/HDBits/HdBitsParser.cs rename to src/NzbDrone.Core/Indexers/HDBits/HDBitsParser.cs index 6d9b05a0f..ee960ce9a 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HdBitsParser.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsParser.cs @@ -1,20 +1,20 @@ using System; using System.Collections.Generic; -using NzbDrone.Core.Parser.Model; +using System.Collections.Specialized; using System.Net; -using NzbDrone.Core.Indexers.Exceptions; +using System.Web; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.Web; -using System.Collections.Specialized; +using NzbDrone.Core.Indexers.Exceptions; +using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Indexers.HDBits { - public class HdBitsParser : IParseIndexerResponse + public class HDBitsParser : IParseIndexerResponse { - private readonly HdBitsSettings _settings; + private readonly HDBitsSettings _settings; - public HdBitsParser(HdBitsSettings settings) + public HDBitsParser(HDBitsSettings settings) { _settings = settings; } @@ -25,28 +25,25 @@ namespace NzbDrone.Core.Indexers.HDBits if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) { - throw new IndexerException( - indexerResponse, + throw new IndexerException(indexerResponse, "Unexpected response status {0} code from API request", indexerResponse.HttpResponse.StatusCode); } - var jsonResponse = JsonConvert.DeserializeObject(indexerResponse.Content); + var jsonResponse = JsonConvert.DeserializeObject(indexerResponse.Content); if (jsonResponse.Status != StatusCode.Success) { - throw new IndexerException( - indexerResponse, - @"HDBits API request returned status code {0} with message ""{1}""", + throw new IndexerException(indexerResponse, + "HDBits API request returned status code {0}: {1}", jsonResponse.Status, - jsonResponse.Message ?? ""); + jsonResponse.Message ?? string.Empty); } var responseData = jsonResponse.Data as JArray; if (responseData == null) { - throw new IndexerException( - indexerResponse, + throw new IndexerException(indexerResponse, "Indexer API call response missing result data"); } @@ -60,6 +57,7 @@ namespace NzbDrone.Core.Indexers.HDBits Guid = string.Format("HDBits-{0}", id), Title = result.Name, Size = result.Size, + InfoHash = result.Hash, DownloadUrl = GetDownloadUrl(id), InfoUrl = GetInfoUrl(id), Seeders = result.Seeders, @@ -88,7 +86,7 @@ namespace NzbDrone.Core.Indexers.HDBits return BuildUrl("/details.php", args); } - + private string BuildUrl(string path, NameValueCollection args) { var builder = new UriBuilder(_settings.BaseUrl); diff --git a/src/NzbDrone.Core/Indexers/HDBits/HdBitsRequestGenerator.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs similarity index 96% rename from src/NzbDrone.Core/Indexers/HDBits/HdBitsRequestGenerator.cs rename to src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs index 0ee22b146..7c59f2359 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HdBitsRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsRequestGenerator.cs @@ -1,16 +1,15 @@ using System; using System.Collections.Generic; -using NzbDrone.Core.IndexerSearch.Definitions; -using NzbDrone.Common.Extensions; +using System.Linq; using NzbDrone.Common.Http; using NzbDrone.Common.Serializer; -using System.Linq; +using NzbDrone.Core.IndexerSearch.Definitions; namespace NzbDrone.Core.Indexers.HDBits { - public class HdBitsRequestGenerator : IIndexerRequestGenerator + public class HDBitsRequestGenerator : IIndexerRequestGenerator { - public HdBitsSettings Settings { get; set; } + public HDBitsSettings Settings { get; set; } public IList> GetRecentRequests() { diff --git a/src/NzbDrone.Core/Indexers/HDBits/HdBitsSettings.cs b/src/NzbDrone.Core/Indexers/HDBits/HDBitsSettings.cs similarity index 83% rename from src/NzbDrone.Core/Indexers/HDBits/HdBitsSettings.cs rename to src/NzbDrone.Core/Indexers/HDBits/HDBitsSettings.cs index 779ee574d..de4cb61e5 100644 --- a/src/NzbDrone.Core/Indexers/HDBits/HdBitsSettings.cs +++ b/src/NzbDrone.Core/Indexers/HDBits/HDBitsSettings.cs @@ -1,25 +1,25 @@ using System; using FluentValidation; +using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; -using NzbDrone.Core.Annotations; namespace NzbDrone.Core.Indexers.HDBits { - public class HdBitsSettingsValidator : AbstractValidator + public class HDBitsSettingsValidator : AbstractValidator { - public HdBitsSettingsValidator() + public HDBitsSettingsValidator() { RuleFor(c => c.BaseUrl).ValidRootUrl(); RuleFor(c => c.ApiKey).NotEmpty(); } } - public class HdBitsSettings : IProviderConfig + public class HDBitsSettings : IProviderConfig { - private static readonly HdBitsSettingsValidator Validator = new HdBitsSettingsValidator(); + private static readonly HDBitsSettingsValidator Validator = new HDBitsSettingsValidator(); - public HdBitsSettings() + public HDBitsSettings() { BaseUrl = "https://hdbits.org"; } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 06f1432e1..c953ec0b0 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -479,11 +479,11 @@ - - - - - + + + + +