notion_ruby_mapping 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +65 -6
- data/images/serial_number.png +0 -0
- data/lib/notion_ruby_mapping/base.rb +8 -2
- data/lib/notion_ruby_mapping/database.rb +6 -2
- data/lib/notion_ruby_mapping/multi_select_property.rb +20 -0
- data/lib/notion_ruby_mapping/notion_cache.rb +0 -1
- data/lib/notion_ruby_mapping/number_property.rb +7 -5
- data/lib/notion_ruby_mapping/page.rb +4 -6
- data/lib/notion_ruby_mapping/property.rb +13 -7
- data/lib/notion_ruby_mapping/select_property.rb +21 -1
- data/lib/notion_ruby_mapping/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53bd845c6d0535c221a3485dde1a005f31d86dfe668a3a61e64a9170cad88e77
|
4
|
+
data.tar.gz: 4523b7623a9bafaceac4264bdbc5a635cdd190558cf2079747922cf9644aa664
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9a372c98e531807eb7a954375ada24adaa3e1fbef57d6058483a7774517fb1bdbbe840bba72a301007750fcba6000d81d0504861513aafbac58b1c445d23518
|
7
|
+
data.tar.gz: fb95291c350bfe39d730360d1aa2ad38d1be92736e2f5f393423c3aabf3e6432552f6c4327c4a0f88d4ecd97129f0e78879d5e562f73d0d625c9836c5c52f9ce
|
data/README.md
CHANGED
@@ -58,6 +58,10 @@ Database.query(database_id).each do |page|
|
|
58
58
|
end
|
59
59
|
```
|
60
60
|
|
61
|
+
|Before execution|After execution|
|
62
|
+
|---|---|
|
63
|
+
|![Before execution](images/pre_set_icon.png)|![After execution](images/post_set_icon.png)|
|
64
|
+
|
61
65
|
The following code sets serial numbers to the pages whose title is not empty in ascending order of titles.
|
62
66
|
```Ruby
|
63
67
|
tp = RichTextProperty.new("TextTitle")
|
@@ -65,12 +69,10 @@ Database.query(database_id, tp.filter_is_not_empty.ascending(tp)).each.with_inde
|
|
65
69
|
page.properties["NumberTitle"].number = index
|
66
70
|
page.update
|
67
71
|
end
|
68
|
-
|
69
72
|
```
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|![Before execution](images/pre_set_icon.png)|![After execution](images/post_set_icon.png)|
|
73
|
+
| After execution |
|
74
|
+
|-----------------------------------------------|
|
75
|
+
| ![After exuecution](images/serial_number.png) |
|
74
76
|
|
75
77
|
## Usage
|
76
78
|
|
@@ -427,7 +429,7 @@ query12 = Query.new.ascending(tp).descending letp
|
|
427
429
|
query13 = tp.filter_starts_with("A").ascending(tp)
|
428
430
|
|
429
431
|
# Result of query13.filter
|
430
|
-
{"property" => "tp", "title" => {"starts_with" => "start"}}
|
432
|
+
{"property" => "tp", "title" => {"starts_with" => "start"}}
|
431
433
|
|
432
434
|
# Result of query13.sort
|
433
435
|
[{"property" => "tp", "direction" => "ascending"}]
|
@@ -487,8 +489,65 @@ end
|
|
487
489
|
|
488
490
|
Not implemented
|
489
491
|
|
492
|
+
#### NumberProperty class
|
493
|
+
|
494
|
+
- constructor
|
495
|
+
```Ruby
|
496
|
+
np = NumberProperty.new "np", number: 123
|
497
|
+
```
|
498
|
+
|
499
|
+
- set value
|
500
|
+
```Ruby
|
501
|
+
np.number = 456 # number <- 456 and will_update <- true
|
502
|
+
```
|
503
|
+
|
504
|
+
- create json
|
505
|
+
```Ruby
|
506
|
+
np.create_json # {"number" => 456}
|
507
|
+
```
|
508
|
+
|
509
|
+
#### SelectProperty class
|
510
|
+
|
511
|
+
- constructor
|
512
|
+
```Ruby
|
513
|
+
sp = SelectProperty.new "sp", select: "Select 1"
|
514
|
+
```
|
515
|
+
|
516
|
+
- set value
|
517
|
+
```Ruby
|
518
|
+
sp.select = "Select 2" # select <- "Select 2" and will_update <- true
|
519
|
+
```
|
520
|
+
|
521
|
+
- create json
|
522
|
+
```Ruby
|
523
|
+
sp.create_json # {"select" => {"name" => "Select 2"}}
|
524
|
+
```
|
525
|
+
|
526
|
+
#### MultiSelectProperty class
|
527
|
+
|
528
|
+
- constructor
|
529
|
+
```Ruby
|
530
|
+
msp1 = MultiSelectProperty.new "msp1", multi_select: "MS1" # Single value
|
531
|
+
msp2 = MultiSelectProperty.new "msp2", multi_select: %w[MS1 MS2] # Multi values
|
532
|
+
```
|
533
|
+
|
534
|
+
- set value
|
535
|
+
```Ruby
|
536
|
+
msp1.multi_select = %w[MS2 MS1] # multi_select <- ["MS1", "MS2"] and will_update <- true
|
537
|
+
msp2.select = "MS2" # multi_select <- "MS2" and will_update <- true
|
538
|
+
```
|
539
|
+
|
540
|
+
- create json
|
541
|
+
```Ruby
|
542
|
+
msp1.create_json # {"multi_select" => [{"name" => "MS2"}, {"name" => "MS1"}]}
|
543
|
+
msp2.create_json # {"multi_select" => [{"name" => "MS2"}]}
|
544
|
+
```
|
545
|
+
|
490
546
|
## ChangeLog
|
491
547
|
|
548
|
+
- 2022/2/20 add support for MultiSelectProperty
|
549
|
+
- 2022/2/19 add support for SelectProperty
|
550
|
+
- 2022/2/17 added Page#properties, Page#add_property_for_update, Page#update
|
492
551
|
- 2022/2/17 added Page#properties, Page#add_property_for_update, Page#update
|
493
552
|
- 2022/2/16 added PropertyCache and Payload class
|
494
553
|
- 2022/2/14 added Database#set_icon
|
Binary file
|
@@ -40,12 +40,18 @@ module NotionRubyMapping
|
|
40
40
|
unless @json
|
41
41
|
return nil if @id.nil?
|
42
42
|
|
43
|
-
|
43
|
+
reload
|
44
44
|
end
|
45
45
|
@property_cache = PropertyCache.new json_properties
|
46
46
|
end
|
47
47
|
@property_cache
|
48
|
-
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [NotionRubyMapping::Base] reloaded self
|
51
|
+
def reload
|
52
|
+
update_json reload_json
|
53
|
+
self
|
54
|
+
end
|
49
55
|
|
50
56
|
# @return [Hash] json properties
|
51
57
|
def json_properties
|
@@ -17,8 +17,12 @@ module NotionRubyMapping
|
|
17
17
|
# @param [String] id database_id (with or without "-")
|
18
18
|
# @param [Payload] payload
|
19
19
|
def update
|
20
|
-
update_json @nc.update_database
|
20
|
+
update_json @nc.update_database(@id, create_json)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Hash]
|
24
|
+
def reload_json
|
25
|
+
@nc.database_json @id
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
24
|
-
|
@@ -4,5 +4,25 @@ module NotionRubyMapping
|
|
4
4
|
# MultiSelect property
|
5
5
|
class MultiSelectProperty < MultiProperty
|
6
6
|
TYPE = "multi_select"
|
7
|
+
|
8
|
+
# @param [String] name
|
9
|
+
# @param [Hash] json
|
10
|
+
# @param [Array] multi_select
|
11
|
+
def initialize(name, json: nil, multi_select: nil)
|
12
|
+
super(name, json: json)
|
13
|
+
@multi_select = multi_select ? Array(multi_select) : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Hash] created json
|
17
|
+
def create_json
|
18
|
+
{"multi_select" => @multi_select ? (@multi_select.map { |v| {"name" => v} }) : @json} || {}
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param [Hash] multi_select
|
22
|
+
# @return [Array, nil] settled array
|
23
|
+
def multi_select=(multi_select)
|
24
|
+
@will_update = true
|
25
|
+
@multi_select = multi_select ? Array(multi_select) : nil
|
26
|
+
end
|
7
27
|
end
|
8
28
|
end
|
@@ -9,15 +9,17 @@ module NotionRubyMapping
|
|
9
9
|
TYPE = "number"
|
10
10
|
|
11
11
|
# @param [String] name Property name
|
12
|
-
# @param [
|
13
|
-
# @param [
|
14
|
-
def initialize(name, number: nil)
|
15
|
-
super(name)
|
12
|
+
# @param [Hash] json
|
13
|
+
# @param [Float] number Number value (optional)
|
14
|
+
def initialize(name, json: nil, number: nil)
|
15
|
+
super(name, json: json)
|
16
16
|
@number = number
|
17
17
|
end
|
18
|
+
attr_reader :number
|
18
19
|
|
20
|
+
# @return [Hash]
|
19
21
|
def create_json
|
20
|
-
{"
|
22
|
+
{"number" => @number || @json}
|
21
23
|
end
|
22
24
|
|
23
25
|
def number=(n)
|
@@ -3,18 +3,16 @@
|
|
3
3
|
module NotionRubyMapping
|
4
4
|
# Notion page object
|
5
5
|
class Page < Base
|
6
|
-
def self.find(
|
7
|
-
NotionCache.instance.page
|
6
|
+
def self.find(id)
|
7
|
+
NotionCache.instance.page id
|
8
8
|
end
|
9
9
|
|
10
|
-
# @param [String] id page_id (with or without "-")
|
11
|
-
# @param [Payload] payload
|
12
10
|
def update
|
13
11
|
update_json @nc.update_page(@id, create_json)
|
14
12
|
end
|
15
|
-
|
13
|
+
|
16
14
|
# @return [Hash]
|
17
|
-
def
|
15
|
+
def reload_json
|
18
16
|
@nc.page_json @id
|
19
17
|
end
|
20
18
|
end
|
@@ -4,10 +4,12 @@ module NotionRubyMapping
|
|
4
4
|
# abstract class for property
|
5
5
|
class Property
|
6
6
|
# @param [String] name Property name
|
7
|
+
# @param [Hash] json
|
7
8
|
# @return [Property] generated Property object
|
8
|
-
def initialize(name)
|
9
|
+
def initialize(name, json: nil)
|
9
10
|
@name = name
|
10
11
|
@will_update = false
|
12
|
+
@json = json
|
11
13
|
end
|
12
14
|
attr_reader :name
|
13
15
|
attr_accessor :will_update
|
@@ -25,12 +27,16 @@ module NotionRubyMapping
|
|
25
27
|
end
|
26
28
|
|
27
29
|
# @param [String] key
|
28
|
-
# @param [Hash]
|
29
|
-
# @return [NotionRubyMapping::
|
30
|
-
def self.create_from_json(key,
|
31
|
-
|
32
|
-
|
33
|
-
NumberProperty.new key,
|
30
|
+
# @param [Hash] input_json
|
31
|
+
# @return [NotionRubyMapping::Property, nil] generated Property object
|
32
|
+
def self.create_from_json(key, input_json)
|
33
|
+
keys = input_json.keys
|
34
|
+
if keys.include? "number"
|
35
|
+
NumberProperty.new key, json: input_json["number"]
|
36
|
+
elsif keys.include? "select"
|
37
|
+
SelectProperty.new key, json: input_json["select"]
|
38
|
+
elsif keys.include? "multi_select"
|
39
|
+
MultiSelectProperty.new key, json: input_json["multi_select"]
|
34
40
|
else
|
35
41
|
nil
|
36
42
|
end
|
@@ -6,5 +6,25 @@ module NotionRubyMapping
|
|
6
6
|
include EqualsDoesNotEqual
|
7
7
|
include IsEmptyIsNotEmpty
|
8
8
|
TYPE = "select"
|
9
|
+
|
10
|
+
# @param [String] name Property name
|
11
|
+
# @param [Hash] json
|
12
|
+
# @param [String] select String value (optional)
|
13
|
+
def initialize(name, json: nil, select: nil)
|
14
|
+
super(name, json: json)
|
15
|
+
@select = select
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Hash]
|
19
|
+
def create_json
|
20
|
+
{"select" => @select ? {"name" => @select} : @json} || {}
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param [String] select
|
24
|
+
# @return [String] settled value
|
25
|
+
def select=(select)
|
26
|
+
@will_update = true
|
27
|
+
@select = select
|
28
|
+
end
|
9
29
|
end
|
10
|
-
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion_ruby_mapping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki KOBAYASHI
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: notion-ruby-client
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- env.yml.sample
|
116
116
|
- images/post_set_icon.png
|
117
117
|
- images/pre_set_icon.png
|
118
|
+
- images/serial_number.png
|
118
119
|
- lib/notion_ruby_mapping.rb
|
119
120
|
- lib/notion_ruby_mapping/base.rb
|
120
121
|
- lib/notion_ruby_mapping/block.rb
|