Class: CollavreNotion::NotionService
- Inherits:
-
Object
- Object
- CollavreNotion::NotionService
- Defined in:
- app/services/collavre_notion/notion_service.rb
Instance Method Summary collapse
- #append_blocks(parent_id, blocks) ⇒ Object
- #client ⇒ Object
- #create_page(parent_id:, title:, blocks: []) ⇒ Object
- #delete_block(block_id) ⇒ Object
- #get_page(page_id) ⇒ Object
- #get_page_blocks(page_id, start_cursor: nil, page_size: 100) ⇒ Object
- #get_workspace ⇒ Object
-
#initialize(user:) ⇒ NotionService
constructor
A new instance of NotionService.
- #replace_page_blocks(page_id, blocks) ⇒ Object
- #search_pages(query: nil, start_cursor: nil, page_size: 10) ⇒ Object
-
#sync_creative(creative, parent_page_id: nil) ⇒ Object
Create or update a page for a creative.
- #update_page(page_id, properties: {}, blocks: nil) ⇒ Object
Constructor Details
#initialize(user:) ⇒ NotionService
Returns a new instance of NotionService.
5 6 7 8 9 |
# File 'app/services/collavre_notion/notion_service.rb', line 5 def initialize(user:) @user = user @account = user.notion_account raise NotionAuthError, "No Notion account found" unless @account end |
Instance Method Details
#append_blocks(parent_id, blocks) ⇒ Object
39 40 41 |
# File 'app/services/collavre_notion/notion_service.rb', line 39 def append_blocks(parent_id, blocks) with_token_refresh { client.append_blocks(parent_id, blocks) } end |
#client ⇒ Object
11 12 13 |
# File 'app/services/collavre_notion/notion_service.rb', line 11 def client @client ||= NotionClient.new(@account) end |
#create_page(parent_id:, title:, blocks: []) ⇒ Object
23 24 25 |
# File 'app/services/collavre_notion/notion_service.rb', line 23 def create_page(parent_id:, title:, blocks: []) with_token_refresh { client.create_page(parent_id: parent_id, title: title, blocks: blocks) } end |
#delete_block(block_id) ⇒ Object
43 44 45 |
# File 'app/services/collavre_notion/notion_service.rb', line 43 def delete_block(block_id) with_token_refresh { client.delete_block(block_id) } end |
#get_page(page_id) ⇒ Object
19 20 21 |
# File 'app/services/collavre_notion/notion_service.rb', line 19 def get_page(page_id) with_token_refresh { client.get_page(page_id) } end |
#get_page_blocks(page_id, start_cursor: nil, page_size: 100) ⇒ Object
31 32 33 |
# File 'app/services/collavre_notion/notion_service.rb', line 31 def get_page_blocks(page_id, start_cursor: nil, page_size: 100) with_token_refresh { client.get_page_blocks(page_id, start_cursor: start_cursor, page_size: page_size) } end |
#get_workspace ⇒ Object
47 48 49 |
# File 'app/services/collavre_notion/notion_service.rb', line 47 def get_workspace with_token_refresh { client.get_workspace } end |
#replace_page_blocks(page_id, blocks) ⇒ Object
35 36 37 |
# File 'app/services/collavre_notion/notion_service.rb', line 35 def replace_page_blocks(page_id, blocks) with_token_refresh { client.replace_page_blocks(page_id, blocks) } end |
#search_pages(query: nil, start_cursor: nil, page_size: 10) ⇒ Object
15 16 17 |
# File 'app/services/collavre_notion/notion_service.rb', line 15 def search_pages(query: nil, start_cursor: nil, page_size: 10) with_token_refresh { client.search_pages(query: query, start_cursor: start_cursor, page_size: page_size) } end |
#sync_creative(creative, parent_page_id: nil) ⇒ Object
Create or update a page for a creative
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/collavre_notion/notion_service.rb', line 52 def sync_creative(creative, parent_page_id: nil) notion_link = find_or_create_page_link(creative, parent_page_id) if notion_link.page_id.present? # Update existing page update_creative_page(creative, notion_link) else # Create new page create_creative_page(creative, notion_link, parent_page_id) end notion_link.mark_synced! notion_link end |
#update_page(page_id, properties: {}, blocks: nil) ⇒ Object
27 28 29 |
# File 'app/services/collavre_notion/notion_service.rb', line 27 def update_page(page_id, properties: {}, blocks: nil) with_token_refresh { client.update_page(page_id, properties: properties, blocks: blocks) } end |