Class: Utils::BlockComponents
- Inherits:
-
Object
- Object
- Utils::BlockComponents
- Defined in:
- lib/notion_api/utils.rb
Class Method Summary collapse
- .add_emoji_icon(block_id, icon) ⇒ Object
- .block_location_add(block_parent_id, block_id, new_block_id = nil, target, command) ⇒ Object
- .block_location_remove(block_parent_id, block_id) ⇒ Object
- .checked_todo(block_id, standardized_check_val) ⇒ Object
- .convert_type(id, block_class_to_convert_to) ⇒ Object
-
.create(block_id, block_type) ⇒ Object
! Each function defined here builds one component that is included in each request sent to Notions backend.
- .duplicate(block_type, block_title, block_id, new_block_id, user_notion_id, contents, properties, formatting) ⇒ Object
- .last_edited_time(id) ⇒ Object
- .parent_location_add(block_parent_id, block_id) ⇒ Object
- .set_block_to_dead(block_id) ⇒ Object
- .set_parent_to_alive(block_parent_id, new_block_id) ⇒ Object
- .title(id, title) ⇒ Object
- .update_codeblock_language(block_id, coding_language) ⇒ Object
Class Method Details
.add_emoji_icon(block_id, icon) ⇒ Object
276 277 278 279 280 281 282 283 |
# File 'lib/notion_api/utils.rb', line 276 def self.add_emoji_icon(block_id, icon) { id: block_id, table:"block", path:["format","page_icon"], command:"set","args": icon } end |
.block_location_add(block_parent_id, block_id, new_block_id = nil, target, command) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/notion_api/utils.rb', line 190 def self.block_location_add(block_parent_id, block_id, new_block_id = nil, target, command) # ! payload for duplicating a block. Most properties should be # ! inherited from the block class the method is invoked on. # ! block_parent_id -> id of parent block : ``str`` # ! block_id -> id of block: ``str`` # ! new_block_id -> id of the new block: ``str`` # ! target -> the ID of the target block : ``str`` # ! command -> the position of the block, before or after, in relation to the target : ``str`` table = "block" path = ["content"] args = if command == "listAfter" { after: target || block_id, id: new_block_id || block_id, } else { before: target || block_id, id: new_block_id || block_id, } end { table: table, id: block_parent_id, # ID of the parent for the new block. It should be the block that the method is invoked on. path: path, command: command, args: args, } end |
.block_location_remove(block_parent_id, block_id) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/notion_api/utils.rb', line 222 def self.block_location_remove(block_parent_id, block_id) # ! removes a notion block # ! block_parent_id -> the parent ID of the block to remove : ``str`` # ! block_id -> the ID of the block to remove : ``str`` table = "block" path = ["content"] command = "listRemove" { table: table, id: block_parent_id, # ID of the parent for the new block. It should be the block that the method is invoked on. path: path, command: command, args: { id: block_id, }, } end |
.checked_todo(block_id, standardized_check_val) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/notion_api/utils.rb', line 240 def self.checked_todo(block_id, standardized_check_val) # ! payload for setting a "checked" value for TodoBlock. # ! block_id -> the ID of the block to remove : ``str`` # ! standardized_check_val -> tyes/no value, determines the checked property of the block : ``str`` table = "block" path = ["properties"] command = "update" { id: block_id, table: table, path: path, command: command, args: { checked: [[standardized_check_val]], }, } end |
.convert_type(id, block_class_to_convert_to) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/notion_api/utils.rb', line 70 def self.convert_type(id, block_class_to_convert_to) # ! payload for converting a block to a different type. # ! id -> id of the block to convert : ``str`` # ! block_class_to_convert_to -> type to convert to block to: ``NotionAPI::<Block_Type>`` table = "block" path = [] command = "update" { id: id, table: table, path: path, command: command, args: { type: block_class_to_convert_to.notion_type, }, } end |
.create(block_id, block_type) ⇒ Object
! Each function defined here builds one component that is included in each request sent to Notions backend. ! Each request sent will contain multiple components.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/notion_api/utils.rb', line 14 def self.create(block_id, block_type) # ! payload for creating a block. # ! block_id -> id of the new block : ``str`` # ! block_type -> type of block to create : ``cls`` table = "block" path = [] command = "update" = DateTime.now.strftime("%Q") { id: block_id, table: table, path: path, command: command, args: { id: block_id, type: block_type, properties: {}, created_time: , last_edited_time: , }, } end |
.duplicate(block_type, block_title, block_id, new_block_id, user_notion_id, contents, properties, formatting) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/notion_api/utils.rb', line 130 def self.duplicate(block_type, block_title, block_id, new_block_id, user_notion_id, contents, properties, formatting) # ! payload for duplicating a block. Most properties should be # ! inherited from the block class the method is invoked on. # ! block_type -> type of block that is being duplicated : ``cls`` # ! block_title -> title of block : ``str`` # ! block_id -> id of block: ``str`` # ! new_block_id -> id of new block : ``str`` # ! user_notion_id -> ID of notion user : ``str`` # ! contents -> The children of the block = DateTime.now.strftime("%Q") table = "block" path = [] command = "update" { id: new_block_id, table: table, path: path, command: command, args: { id: new_block_id, version: 10, type: block_type, properties: properties, format: formatting, content: contents, # root-level blocks created_time: , last_edited_time: , created_by_table: "notion_user", created_by_id: user_notion_id, last_edited_by_table: "notion_user", last_edited_by_id: user_notion_id, copied_from: block_id, }, } end |
.last_edited_time(id) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/notion_api/utils.rb', line 53 def self.last_edited_time(id) # ! payload for updating the last edited time # ! id -> either the block ID or parent ID : ``str`` = DateTime.now.strftime("%Q") table = "block" path = ["last_edited_time"] command = "set" { table: table, id: id, path: path, command: command, args: , } end |
.parent_location_add(block_parent_id, block_id) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/notion_api/utils.rb', line 167 def self.parent_location_add(block_parent_id, block_id) # ! payload for adding a parent # ! block_parent_id -> the parent id of the block : ``str`` # ! block_id -> the id of the block : ``str`` table = "block" path = [] command = "update" parent_table = "block" alive = true { id: block_id, table: table, path: path, command: command, args: { parent_id: block_parent_id, parent_table: parent_table, alive: alive, }, } end |
.set_block_to_dead(block_id) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/notion_api/utils.rb', line 111 def self.set_block_to_dead(block_id) # ! payload for setting a block to dead (alive == true) # ! block_id -> the block ID to 'kill' : ``str`` table = "block" path = [] command = "update" alive = false { id: block_id, table: table, path: path, command: command, args: { alive: alive, }, } end |
.set_parent_to_alive(block_parent_id, new_block_id) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/notion_api/utils.rb', line 89 def self.set_parent_to_alive(block_parent_id, new_block_id) # ! payload for setting a blocks parent ID to 'alive' # ! block_parent_id -> the blocks parent ID : ``str`` # ! new_block_id -> the new block ID, who is a child of the parent : ``str`` table = "block" path = [] command = "update" parent_table = "block" alive = true { id: new_block_id, table: table, path: path, command: command, args: { parent_id: block_parent_id, parent_table: parent_table, alive: alive, }, } end |
.title(id, title) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/notion_api/utils.rb', line 37 def self.title(id, title) # ! payload for updating the title of a block # ! id -> the ID to update the title of : ``str`` table = "block" path = %w[properties title] command = "set" { id: id, table: table, path: path, command: command, args: [[title]], } end |
.update_codeblock_language(block_id, coding_language) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/notion_api/utils.rb', line 258 def self.update_codeblock_language(block_id, coding_language) # ! update the language for a codeblock # ! block_id -> id of the code block # ! coding_language -> language to change the block to. table = "block" path = ["properties"] command = "update" { id: block_id, table: table, path: path, command: command, args: { language: [[coding_language]], }, } end |