notion_ruby_mapping 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -7
- data/env.yml.sample +1 -0
- data/lib/notion_ruby_mapping/base.rb +14 -10
- data/lib/notion_ruby_mapping/database.rb +6 -0
- data/lib/notion_ruby_mapping/list.rb +24 -19
- data/lib/notion_ruby_mapping/notion_cache.rb +11 -0
- data/lib/notion_ruby_mapping/page.rb +7 -1
- data/lib/notion_ruby_mapping/payload.rb +2 -2
- data/lib/notion_ruby_mapping/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: 00e3fdb4888f3e3c321215b91e3bb281e2b7683be35109f258b653febca4b697
|
4
|
+
data.tar.gz: 90ffb01da47b66c38b6bf0300b7e53f0302e7ce194ec35dba140a807b38e5239
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41ba458e34fc7f322c470e2a3a3a2b47cc091811267ed014066fc3eea5a9f29d99e48ce6d3e8e3a166cda06682612bd9429b42f2dea70c9072404fa66a76c311
|
7
|
+
data.tar.gz: 5f4205dd334fc5d31bf1e56f2e5ca4cc769feff7f3d5310e9b56c1b93658d837341786936eb1641f5f84cb3fc903c342a3a019cd340d39c837370be6e54d6a04
|
data/README.md
CHANGED
@@ -101,7 +101,11 @@ NotionCache.instance.create_client token
|
|
101
101
|
|
102
102
|
db = Database.new id: database_id
|
103
103
|
db.query_database.each do |page|
|
104
|
-
|
104
|
+
unless page.icon
|
105
|
+
page.set_icon(emoji: "💿")
|
106
|
+
page.save
|
107
|
+
p page.id
|
108
|
+
end
|
105
109
|
end
|
106
110
|
```
|
107
111
|
|
@@ -119,7 +123,7 @@ tp = db.properties["TextTitle"]
|
|
119
123
|
query = tp.filter_is_not_empty.ascending(tp)
|
120
124
|
db.query_database(tp.filter_is_not_empty.ascending(tp)).each.with_index(1) do |page, index|
|
121
125
|
page.properties["NumberTitle"].number = index
|
122
|
-
page.
|
126
|
+
page.save
|
123
127
|
end
|
124
128
|
```
|
125
129
|
|
@@ -138,7 +142,7 @@ page = Page.find page_id # API access
|
|
138
142
|
print page.title # -> ABC\nDEF
|
139
143
|
tp = page.properties["Title"]
|
140
144
|
tp[1].text = "GHI"
|
141
|
-
page.
|
145
|
+
page.save # API access
|
142
146
|
print page.title # -> ABC\nGHI
|
143
147
|
```
|
144
148
|
|
@@ -148,7 +152,7 @@ print page.title # -> ABC\nGHI
|
|
148
152
|
page = Page.new id: page_id, assign: [TitleProperty, "Title"]
|
149
153
|
tp = page.properties["Title"]
|
150
154
|
tp << TextObject.new("JKL")
|
151
|
-
page.
|
155
|
+
page.save # API access
|
152
156
|
print page.title # -> JKL
|
153
157
|
```
|
154
158
|
|
@@ -209,9 +213,10 @@ to.text = "ABC" # TextObject can set text by ".text="
|
|
209
213
|
# or tp[1].text = "ABC"
|
210
214
|
|
211
215
|
np.number = 3.14159
|
216
|
+
page.save # Notion API call
|
212
217
|
```
|
213
218
|
|
214
|
-
After update some properties, `page.
|
219
|
+
After update some properties, `page.save` method sends `Notion API` and replace the page information using the response of API.
|
215
220
|
|
216
221
|
```Ruby
|
217
222
|
page.update # Notion API call
|
@@ -221,19 +226,27 @@ page.update # Notion API call
|
|
221
226
|
|
222
227
|
`page.set_icon` can change the page icon using emoji or external url.
|
223
228
|
|
229
|
+
[Breaking change on v0.2.2] `page.set_icon` has no longer calling the Notion API.
|
230
|
+
Please use `page.save` after `page.set_icon` if you want to update or create the page.
|
231
|
+
|
224
232
|
```Ruby
|
225
233
|
# both methods call Notion API
|
226
234
|
obj.set_icon emoji: "💿" # set emoji
|
235
|
+
obj.save
|
236
|
+
|
227
237
|
obj.set_icon url: "https://cdn.profile-image.st-hatena.com/users/hkob/profile.png" # set external url
|
238
|
+
obj.save
|
228
239
|
```
|
229
240
|
|
230
241
|
#### 4.1.4 other methods
|
231
242
|
|
243
|
+
- `page.save` call Notion API, and so on and replace object information.
|
244
|
+
- `page.new_record?` returns true if the page was generated by `create_child_page`.
|
232
245
|
- `page.title` returns plain_text string of `Title`.
|
233
246
|
- `page.icon` returns JSON hash for the page icon.
|
234
247
|
- `page[key]` returns a hash or an array object except "properties".
|
235
248
|
|
236
|
-
### 4.2
|
249
|
+
### 4.2 Database
|
237
250
|
|
238
251
|
#### 4.2.1 Retrieve a database
|
239
252
|
|
@@ -532,7 +545,15 @@ query13 = tp.filter_starts_with("A").ascending(tp)
|
|
532
545
|
[{"property" => "tp", "direction" => "ascending"}]
|
533
546
|
```
|
534
547
|
|
535
|
-
#### 4.2.3
|
548
|
+
#### 4.2.3 Create child page
|
549
|
+
|
550
|
+
`create_child_page` creates a child page object of the database.
|
551
|
+
|
552
|
+
```Ruby
|
553
|
+
page = db.create_child_page TitleProperty, "Name"
|
554
|
+
```
|
555
|
+
|
556
|
+
#### 4.2.4 Update database
|
536
557
|
|
537
558
|
=== under construction ===
|
538
559
|
|
data/env.yml.sample
CHANGED
@@ -6,13 +6,14 @@ module NotionRubyMapping
|
|
6
6
|
# @param [Hash, nil] json
|
7
7
|
# @param [String, nil] id
|
8
8
|
# @param [Array<Property, Class, String>] assign
|
9
|
-
def initialize(json: nil, id: nil, assign: [])
|
9
|
+
def initialize(json: nil, id: nil, assign: [], parent: nil)
|
10
10
|
@nc = NotionCache.instance
|
11
11
|
@json = json
|
12
12
|
@id = @nc.hex_id(id || json && @json["id"])
|
13
|
-
|
13
|
+
@new_record = true unless parent.nil?
|
14
|
+
raise StandardError, "Unknown id" if !is_a?(List) && @id.nil? && parent.nil?
|
14
15
|
|
15
|
-
@payload =
|
16
|
+
@payload = Payload.new(parent && {"parent" => parent})
|
16
17
|
@property_cache = nil
|
17
18
|
assign.each_slice(2) { |(klass, key)| assign_property(klass, key) }
|
18
19
|
end
|
@@ -35,9 +36,8 @@ module NotionRubyMapping
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
@payload ||= Payload.new
|
39
|
+
def new_record?
|
40
|
+
@new_record
|
41
41
|
end
|
42
42
|
|
43
43
|
# @return [NotionRubyMapping::PropertyCache] get or created PropertyCache object
|
@@ -63,6 +63,11 @@ module NotionRubyMapping
|
|
63
63
|
update_json reload_json
|
64
64
|
self
|
65
65
|
end
|
66
|
+
|
67
|
+
# @return [NotionRubyMapping::Base]
|
68
|
+
def save
|
69
|
+
@new_record ? create : update
|
70
|
+
end
|
66
71
|
|
67
72
|
# @return [Hash] json properties
|
68
73
|
def json_properties
|
@@ -86,7 +91,7 @@ module NotionRubyMapping
|
|
86
91
|
end
|
87
92
|
|
88
93
|
def restore_from_json
|
89
|
-
payload.clear
|
94
|
+
@payload.clear
|
90
95
|
return if (ps = @json["properties"]).nil?
|
91
96
|
|
92
97
|
properties.json = json_properties
|
@@ -102,8 +107,7 @@ module NotionRubyMapping
|
|
102
107
|
# @return [NotionRubyMapping::Base]
|
103
108
|
def set_icon(emoji: nil, url: nil)
|
104
109
|
if is_a?(Page) || is_a?(Database)
|
105
|
-
payload.set_icon(emoji: emoji, url: url)
|
106
|
-
update
|
110
|
+
@payload.set_icon(emoji: emoji, url: url)
|
107
111
|
end
|
108
112
|
self
|
109
113
|
end
|
@@ -142,7 +146,7 @@ module NotionRubyMapping
|
|
142
146
|
|
143
147
|
# @return [Hash] created json
|
144
148
|
def property_values_json
|
145
|
-
payload.property_values_json @property_cache&.property_values_json
|
149
|
+
@payload.property_values_json @property_cache&.property_values_json
|
146
150
|
end
|
147
151
|
end
|
148
152
|
end
|
@@ -18,6 +18,12 @@ module NotionRubyMapping
|
|
18
18
|
update_json @nc.update_database_request(@id, property_values_json)
|
19
19
|
end
|
20
20
|
|
21
|
+
# @param [Array<Property, Class, String>] assign
|
22
|
+
# @return [NotionRubyMapping::Base]
|
23
|
+
def create_child_page(*assign)
|
24
|
+
Page.new assign: assign, parent: {"database_id" => @id}
|
25
|
+
end
|
26
|
+
|
21
27
|
protected
|
22
28
|
|
23
29
|
# @return [Hash]
|
@@ -8,6 +8,7 @@ module NotionRubyMapping
|
|
8
8
|
def initialize(json: nil, id: nil, database: nil, query: nil)
|
9
9
|
super(json: json, id: id)
|
10
10
|
@has_more = @json["has_more"]
|
11
|
+
@load_all_contents = !@has_more
|
11
12
|
@database = database
|
12
13
|
@query = query
|
13
14
|
@index = 0
|
@@ -18,30 +19,34 @@ module NotionRubyMapping
|
|
18
19
|
def each
|
19
20
|
return enum_for(:each) unless block_given?
|
20
21
|
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
|
25
|
-
@has_more = @json["has_more"]
|
26
|
-
@has_content = true
|
27
|
-
end
|
28
|
-
|
29
|
-
while @has_content
|
30
|
-
if @index < results.length
|
31
|
-
object = Base.create_from_json(results[@index])
|
32
|
-
@index += 1
|
33
|
-
yield object
|
34
|
-
elsif @has_more
|
35
|
-
if @database
|
36
|
-
@query.start_cursor = @json["next_cursor"]
|
22
|
+
if @database
|
23
|
+
unless @has_content # re-exec
|
24
|
+
unless @load_all_contents
|
25
|
+
@query.start_cursor = nil
|
37
26
|
@json = @database.query_database @query
|
38
|
-
@index = 0
|
39
27
|
@has_more = @json["has_more"]
|
28
|
+
end
|
29
|
+
@index = 0
|
30
|
+
@has_content = true
|
31
|
+
end
|
32
|
+
|
33
|
+
while @has_content
|
34
|
+
if @index < results.length
|
35
|
+
object = Base.create_from_json(results[@index])
|
36
|
+
@index += 1
|
37
|
+
yield object
|
38
|
+
elsif @has_more
|
39
|
+
if @database
|
40
|
+
@query.start_cursor = @json["next_cursor"]
|
41
|
+
@json = @database.query_database @query
|
42
|
+
@index = 0
|
43
|
+
@has_more = @json["has_more"]
|
44
|
+
else
|
45
|
+
@has_content = false
|
46
|
+
end
|
40
47
|
else
|
41
48
|
@has_content = false
|
42
49
|
end
|
43
|
-
else
|
44
|
-
@has_content = false
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
@@ -42,6 +42,11 @@ module NotionRubyMapping
|
|
42
42
|
"v1/pages/#{page_id}"
|
43
43
|
end
|
44
44
|
|
45
|
+
# @return [String (frozen)] page_path
|
46
|
+
def pages_path
|
47
|
+
"v1/pages"
|
48
|
+
end
|
49
|
+
|
45
50
|
# @param [String] database_id
|
46
51
|
# @return [String (frozen)] page_path
|
47
52
|
def database_path(database_id)
|
@@ -124,6 +129,12 @@ module NotionRubyMapping
|
|
124
129
|
request :patch, "v1/pages/#{page_id}", payload
|
125
130
|
end
|
126
131
|
|
132
|
+
# @param [Hash] payload
|
133
|
+
# @return [Hash] response
|
134
|
+
def create_page_request(payload)
|
135
|
+
request :post, "v1/pages", payload
|
136
|
+
end
|
137
|
+
|
127
138
|
# @param [String] id id string with "-"
|
128
139
|
# @return [String] id without "-"
|
129
140
|
def hex_id(id)
|
@@ -7,11 +7,17 @@ module NotionRubyMapping
|
|
7
7
|
NotionCache.instance.page id
|
8
8
|
end
|
9
9
|
|
10
|
-
# @return [NotionRubyMapping::Base]
|
10
|
+
# @return [NotionRubyMapping::Base]46G
|
11
11
|
def update
|
12
12
|
update_json @nc.update_page_request(@id, property_values_json)
|
13
13
|
end
|
14
14
|
|
15
|
+
# @return [NotionRubyMapping::Base]
|
16
|
+
def create
|
17
|
+
@new_record = false
|
18
|
+
update_json @nc.create_page_request(property_values_json)
|
19
|
+
end
|
20
|
+
|
15
21
|
protected
|
16
22
|
|
17
23
|
# @return [Hash]
|
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.2.
|
4
|
+
version: 0.2.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-03-
|
11
|
+
date: 2022-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|