HDBits fixup.

pull/4/head
Taloth Saldono 10 years ago
parent 3ae2883eb5
commit 4a6778c609

@ -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<HdBits>
public class HDBitsFixture : CoreTest<HDBits>
{
[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<IHttpClient>()
.Setup(v => v.Execute(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(),

@ -204,7 +204,7 @@
<Compile Include="IndexerTests\BitMeTvTests\BitMeTvFixture.cs" />
<Compile Include="IndexerTests\BroadcastheNetTests\BroadcastheNetFixture.cs" />
<Compile Include="IndexerTests\EztvTests\EztvFixture.cs" />
<Compile Include="IndexerTests\HdBitsTests\HdBitsFixture.cs" />
<Compile Include="IndexerTests\HDBitsTests\HDBitsFixture.cs" />
<Compile Include="IndexerTests\IndexerServiceFixture.cs" />
<Compile Include="IndexerTests\IntegrationTests\IndexerIntegrationTests.cs" />
<Compile Include="IndexerTests\TorznabTests\TorznabFixture.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<HdBitsSettings>
public class HDBits : HttpIndexerBase<HDBitsSettings>
{
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);
}
}
}

@ -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; }

@ -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<HdBitsResponse>(indexerResponse.Content);
var jsonResponse = JsonConvert.DeserializeObject<HDBitsResponse>(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);

@ -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<IEnumerable<IndexerRequest>> GetRecentRequests()
{

@ -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<HdBitsSettings>
public class HDBitsSettingsValidator : AbstractValidator<HDBitsSettings>
{
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";
}

@ -479,11 +479,11 @@
<Compile Include="Indexers\Fanzub\FanzubRequestGenerator.cs" />
<Compile Include="Indexers\Fanzub\FanzubSettings.cs" />
<Compile Include="Indexers\FetchAndParseRssService.cs" />
<Compile Include="Indexers\HDBits\HdBits.cs" />
<Compile Include="Indexers\HDBits\HdBitsApi.cs" />
<Compile Include="Indexers\HDBits\HdBitsParser.cs" />
<Compile Include="Indexers\HDBits\HdBitsRequestGenerator.cs" />
<Compile Include="Indexers\HDBits\HdBitsSettings.cs" />
<Compile Include="Indexers\HDBits\HDBits.cs" />
<Compile Include="Indexers\HDBits\HDBitsApi.cs" />
<Compile Include="Indexers\HDBits\HDBitsParser.cs" />
<Compile Include="Indexers\HDBits\HDBitsRequestGenerator.cs" />
<Compile Include="Indexers\HDBits\HDBitsSettings.cs" />
<Compile Include="Indexers\IIndexer.cs" />
<Compile Include="Indexers\IIndexerRequestGenerator.cs" />
<Compile Include="Indexers\IndexerBase.cs" />

Loading…
Cancel
Save