Get json response when adding item to the queue
This commit is contained in:
parent
a2e7f9ecbb
commit
1b9480275f
|
@ -43,15 +43,15 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
|
||||||
private void WithFailResponse()
|
private void WithFailResponse()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<HttpProvider>()
|
Mocker.GetMock<HttpProvider>()
|
||||||
.Setup(s => s.DownloadString(It.IsAny<String>())).Returns("failed");
|
.Setup(s => s.DownloadString(It.IsAny<String>())).Returns("{ \"status\": false, \"error\": \"API Key Required\" }");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void add_url_should_format_request_properly()
|
public void add_url_should_format_request_properly()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
|
Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
|
||||||
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=0&pp=3&cat=tv&nzbname=My+Series+Name+-+5x2-5x3+-+My+title+%5bBluray720p%5d+%5bProper%5d&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
|
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=0&pp=3&cat=tv&nzbname=My+Series+Name+-+5x2-5x3+-+My+title+%5bBluray720p%5d+%5bProper%5d&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
|
||||||
.Returns("ok");
|
.Returns("{ \"status\": true }");
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
Mocker.Resolve<SabProvider>().DownloadNzb(url, title).Should().BeTrue();
|
Mocker.Resolve<SabProvider>().DownloadNzb(url, title).Should().BeTrue();
|
||||||
|
@ -61,8 +61,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
|
||||||
public void newzbin_add_url_should_format_request_properly()
|
public void newzbin_add_url_should_format_request_properly()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
|
Mocker.GetMock<HttpProvider>(MockBehavior.Strict)
|
||||||
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=addid&name=6107863&priority=0&pp=3&cat=tv&nzbname=My+Series+Name+-+5x2-5x3+-+My+title+%5bBluray720p%5d+%5bProper%5d&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
|
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=addid&name=6107863&priority=0&pp=3&cat=tv&nzbname=My+Series+Name+-+5x2-5x3+-+My+title+%5bBluray720p%5d+%5bProper%5d&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
|
||||||
.Returns("ok");
|
.Returns("{ \"status\": true }");
|
||||||
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
@ -78,8 +78,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
|
||||||
WithFailResponse();
|
WithFailResponse();
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
Mocker.Resolve<SabProvider>().DownloadNzb(url, title).Should().BeFalse();
|
Assert.Throws<ApplicationException>(() => Mocker.Resolve<SabProvider>().DownloadNzb(url, title).Should().BeFalse());
|
||||||
ExceptionVerification.ExpectedWarns(1);
|
//ExceptionVerification.ExpectedErrors(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Model.Sabnzbd
|
||||||
|
{
|
||||||
|
public class SabAddResponse
|
||||||
|
{
|
||||||
|
public bool Status { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "nzo_ids")]
|
||||||
|
public List<String> Ids { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -277,6 +277,7 @@
|
||||||
<Compile Include="Model\LanguageType.cs" />
|
<Compile Include="Model\LanguageType.cs" />
|
||||||
<Compile Include="Model\MisnamedEpisodeModel.cs" />
|
<Compile Include="Model\MisnamedEpisodeModel.cs" />
|
||||||
<Compile Include="Model\QualityModel.cs" />
|
<Compile Include="Model\QualityModel.cs" />
|
||||||
|
<Compile Include="Model\Sabnzbd\SabAddResponse.cs" />
|
||||||
<Compile Include="Model\Sabnzbd\SabHistoryItem.cs" />
|
<Compile Include="Model\Sabnzbd\SabHistoryItem.cs" />
|
||||||
<Compile Include="Model\Sabnzbd\SabHistory.cs" />
|
<Compile Include="Model\Sabnzbd\SabHistory.cs" />
|
||||||
<Compile Include="Model\Sabnzbd\SabJsonError.cs" />
|
<Compile Include="Model\Sabnzbd\SabJsonError.cs" />
|
||||||
|
|
|
@ -87,7 +87,7 @@ namespace NzbDrone.Core.Providers.DownloadClients
|
||||||
string name = GetNzbName(url);
|
string name = GetNzbName(url);
|
||||||
string nzbName = HttpUtility.UrlEncode(title);
|
string nzbName = HttpUtility.UrlEncode(title);
|
||||||
|
|
||||||
string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}",
|
string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}&output=json",
|
||||||
name, priority, cat, nzbName);
|
name, priority, cat, nzbName);
|
||||||
|
|
||||||
if (url.ToLower().Contains("newzbin"))
|
if (url.ToLower().Contains("newzbin"))
|
||||||
|
@ -98,19 +98,17 @@ namespace NzbDrone.Core.Providers.DownloadClients
|
||||||
string request = GetSabRequest(action);
|
string request = GetSabRequest(action);
|
||||||
logger.Info("Adding report [{0}] to the queue.", title);
|
logger.Info("Adding report [{0}] to the queue.", title);
|
||||||
|
|
||||||
var response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
|
var response = _httpProvider.DownloadString(request);
|
||||||
|
|
||||||
logger.Debug("Queue Response: [{0}]", response);
|
logger.Debug("Queue Response: [{0}]", response);
|
||||||
|
|
||||||
if (response == "ok")
|
CheckForError(response);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
logger.Warn("SAB returned unexpected response '{0}'", response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (WebException ex)
|
catch (WebException ex)
|
||||||
{
|
{
|
||||||
logger.Error("Error communicating with SAB");
|
logger.Error("Error communicating with SAB: " + ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue