public async Task ParseFromUriWithCustomHttpMessageHandler() { JsonFeed jsonFeed = await JsonFeed.ParseFromUriAsync(new Uri("https://jsonfeed.org/feed.json"), new HttpClientHandler()); string outputJsonFeed = jsonFeed.Write(); Assert.IsNotEmpty(outputJsonFeed); }
public async Task ParseFromUri() { JsonFeed jsonFeed = await JsonFeed.ParseFromUriAsync(new Uri("https://jsonfeed.org/feed.json")); string outputJsonFeed = jsonFeed.Write(); Assert.IsNotEmpty(outputJsonFeed); }
public async Task <List <SourceData> > GetAsync(DateTime sinceWhen) { var currentTime = DateTime.UtcNow; var sourceItems = new List <SourceData>(); _logger.LogDebug("Checking the Json feed '{_jsonFeedReaderSettings.FeedUrl}' for new posts since '{sinceWhen:u}'", _jsonFeedReaderSettings.FeedUrl, sinceWhen); List <JsonFeedItem> items = null; try { var jsonFeed = await JsonFeed.ParseFromUriAsync(new Uri(_jsonFeedReaderSettings.FeedUrl)); items = jsonFeed.Items.Where(i => i.DateModified > sinceWhen || i.DatePublished > sinceWhen).ToList(); } catch (Exception e) { _logger.LogError(e, "Error parsing the Json feed for: {_jsonFeedReaderSettings.FeedUrl}.", _jsonFeedReaderSettings.FeedUrl); throw; } _logger.LogDebug($"Found {items.Count} posts."); foreach (var jsonFeedItem in items) { sourceItems.Add(new SourceData(SourceSystems.SyndicationFeed) { Author = jsonFeedItem.Author?.Name, PublicationDate = jsonFeedItem.DatePublished?.UtcDateTime ?? currentTime, UpdatedOnDate = jsonFeedItem.DateModified?.UtcDateTime ?? currentTime, //Text = jsonFeedItem.ContentHtml, Title = jsonFeedItem.Title, Url = jsonFeedItem.Id, EndAfter = null, AddedOn = currentTime, Tags = jsonFeedItem.Tags is null ? null : string.Join(",", jsonFeedItem.Tags) });