Example #1
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 #2
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 #3
0
        public async Task TestGetUserTasks()
        {
            var sessionInfo = TestUtils.CreateUnofficialNotionSessionInfo();
            var session     = new NotionSession(sessionInfo);

            var userTasks = await session.GetUserTasks(new object());

            Assert.IsNotNull(userTasks);

            var clientExperiments = await session.GetClientExperiments(Guid.Parse("53d14533-94b9-4e87-aec8-9378b2bcedcc"));

            Assert.IsNotNull(clientExperiments);
            Assert.IsTrue(clientExperiments.Experiments.Count > 0);

            var userContent = await session.LoadUserContent();

            Assert.IsNotNull(userContent);
        }