This commit is contained in:
kay.one 2013-02-23 12:35:26 -08:00
parent c35682376e
commit cf8be4bf8f
16 changed files with 20 additions and 21 deletions

View file

@ -0,0 +1,25 @@
using System.IO;
using System.Linq;
using Nancy;
using Nancy.Responses;
using Newtonsoft.Json;
namespace NzbDrone.Api.Extensions
{
public static class JsonExtensions
{
public static T FromJson<T>(this Stream body)
{
var reader = new StreamReader(body, true);
body.Position = 0;
var value = reader.ReadToEnd();
return JsonConvert.DeserializeObject<T>(value, Serializer.Settings);
}
public static JsonResponse<TModel> AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK)
{
var jsonResponse = new JsonResponse<TModel>(model, new NancyJsonSerializer()) { StatusCode = statusCode };
return jsonResponse;
}
}
}