Class: Utils::CollectionViewComponents
- Inherits:
-
Object
- Object
- Utils::CollectionViewComponents
- Defined in:
- lib/notion_api/utils.rb
Class Method Summary collapse
- .add_collection_property(collection_id, args) ⇒ Object
- .add_new_row(new_block_id) ⇒ Object
- .create_collection_view(new_block_id, collection_id, view_ids) ⇒ Object
- .insert_data(block_id, column, value) ⇒ Object
- .query_collection(collection_id, view_id, search_query = '') ⇒ Object
- .set_collection_blocks_alive(new_block_id, collection_id) ⇒ Object
- .set_collection_columns(collection_id, new_block_id, data) ⇒ Object
- .set_collection_title(collection_title, collection_id) ⇒ Object
- .set_view_config(new_block_id, view_id, children_ids) ⇒ Object
Class Method Details
.add_collection_property(collection_id, args) ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/notion_api/utils.rb', line 484 def self.add_collection_property(collection_id, args) # ! payload for adding a column to the table. # ! collection_id -> the collection ID : ``str`` # ! args -> the definition of the column : ``str`` { id: collection_id, table: 'collection', path: [], command: 'update', args: args } end |
.add_new_row(new_block_id) ⇒ Object
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/notion_api/utils.rb', line 442 def self.add_new_row(new_block_id) # ! payload for adding a new row to the table. # ! new_block_id -> the ID of the new row : ``str`` table = 'block' path = [] command = 'set' type = 'page' { id: new_block_id, table: table, path: path, command: command, args: { type: type, id: new_block_id, version: 1 } } end |
.create_collection_view(new_block_id, collection_id, view_ids) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/notion_api/utils.rb', line 280 def self.create_collection_view(new_block_id, collection_id, view_ids) # ! payload for creating a collection view # ! new_block_id -> id of the new block # ! collection_id -> ID of the collection. # ! view_ids -> id of the view table = 'block' command = 'update' path = [] type = 'collection_view' properties = {} = DateTime.now.strftime('%Q') { id: new_block_id, table: table, path: path, command: command, args: { id: new_block_id, type: type, collection_id: collection_id, view_ids: [ view_ids ], properties: properties, created_time: , last_edited_time: } } end |
.insert_data(block_id, column, value) ⇒ Object
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/notion_api/utils.rb', line 421 def self.insert_data(block_id, column, value) # ! payload for inserting data into the table. # ! block_id -> the ID of the block : ``str`` # ! column -> the name of the column to insert data into. # ! value -> the value to insert into the column. table = 'block' path = [ 'properties', column ] command = 'set' { id: block_id, table: table, path: path, command: command, args: [[value]] } end |
.query_collection(collection_id, view_id, search_query = '') ⇒ Object
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/notion_api/utils.rb', line 463 def self.query_collection(collection_id, view_id, search_query = '') # ! payload for querying the table for data. # ! collection_id -> the collection ID : ``str`` # ! view_id -> the view ID : ``str`` # ! search_query -> the query for searching the table : ``str`` query = {} loader = { type: 'table', limit: 100, searchQuery: search_query, loadContentCover: true } { collectionId: collection_id, collectionViewId: view_id, query: query, loader: loader } end |
.set_collection_blocks_alive(new_block_id, collection_id) ⇒ Object
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/notion_api/utils.rb', line 311 def self.set_collection_blocks_alive(new_block_id, collection_id) # ! payload for setting the collection blocks to alive. # ! new_block_id -> id of the new block # ! collection_id -> ID of the collection. table = 'block' path = [] command = 'update' parent_table = 'collection' alive = true type = 'page' properties = {} = DateTime.now.strftime('%Q') { id: new_block_id, table: table, path: path, command: command, args: { id: new_block_id, type: type, parent_id: collection_id, parent_table: parent_table, alive: alive, properties: properties, created_time: , last_edited_time: } } end |
.set_collection_columns(collection_id, new_block_id, data) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/notion_api/utils.rb', line 374 def self.set_collection_columns(collection_id, new_block_id, data) # ! payload for setting the columns of the table. # ! collection_id -> ID of the collection. # ! new_block_id -> id of the new block # ! data -> json data to insert into table. col_names = data[0].keys schema_conf = {} col_names.each_with_index do |_name, i| if i.zero? schema_conf[:title] = { name: col_names[i], type: 'title' } else schema_conf[col_names[i]] = { name: col_names[i], type: 'text' } end end { id: collection_id, table: 'collection', path: [], command: 'update', args: { id: collection_id, schema: schema_conf, parent_id: new_block_id, parent_table: 'block', alive: true } } end |
.set_collection_title(collection_title, collection_id) ⇒ Object
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/notion_api/utils.rb', line 404 def self.set_collection_title(collection_title, collection_id) # ! payload for setting the title of the collection. # ! collection_title -> title of the collection. # ! collection_id -> ID of the collection. table = 'collection' path = ['name'] command = 'set' { id: collection_id, table: table, path: path, command: command, args: [[collection_title]] } end |
.set_view_config(new_block_id, view_id, children_ids) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/notion_api/utils.rb', line 342 def self.set_view_config(new_block_id, view_id, children_ids) # ! payload for setting the configurations of the view. # ! new_block_id -> id of the new block # ! view_id -> id of the view # ! children_ids -> IDs for the children of the collection. table = 'collection_view' path = [] command = 'update' version = 0 type = 'table' name = 'Default View' parent_table = 'block' alive = true { id: view_id, table: table, path: path, command: command, args: { id: view_id, version: version, type: type, name: name, page_sort: children_ids, parent_id: new_block_id, parent_table: parent_table, alive: alive } } end |