Example #1
0
        private void AddArtworkRoute(HttpSupport httpSupport)
        {
            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");
            });
        }
Example #2
0
        public void Execute(IEvent receivedEvent)
        {
            if (receivedEvent == null)
            {
                throw new ArgumentNullException(nameof(receivedEvent));
            }

            var connectionId = receivedEvent.ConnectionId;

            if (!(receivedEvent.Data is JObject data))
            {
                Publish(Message((int)HttpStatusCode.BadRequest, "no artwork"), connectionId);
                return;
            }

            var id = (string)data["id"];

            if (string.IsNullOrWhiteSpace(id))
            {
                Publish(Message((int)HttpStatusCode.BadRequest, "missing id"), connectionId);
                return;
            }

            var artwork = _libraryApiAdapter.GetPodcastSubscriptionArtwork(id);
            var base64  = Convert.ToBase64String(artwork);

            Publish(Message((int)HttpStatusCode.OK, string.Empty, base64), connectionId);
        }
Example #3
0
        public void Execute(IEvent @event)
        {
            var data         = @event.Data as JObject;
            var connectionId = @event.ConnectionId;

            if (data == null)
            {
                Publish(Message((int)HttpStatusCode.BadRequest, "no artwork"), connectionId);
                return;
            }
            var id = (string)data["id"];

            if (string.IsNullOrWhiteSpace(id))
            {
                Publish(Message((int)HttpStatusCode.BadRequest, "missing id"), connectionId);
                return;
            }
            var artwork = _libraryApiAdapter.GetPodcastSubscriptionArtwork(id);
            var base64  = Convert.ToBase64String(artwork);

            Publish(Message((int)HttpStatusCode.OK, "", base64), connectionId);
        }
        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");
            });
        }