mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-26 01:27:00 +00:00
Get json response when adding item to the queue
This commit is contained in:
parent
a2e7f9ecbb
commit
1b9480275f
4 changed files with 29 additions and 14 deletions
|
@ -43,15 +43,15 @@ public void Setup()
|
|||
private void WithFailResponse()
|
||||
{
|
||||
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]
|
||||
public void add_url_should_format_request_properly()
|
||||
{
|
||||
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"))
|
||||
.Returns("ok");
|
||||
.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("{ \"status\": true }");
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<SabProvider>().DownloadNzb(url, title).Should().BeTrue();
|
||||
|
@ -61,8 +61,8 @@ public void add_url_should_format_request_properly()
|
|||
public void newzbin_add_url_should_format_request_properly()
|
||||
{
|
||||
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"))
|
||||
.Returns("ok");
|
||||
.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("{ \"status\": true }");
|
||||
|
||||
|
||||
//Act
|
||||
|
@ -78,8 +78,8 @@ public void add_by_url_should_detect_and_handle_sab_errors()
|
|||
WithFailResponse();
|
||||
|
||||
//Act
|
||||
Mocker.Resolve<SabProvider>().DownloadNzb(url, title).Should().BeFalse();
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
Assert.Throws<ApplicationException>(() => Mocker.Resolve<SabProvider>().DownloadNzb(url, title).Should().BeFalse());
|
||||
//ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
16
NzbDrone.Core/Model/Sabnzbd/SabAddResponse.cs
Normal file
16
NzbDrone.Core/Model/Sabnzbd/SabAddResponse.cs
Normal file
|
@ -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\MisnamedEpisodeModel.cs" />
|
||||
<Compile Include="Model\QualityModel.cs" />
|
||||
<Compile Include="Model\Sabnzbd\SabAddResponse.cs" />
|
||||
<Compile Include="Model\Sabnzbd\SabHistoryItem.cs" />
|
||||
<Compile Include="Model\Sabnzbd\SabHistory.cs" />
|
||||
<Compile Include="Model\Sabnzbd\SabJsonError.cs" />
|
||||
|
|
|
@ -87,7 +87,7 @@ public virtual bool DownloadNzb(string url, string title)
|
|||
string name = GetNzbName(url);
|
||||
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);
|
||||
|
||||
if (url.ToLower().Contains("newzbin"))
|
||||
|
@ -98,19 +98,17 @@ public virtual bool DownloadNzb(string url, string title)
|
|||
string request = GetSabRequest(action);
|
||||
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);
|
||||
|
||||
if (response == "ok")
|
||||
return true;
|
||||
|
||||
logger.Warn("SAB returned unexpected response '{0}'", response);
|
||||
CheckForError(response);
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (WebException ex)
|
||||
{
|
||||
logger.Error("Error communicating with SAB");
|
||||
logger.Error("Error communicating with SAB: " + ex.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue