Class: NotionAPI::LinkBlock

Inherits:
BlockTemplate show all
Defined in:
lib/notion_api/notion_types/link_block.rb

Overview

simiilar to code block but for mathematical functions.

Constant Summary

Constants included from Utils

Utils::URLS

Class Attribute Summary collapse

Attributes inherited from BlockTemplate

#id, #parent_id, #title

Attributes inherited from Core

#clean_id, #cookies, #headers

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BlockTemplate

#convert, #create, #duplicate, #initialize, #move

Methods included from Utils

#build_payload

Methods inherited from Core

#children, #children_ids, #extract_id, #get_page, #initialize

Constructor Details

This class inherits a constructor from NotionAPI::BlockTemplate

Class Attribute Details

.notion_typeObject (readonly)

Returns the value of attribute notion_type.



13
14
15
# File 'lib/notion_api/notion_types/link_block.rb', line 13

def notion_type
  @notion_type
end

.typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/notion_api/notion_types/link_block.rb', line 13

def type
  @type
end

Class Method Details

.create(block_id, new_block_id, block_title, target, position_command, request_ids, options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/notion_api/notion_types/link_block.rb', line 16

def self.create(block_id, new_block_id, block_title, target, position_command, request_ids, options)
  block_title = super.extract_id(block_title)

  cookies = Core.options["cookies"]
  headers = Core.options["headers"]
  
  create_block_hash = Utils::BlockComponents.create(new_block_id, self.notion_type)
  block_location_hash = Utils::BlockComponents.block_location_add(block_id, block_id, block_title, new_block_id, position_command)
  last_edited_time_hash = Utils::BlockComponents.last_edited_time(block_id)
  remove_item_hash = Utils::BlockComponents.block_location_remove( super.parent_id, new_block_id)
  
  operations = [
    create_block_hash,
    block_location_hash,
    last_edited_time_hash,
    remove_item_hash
  ]
  
  request_url = URLS[:UPDATE_BLOCK]
  request_body = Utils::BlockComponents.build_payload(operations, request_ids)
  
  response = HTTParty.post(
    request_url,
    body: request_body.to_json,
    cookies: cookies,
    headers: headers,
  )

  unless response.code == 200; raise "There was an issue completing your request. Here is the response from Notion: #{response.body}, and here is the payload that was sent: #{operations}.
       Please try again, and if issues persist open an issue in GitHub.";       end
  
  self.new(new_block_id, block_title, block_id)
end

Instance Method Details

#typeObject



8
9
10
# File 'lib/notion_api/notion_types/link_block.rb', line 8

def type
  NotionAPI::LinkBlock.notion_type
end