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