notion 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/notion_api/notion_types/collection_view_blocks.rb +12 -3
- data/lib/notion_api/utils.rb +121 -59
- data/lib/notion_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 260bf00a0f7ffc3dec1cbf364c69815e5dcbf829677710e5b740bd58476ca9f7
|
4
|
+
data.tar.gz: 7220c9399aca9756e4773dda4b5fbdd573bd3decfe32758797ea11e309e6f0e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5933ae50944a7f77e6c68410d4291935b769869b59f71817dabd98df2e5a50f86f6200c4b7bc9800249e274c4e3ecd1e5d339df66cb08e258c50c25308e3bba
|
7
|
+
data.tar.gz: e01f29a16242b81b586d7852062efe030a760f30620096a691be6ee47c45de3d5f1b1ef7ce0f166a6c3328e3972ca470aaffd51b235f8d9f2f6c8b6ead69c193
|
@@ -33,7 +33,9 @@ module NotionAPI
|
|
33
33
|
transaction_id = extract_id(SecureRandom.hex(16))
|
34
34
|
space_id = extract_id(SecureRandom.hex(16))
|
35
35
|
new_block_id = extract_id(SecureRandom.hex(16))
|
36
|
-
|
36
|
+
collection_data = extract_collection_data(collection_id, view_id)
|
37
|
+
last_row_id = collection_data["collection_view"][@view_id]["value"]["page_sort"][-1]
|
38
|
+
schema = collection_data['collection'][collection_id]['value']['schema']
|
37
39
|
keys = schema.keys
|
38
40
|
col_map = {}
|
39
41
|
keys.map { |key| col_map[schema[key]["name"]] = key }
|
@@ -47,17 +49,24 @@ module NotionAPI
|
|
47
49
|
instantiate_row = Utils::CollectionViewComponents.add_new_row(new_block_id)
|
48
50
|
set_block_alive = Utils::CollectionViewComponents.set_collection_blocks_alive(new_block_id, @collection_id)
|
49
51
|
new_block_edited_time = Utils::BlockComponents.last_edited_time(new_block_id)
|
50
|
-
|
52
|
+
page_sort = Utils::BlockComponents.row_location_add(last_row_id, new_block_id, @view_id)
|
51
53
|
|
52
54
|
operations = [
|
53
55
|
instantiate_row,
|
54
56
|
set_block_alive,
|
55
57
|
new_block_edited_time,
|
56
|
-
|
58
|
+
page_sort
|
57
59
|
]
|
58
60
|
|
59
61
|
data.keys.each_with_index do |col_name, j|
|
60
62
|
unless col_map.keys.include?(col_name.to_s); raise ArgumentError, "Column '#{col_name.to_s}' does not exist." end
|
63
|
+
if %q[select multi_select].include?(schema[col_map[col_name.to_s]]["type"])
|
64
|
+
options = schema[col_map[col_name.to_s]]["options"].map {|option| option["value"]}
|
65
|
+
if !options.include?(data[col_name])
|
66
|
+
create_new_option = Utils::CollectionViewComponents.add_new_option(col_map[col_name.to_s], data[col_name], @collection_id)
|
67
|
+
operations.push(create_new_option)
|
68
|
+
end
|
69
|
+
end
|
61
70
|
child_component = Utils::CollectionViewComponents.insert_data(new_block_id, col_map[col_name.to_s], data[col_name], schema[col_map[col_name.to_s]]["type"])
|
62
71
|
operations.push(child_component)
|
63
72
|
end
|
data/lib/notion_api/utils.rb
CHANGED
@@ -200,14 +200,14 @@ module Utils
|
|
200
200
|
|
201
201
|
args = if command == "listAfter"
|
202
202
|
{
|
203
|
-
|
204
|
-
|
205
|
-
|
203
|
+
after: target || block_id,
|
204
|
+
id: new_block_id || block_id,
|
205
|
+
}
|
206
206
|
else
|
207
207
|
{
|
208
|
-
|
209
|
-
|
210
|
-
|
208
|
+
before: target || block_id,
|
209
|
+
id: new_block_id || block_id,
|
210
|
+
}
|
211
211
|
end
|
212
212
|
|
213
213
|
{
|
@@ -219,6 +219,21 @@ module Utils
|
|
219
219
|
}
|
220
220
|
end
|
221
221
|
|
222
|
+
def self.row_location_add(last_row_id, block_id, view_id)
|
223
|
+
{
|
224
|
+
"table": "collection_view",
|
225
|
+
"id": view_id,
|
226
|
+
"path": [
|
227
|
+
"page_sort"
|
228
|
+
],
|
229
|
+
"command": "listAfter",
|
230
|
+
"args": {
|
231
|
+
"after": last_row_id,
|
232
|
+
"id": block_id
|
233
|
+
}
|
234
|
+
}
|
235
|
+
end
|
236
|
+
|
222
237
|
def self.block_location_remove(block_parent_id, block_id)
|
223
238
|
# ! removes a notion block
|
224
239
|
# ! block_parent_id -> the parent ID of the block to remove : ``str``
|
@@ -276,9 +291,9 @@ module Utils
|
|
276
291
|
def self.add_emoji_icon(block_id, icon)
|
277
292
|
{
|
278
293
|
id: block_id,
|
279
|
-
table:"block",
|
280
|
-
path:["format","page_icon"],
|
281
|
-
command:"set","args": icon
|
294
|
+
table: "block",
|
295
|
+
path: ["format", "page_icon"],
|
296
|
+
command: "set", "args": icon,
|
282
297
|
}
|
283
298
|
end
|
284
299
|
end
|
@@ -383,14 +398,14 @@ module Utils
|
|
383
398
|
# ! new_block_id -> id of the new block
|
384
399
|
# ! data -> json data to insert into table.
|
385
400
|
col_names = data[0].keys
|
386
|
-
data_mappings = {Integer => "number", String => "text", Array => "text", Float => "number", Date => "date"}
|
401
|
+
data_mappings = { Integer => "number", String => "text", Array => "text", Float => "number", Date => "date" }
|
387
402
|
exceptions = [ArgumentError, TypeError]
|
388
403
|
data_types = col_names.map do |name|
|
389
404
|
# TODO: this is a little hacky... should probably think about a better way or add a requirement for user input to match a certain criteria.
|
390
|
-
begin
|
405
|
+
begin
|
391
406
|
DateTime.parse(data[0][name]) ? data_mappings[Date] : nil
|
392
407
|
rescue *exceptions
|
393
|
-
data_mappings[data[0][name].class]
|
408
|
+
data_mappings[data[0][name].class]
|
394
409
|
end
|
395
410
|
end
|
396
411
|
|
@@ -403,18 +418,18 @@ module Utils
|
|
403
418
|
end
|
404
419
|
end
|
405
420
|
return {
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
421
|
+
id: collection_id,
|
422
|
+
table: "collection",
|
423
|
+
path: [],
|
424
|
+
command: "update",
|
425
|
+
args: {
|
426
|
+
id: collection_id,
|
427
|
+
schema: schema_conf,
|
428
|
+
parent_id: new_block_id,
|
429
|
+
parent_table: "block",
|
430
|
+
alive: true,
|
431
|
+
},
|
432
|
+
}, data_types
|
418
433
|
end
|
419
434
|
|
420
435
|
def self.set_collection_title(collection_title, collection_id)
|
@@ -440,6 +455,11 @@ module Utils
|
|
440
455
|
# ! column -> the name of the column to insert data into.
|
441
456
|
# ! value -> the value to insert into the column.
|
442
457
|
# ! mapping -> the column data type.
|
458
|
+
simple_mappings = ["title", "text", "phone_number", "email", "url", "number", "checkbox", "select", "multi_select"]
|
459
|
+
datetime_mappings = ["date"]
|
460
|
+
media_mappings = ["file"]
|
461
|
+
person_mappings = ["person"]
|
462
|
+
|
443
463
|
table = "block"
|
444
464
|
path = [
|
445
465
|
"properties",
|
@@ -447,12 +467,47 @@ module Utils
|
|
447
467
|
]
|
448
468
|
command = "set"
|
449
469
|
|
470
|
+
if simple_mappings.include?(mapping)
|
471
|
+
args = [[value]]
|
472
|
+
elsif media_mappings.include?(mapping)
|
473
|
+
args = [[value, [["a", value]]]]
|
474
|
+
elsif datetime_mappings.include?(mapping)
|
475
|
+
args = [["‣", [["d", { "type": "date", "start_date": value }]]]]
|
476
|
+
elsif person_mappings.include?(mapping)
|
477
|
+
args = [["‣",
|
478
|
+
[["u", value]]
|
479
|
+
]]
|
480
|
+
else
|
481
|
+
raise SchemaTypeError, "Invalid property type: #{mapping}"
|
482
|
+
end
|
483
|
+
|
450
484
|
{
|
451
|
-
id: block_id,
|
452
485
|
table: table,
|
486
|
+
id: block_id,
|
487
|
+
command: command,
|
453
488
|
path: path,
|
489
|
+
args: args,
|
490
|
+
}
|
491
|
+
end
|
492
|
+
|
493
|
+
def self.add_new_option(column, value, collection_id)
|
494
|
+
table = "collection"
|
495
|
+
path = ["schema", column, "options"]
|
496
|
+
command = "keyedObjectListAfter"
|
497
|
+
args = {
|
498
|
+
"value": {
|
499
|
+
"id": SecureRandom.hex(16),
|
500
|
+
"value": value,
|
501
|
+
"color": "green"
|
502
|
+
}
|
503
|
+
}
|
504
|
+
|
505
|
+
{
|
506
|
+
table: table,
|
507
|
+
id: collection_id,
|
454
508
|
command: command,
|
455
|
-
|
509
|
+
path: path,
|
510
|
+
args: args,
|
456
511
|
}
|
457
512
|
end
|
458
513
|
|
@@ -505,45 +560,45 @@ module Utils
|
|
505
560
|
args["format"] = {
|
506
561
|
"table_properties" => [
|
507
562
|
{
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
563
|
+
"property" => "title",
|
564
|
+
"visible" => true,
|
565
|
+
"width" => 280,
|
566
|
+
},
|
512
567
|
{
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
568
|
+
"property" => "aliases",
|
569
|
+
"visible" => true,
|
570
|
+
"width" => 200,
|
571
|
+
},
|
517
572
|
{
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
573
|
+
"property" => "category",
|
574
|
+
"visible" => true,
|
575
|
+
"width" => 200,
|
576
|
+
},
|
522
577
|
{
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
578
|
+
"property" => "description",
|
579
|
+
"visible" => true,
|
580
|
+
"width" => 200,
|
581
|
+
},
|
527
582
|
{
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
583
|
+
"property" => "ios_version",
|
584
|
+
"visible" => true,
|
585
|
+
"width" => 200,
|
586
|
+
},
|
587
|
+
{
|
588
|
+
"property" => "tags",
|
589
|
+
"visible" => true,
|
590
|
+
"width" => 200,
|
591
|
+
},
|
532
592
|
{
|
533
|
-
"property" => "tags",
|
534
|
-
"visible" => true,
|
535
|
-
"width" => 200,
|
536
|
-
},
|
537
|
-
{
|
538
593
|
"property" => "phone",
|
539
594
|
"visible" => true,
|
540
595
|
"width" => 200,
|
541
596
|
},
|
542
597
|
{
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
598
|
+
"property" => "unicode_version",
|
599
|
+
"visible" => true,
|
600
|
+
"width" => 200,
|
601
|
+
},
|
547
602
|
],
|
548
603
|
}
|
549
604
|
{
|
@@ -563,11 +618,11 @@ module Utils
|
|
563
618
|
table = "block"
|
564
619
|
path = [
|
565
620
|
"properties",
|
566
|
-
column_name
|
621
|
+
column_name,
|
567
622
|
]
|
568
623
|
command = "set"
|
569
624
|
args = [[
|
570
|
-
new_value
|
625
|
+
new_value,
|
571
626
|
]]
|
572
627
|
|
573
628
|
{
|
@@ -575,11 +630,18 @@ module Utils
|
|
575
630
|
table: table,
|
576
631
|
path: path,
|
577
632
|
command: command,
|
578
|
-
args: args
|
633
|
+
args: args,
|
579
634
|
}
|
580
635
|
end
|
581
636
|
end
|
582
637
|
|
638
|
+
class SchemaTypeError < StandardError
|
639
|
+
def initialize(msg="Custom exception that is raised when an invalid property type is passed as a mapping.", exception_type="schema_type")
|
640
|
+
@exception_type = exception_type
|
641
|
+
super(msg)
|
642
|
+
end
|
643
|
+
end
|
644
|
+
|
583
645
|
def build_payload(operations, request_ids)
|
584
646
|
# ! properly formats the payload for Notions backend.
|
585
647
|
# ! operations -> an array of hashes that define the operations to perform : ``Array[Hash]``
|
@@ -600,4 +662,4 @@ module Utils
|
|
600
662
|
}
|
601
663
|
payload
|
602
664
|
end
|
603
|
-
end
|
665
|
+
end
|
data/lib/notion_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Murphy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|