You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
782 B
25 lines
782 B
using System.IO;
|
|
using System.Linq;
|
|
using Nancy;
|
|
using Nancy.Responses;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace NzbDrone.Services.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;
|
|
}
|
|
}
|
|
} |