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;
|
|
|
|
|
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-01 02:11:29 +02:00
|
|
|
AppRatingEndpoint ratingEndpoint = new AppRatingEndpoint();
|
|
|
|
|
AppMetadataEndpoint metaEndpoint = new AppMetadataEndpoint();
|
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
|
|
|
{
|
|
|
|
|
AppMetadata meta = await metaEndpoint.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-01 00:19:52 +02:00
|
|
|
{
|
|
|
|
|
AppReviews reviews = await ratingEndpoint.GetReviews(ctx.id, StoreType.WindowsPhone8, StoreCultureType.EN_US, StoreReviewSorting.Latest);
|
|
|
|
|
return Response.AsJson(reviews);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-04-03 22:40:12 +02:00
|
|
|
Get["/image/{id}.jpg", true] = async (ctx, token) =>
|
2015-04-01 00:19:52 +02:00
|
|
|
{
|
|
|
|
|
Stream imageStream = await metaEndpoint.GetImageAsStream(ctx.id, StoreImageType.None);
|
|
|
|
|
return Response.FromStream(imageStream, "image/jpeg");
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|