private void AddEpisodesRoute(HttpSupport httpSupport) { 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); }); }
private void GetPage(string connectionId, string id = "", int offset = 0, int limit = 800) { var data = _libraryApiAdapter.GetEpisodes(id).ToList(); var message = CreateMessage(offset, limit, data, Constants.PodcastEpisodes); _hub.Publish(new PluginResponseAvailableEvent(message, 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"); }); }