Some styling

This commit is contained in:
tidusjar 2016-03-04 13:19:17 +00:00
commit 37aa6b938d
9 changed files with 102 additions and 37 deletions

View file

@ -39,7 +39,7 @@ namespace PlexRequests.Api
{
public class ApiRequest : IApiRequest
{
/// <summary>
/// An API request handler
/// </summary>
@ -54,7 +54,7 @@ namespace PlexRequests.Api
var response = client.Execute<T>(request);
if (response.ErrorException != null)
{
{
var message = "Error retrieving response. Check inner details for more info.";
throw new ApplicationException(message, response.ErrorException);
}
@ -75,7 +75,8 @@ namespace PlexRequests.Api
throw new ApplicationException(message, response.ErrorException);
}
return Deserialize<T>(response.Content);
var result = Deserialize<T>(response.Content);
return result;
}
public T Deserialize<T>(string input)
@ -83,8 +84,15 @@ namespace PlexRequests.Api
{
var ser = new XmlSerializer(typeof(T));
using (var sr = new StringReader(input))
return (T)ser.Deserialize(sr);
try
{
using (var sr = new StringReader(input))
return (T)ser.Deserialize(sr);
}
catch (InvalidOperationException)
{
return null;
}
}
}
}

View file

@ -0,0 +1,38 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: PlexError.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Xml.Serialization;
namespace PlexRequests.Api.Models
{
[XmlRoot(ElementName = "errors")]
public class PlexError
{
[XmlElement(ElementName = "error")]
public string Error { get; set; }
}
}

View file

@ -62,6 +62,7 @@
<ItemGroup>
<Compile Include="ApiRequest.cs" />
<Compile Include="Models\PlexAuthentication.cs" />
<Compile Include="Models\PlexError.cs" />
<Compile Include="Models\PlexFriends.cs" />
<Compile Include="Models\PlexUserRequest.cs" />
<Compile Include="Models\Tv\Authentication.cs" />