From 3f515d103d0325d57448104018fdd3c6eb0b2c1b Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 18 Jun 2025 19:22:37 +0530 Subject: [PATCH] feat: notion processor service --- lib/integrations/notion/processor_service.rb | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/integrations/notion/processor_service.rb diff --git a/lib/integrations/notion/processor_service.rb b/lib/integrations/notion/processor_service.rb new file mode 100644 index 000000000..8a071ba8d --- /dev/null +++ b/lib/integrations/notion/processor_service.rb @@ -0,0 +1,36 @@ +class Integrations::Notion::ProcessorService + pattr_initialize [:account!] + + def search_pages(query, sort = nil) + response = notion_client.search(query, sort) + return { error: response[:error] } if response[:error] + + response['results'].map(&:as_json) + end + + def page(page_id) + response = notion_client.page(page_id) + return { error: response[:error] } if response[:error] + + response.as_json + end + + def page_md(page_id) + # Get page content blocks + blocks_response = notion_client.page_blocks(page_id) + return { error: blocks_response[:error] } if blocks_response[:error] + + # Convert blocks to markdown + NotionToMarkdown.new.convert(blocks_response['results']) + end + + private + + def notion_hook + @notion_hook ||= account.hooks.find_by!(app_id: 'notion') + end + + def notion_client + @notion_client ||= Notion.new(notion_hook.access_token) + end +end \ No newline at end of file