Exemple #1
0
        private void AddPodcastsRoute(HttpSupport httpSupport)
        {
            httpSupport.AddRoute(@"/podcasts", (ctx, data) =>
            {
                var request = ctx.Request;
                if (CheckIfNotPost(request, ctx))
                {
                    return;
                }

                if (CheckIfNotJson(request, ctx))
                {
                    return;
                }

                var requestPayload = ReadPayload(request);

                if (CheckIfNotEmpty(requestPayload, ctx))
                {
                    return;
                }

                var requestData   = JsonConvert.DeserializeObject <PaginatedRequest>(requestPayload);
                var subscriptions = _adapter.GetPodcastSubscriptions().ToList();
                var page          = PaginatedData.CreatePage(requestData.Offset, requestData.Limit, subscriptions);
                ctx.OutputUtf8(JsonConvert.SerializeObject(page), "application/json", Encoding.UTF8);
            });
        }
Exemple #2
0
 protected override List <PodcastSubscription> GetData()
 {
     return(_libraryApiAdapter.GetPodcastSubscriptions().ToList());
 }
        public void RegisterRoutes(HttpSupport httpSupport)
        {
            httpSupport.AddRoute(@"/podcasts", (ctx, data) =>
            {
                var request = ctx.Request;
                if (CheckIfNotPost(request, ctx))
                {
                    return;
                }
                if (CheckIfNotJson(request, ctx))
                {
                    return;
                }

                var requestPayload = ReadPayload(request);

                if (CheckIfNotEmpty(requestPayload, ctx))
                {
                    return;
                }

                var requestData   = JsonConvert.DeserializeObject <PaginatedRequest>(requestPayload);
                var subscriptions = _adapter.GetPodcastSubscriptions().ToList();
                var page          = PaginatedData.CreatePage(requestData.Offset, requestData.Limit, subscriptions);
                ctx.OutputUtf8(JsonConvert.SerializeObject(page), "application/json", Encoding.UTF8);
            });

            httpSupport.AddRoute(@"/episodes", (ctx, data) =>
            {
                var request = ctx.Request;
                if (CheckIfNotPost(request, ctx))
                {
                    return;
                }
                if (CheckIfNotJson(request, ctx))
                {
                    return;
                }

                var requestPayload = ReadPayload(request);

                if (CheckIfNotEmpty(requestPayload, ctx))
                {
                    return;
                }

                var requestData = JsonConvert.DeserializeObject <IdentifiablePaginatedRequest>(requestPayload);

                if (string.IsNullOrWhiteSpace(requestData.Id))
                {
                    ctx.WriteError((int)HttpStatusCode.BadRequest, "invalid id");
                    return;
                }

                var episodes = _adapter.GetEpisodes(requestData.Id).ToList();
                var page     = PaginatedData.CreatePage(requestData.Offset, requestData.Limit, episodes);
                ctx.OutputUtf8(JsonConvert.SerializeObject(page), "application/json", Encoding.UTF8);
            });

            httpSupport.AddRoute(@"/subscription-artwork", (ctx, data) =>
            {
                var request = ctx.Request;
                if (CheckIfNotPost(request, ctx))
                {
                    return;
                }
                if (CheckIfNotJson(request, ctx))
                {
                    return;
                }

                var requestPayload = ReadPayload(request);

                if (CheckIfNotEmpty(requestPayload, ctx))
                {
                    return;
                }
                var requestData = JsonConvert.DeserializeObject <IdentifiableRequest>(requestPayload);

                if (string.IsNullOrWhiteSpace(requestData.Id))
                {
                    ctx.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return;
                }
                ctx.OutputBinary(_adapter.GetPodcastSubscriptionArtwork(requestData.Id), "image/jpeg");
            });
        }