Example #1
0
        public async Task GetRssFeedFromSubPagesOfFirstPageOfFirstSpace()
        {
            //Connect to the Notion account
            var sessionInfo   = TestUtils.CreateUnofficialNotionSessionInfo();
            var notionSession = new NotionSession(sessionInfo);

            //Get first notion "space"
            var userContent = await notionSession.LoadUserContent();

            var spacePages = userContent.RecordMap.Space.First().Value.Pages;

            //Get sub-pages of the "public blog" page, which makes the content of the blog
            var blogId    = spacePages.First(pageId => userContent.RecordMap.Block[pageId].Title == "Public blog");
            var blog      = userContent.RecordMap.Block[blogId];
            var blogPages = blog.Content;

            //Convert the blogPages into a RSS feed
            var feed = await notionSession.GetSyndicationFeed(blogPages, maxBlocks : 100);

            feed.Title = new TextSyndicationContent(blog.Title);

            Assert.IsNotNull(feed);
            Assert.IsTrue(feed.Items.Any());
            Assert.IsFalse(feed.Items.Any(item => item.Title?.Text == "Work In Progress"));
        }
Example #2
0
        public async Task RefreshNotionData()
        {
            if (isRefreshing)
            {
                return;
            }
            isRefreshing = true;

            try
            {
                var notionSession = new NotionSession(new NotionSessionInfo {
                    TokenV2 = notionOptions.Key, NotionBrowserId = notionOptions.BrowserId, NotionUserId = notionOptions.UserId
                });
                var userContent = await notionSession.LoadUserContent().ConfigureAwait(false);

                var spacePages = userContent.RecordMap.Space.First().Value.Pages;

                //Refresh CMS
                var cmsPageId = spacePages.First(pageId => userContent.RecordMap.Block.TryGetValue(pageId, out var page) && page.Title == notionOptions.CmsPageTitle);
                var cmsPages  = userContent.RecordMap.Block[cmsPageId].Content;
                var cmsItems  = await notionSession.GetSyndicationFeed(cmsPages, maxBlocks : 100, stopBeforeFirstSubHeader : false).ConfigureAwait(false);

                CmsTitle = userContent.RecordMap.Block[cmsPageId].Title;
                CmsArticles.OnNext(cmsItems.Items.ToList());
            }
            catch (Exception e)
            {
                logger.LogError(e, "Can't update notion data");
            }
            finally
            {
                isRefreshing = false;
            }
        }
Example #3
0
        public async Task GetRssFeedFromRootPagesOfFirstSpace()
        {
            var sessionInfo = TestUtils.CreateUnofficialNotionSessionInfo();
            var session     = new NotionSession(sessionInfo);

            var feed = await session.GetSyndicationFeed();

            Assert.IsNotNull(feed);
            Assert.IsTrue(feed.Items.Any());
        }
        public async Task TestGetSyndicationFeed()
        {
            var session = new NotionSession(TestUtils.CreateOfficialNotionSessionInfo());
            var pages   = await session.GetTopLevelPages().ToListAsync();

            Assert.IsNotNull(pages);
            var page = pages.Where(p => p.Title?.Title?.FirstOrDefault().PlainText == "Public blog").FirstOrDefault();

            Assert.IsNotNull(page);

            var feed = await session.GetSyndicationFeed(page);

            Assert.IsNotNull(feed?.Items);
            Assert.AreNotEqual(0, feed.Items.Count());
        }