Files
onepeek/src/OnePeek.WebConsole/Modules/ApiModule.cs
T

43 lines
1.2 KiB
C#
Raw Normal View History

using Nancy;
using OnePeek.Api;
using OnePeek.Entities;
2015-04-15 23:43:42 +02:00
using System.Collections.Generic;
using System.IO;
2015-04-03 22:40:12 +02:00
namespace OnePeek.WebConsole.Modules
{
2015-04-01 02:21:22 +02:00
public class ApiModule : NancyModule
{
2015-04-01 02:21:22 +02:00
public ApiModule() : base("api/")
{
2015-04-20 23:51:31 +02:00
OnePeekApi api = new OnePeekApi();
2015-04-03 22:40:12 +02:00
Get["/meta/{id}", true] = async (ctx, token) =>
{
2015-04-20 23:51:31 +02:00
AppMetadata meta = await api.GetMetadata(ctx.id, StoreType.WindowsPhone8, StoreCultureType.EN_US);
return Response.AsJson(meta);
};
2015-04-03 22:40:12 +02:00
Get["/reviews/{id}", true] = async (ctx, token) =>
{
2015-04-20 23:51:31 +02:00
AppReviews reviews = await api.GetReviews(ctx.id, StoreType.WindowsPhone8, StoreCultureType.EN_US, StoreReviewSorting.Latest);
return Response.AsJson(reviews);
};
2015-04-15 23:43:42 +02:00
Get["/ratings/{id}", true] = async (ctx, token) =>
{
2015-04-20 23:51:31 +02:00
IEnumerable<AppRating> ratings = await api.GetRatingsForAllCultures(ctx.id, StoreType.WindowsPhone8, new System.Threading.CancellationTokenSource().Token, null);
2015-04-15 23:43:42 +02:00
return Response.AsJson(ratings);
};
2015-04-03 22:40:12 +02:00
Get["/image/{id}.jpg", true] = async (ctx, token) =>
{
2015-04-20 23:51:31 +02:00
Stream imageStream = await api.GetImageAsStream(ctx.id, StoreImageType.None);
return Response.FromStream(imageStream, "image/jpeg");
};
}
}
}