Skip to content

Commit

Permalink
Fixed #144
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Apr 6, 2016
1 parent 08cbf92 commit 3efd54c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
6 changes: 6 additions & 0 deletions PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj">
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
<Name>PlexRequests.Helpers</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion PlexRequests.Api.Models/SickRage/SickRageBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PlexRequests.Api.Models.SickRage
{
public class SickRageBase<T>
public abstract class SickRageBase<T>
{
public T data { get; set; }
public string message { get; set; }
Expand Down
31 changes: 29 additions & 2 deletions PlexRequests.Api.Models/SickRage/SickRageSeasonList.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
namespace PlexRequests.Api.Models.SickRage
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using PlexRequests.Helpers;

namespace PlexRequests.Api.Models.SickRage
{
public class SickRageSeasonList : SickRageBase<int[]>
public class SickRageSeasonList : SickRageBase<object>
{
[JsonIgnore]
public int[] Data => ParseObjectToArray<int>(data);

protected T[] ParseObjectToArray<T>(object ambiguousObject)
{
var json = ambiguousObject.ToString();
if (string.IsNullOrWhiteSpace(json))
{
return new T[0]; // Could return null here instead.
}
if (json.TrimStart().StartsWith("["))
{
return JsonConvert.DeserializeObject<T[]>(json);
}
if (json.TrimStart().Equals("{}"))
{
return new T[0];
}

return new T[1] { JsonConvert.DeserializeObject<T>(json) };

}
}
}
13 changes: 11 additions & 2 deletions PlexRequests.Api/ApiRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// ************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

Expand All @@ -33,13 +34,19 @@
using NLog;

using PlexRequests.Api.Interfaces;

using PlexRequests.Helpers;
using RestSharp;

namespace PlexRequests.Api
{
public class ApiRequest : IApiRequest
{
private JsonSerializerSettings Settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
};

private static Logger Log = LogManager.GetCurrentClassLogger();
/// <summary>
/// An API request handler
Expand Down Expand Up @@ -108,7 +115,7 @@ public T ExecuteXml<T>(IRestRequest request, Uri baseUri) where T : class
}


var json = JsonConvert.DeserializeObject<T>(response.Content);
var json = JsonConvert.DeserializeObject<T>(response.Content, Settings);

return json;
}
Expand All @@ -129,4 +136,6 @@ private T DeserializeXml<T>(string input)
}
}
}


}
2 changes: 1 addition & 1 deletion PlexRequests.Api/SickrageApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task<SickRageTvAdd> AddSeries(int tvdbId, int seasonCount, int[] se
while (seasonIncrement < seasonCount)
{
seasonList = VerifyShowHasLoaded(tvdbId, apiKey, baseUrl);
seasonIncrement = seasonList.data?.Length ?? 0;
seasonIncrement = seasonList.Data?.Length ?? 0;

if (sw.ElapsedMilliseconds > 30000) // Break out after 30 seconds, it's not going to get added
{
Expand Down
16 changes: 8 additions & 8 deletions PlexRequests.UI/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@


<!-- Scripts -->
<script src="/Content/jquery-2.2.1.min.js"></script>
<script src="/Content/handlebars.min.js"></script>
<script src="/Content/bootstrap.min.js"></script>
<script src="/Content/bootstrap-notify.min.js"></script>
<script src="/Content/site.js"></script>
<script src="/Content/pace.min.js"></script>
<script src="/Content/jquery.mixitup.js"></script>
<script src="/Content/moment.min.js"></script>
<script src="~/Content/jquery-2.2.1.min.js"></script>
<script src="~/Content/handlebars.min.js"></script>
<script src="~/Content/bootstrap.min.js"></script>
<script src="~/Content/bootstrap-notify.min.js"></script>
<script src="~/Content/site.js"></script>
<script src="~/Content/pace.min.js"></script>
<script src="~/Content/jquery.mixitup.js"></script>
<script src="~/Content/moment.min.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ assembly_info:
file: '**\AssemblyInfo.*'
assembly_version: '1.6.0'
assembly_file_version: '{version}'
assembly_informational_version: '1.6.0'
assembly_informational_version: '1.6.0'
before_build:
- cmd: appveyor-retry nuget restore
build:
Expand Down

0 comments on commit 3efd54c

Please sign in to comment.