notion_ruby_mapping 0.2.0 → 0.2.3
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 +104 -26
- 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 -11
- data/lib/notion_ruby_mapping/mention_object.rb +26 -1
- 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/rich_text_object.rb +57 -1
- data/lib/notion_ruby_mapping/text_object.rb +0 -49
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/tools/an +103 -0
- 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: ab8de3fcc36d0cc0d489fdf31b50845e5c86aea51891067f4412733f605ac76e
|
4
|
+
data.tar.gz: 454a657be8a1acea1d14444bb811704c6183fb8e1fb624ad656fdbf403671031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3a86a3ee7cfd53eb58127b1a462a9f7b9ea97c57c6b0b1a7e0ea9ec72d1dde34ebd7759a18ad10c5f540be0cbdaa81c517924923fb502a9be68c62bcb587020
|
7
|
+
data.tar.gz: '009d50cc385fc9e462b1f475f647d93792501887db955f67a205a6d8a5397cb5f21752e0bcd0789e01d81c51374495135ad1dd101573d8dca4735c176e78cac1'
|
data/README.md
CHANGED
@@ -6,12 +6,7 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
|
|
6
6
|
|
7
7
|
## Table of Contents
|
8
8
|
|
9
|
-
|
10
|
-
<!-- @import "[TOC]" {cmd="toc" depthFrom=1 depthTo=6 orderedList=false} -->
|
11
|
-
|
12
|
-
<!-- code_chunk_output -->
|
13
|
-
|
14
|
-
- [notion\_ruby\_mapping](#notion_ruby_mapping)
|
9
|
+
- [notion_ruby_mapping](#notion_ruby_mapping)
|
15
10
|
- [Table of Contents](#table-of-contents)
|
16
11
|
- [1. Installation](#1-installation)
|
17
12
|
- [2. Example code](#2-example-code)
|
@@ -29,12 +24,13 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
|
|
29
24
|
- [4.1.2 Update page properties](#412-update-page-properties)
|
30
25
|
- [4.1.3 Update other page information](#413-update-other-page-information)
|
31
26
|
- [4.1.4 other methods](#414-other-methods)
|
32
|
-
- [4.2
|
27
|
+
- [4.2 Database](#42-database)
|
33
28
|
- [4.2.1 Retrieve a database](#421-retrieve-a-database)
|
34
29
|
- [4.2.2 Query a database](#422-query-a-database)
|
35
30
|
- [4.2.2.1 Complex conditions](#4221-complex-conditions)
|
36
31
|
- [4.2.2.2 Sort criteria](#4222-sort-criteria)
|
37
|
-
- [4.2.3
|
32
|
+
- [4.2.3 Create child page](#423-create-child-page)
|
33
|
+
- [4.2.4 Update database](#424-update-database)
|
38
34
|
- [4.3 List class](#43-list-class)
|
39
35
|
- [4.4 Block class](#44-block-class)
|
40
36
|
- [4.5 Property classes](#45-property-classes)
|
@@ -54,14 +50,16 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
|
|
54
50
|
- [4.5.3.10 EmailProperty](#45310-emailproperty)
|
55
51
|
- [4.5.3.11 FilesProperty](#45311-filesproperty)
|
56
52
|
- [4.5.3.12 RelationProperty](#45312-relationproperty)
|
53
|
+
- [5. XXXObjects](#5-xxxobjects)
|
54
|
+
- [5.1 RichTextObject](#51-richtextobject)
|
55
|
+
- [5.2 TextObject](#52-textobject)
|
56
|
+
- [5.3 MentionObject](#53-mentionobject)
|
57
|
+
- [5.4 UserObject](#54-userobject)
|
57
58
|
- [6. ChangeLog](#6-changelog)
|
58
|
-
- [
|
59
|
-
- [
|
60
|
-
- [
|
61
|
-
- [
|
62
|
-
|
63
|
-
<!-- /code_chunk_output -->
|
64
|
-
|
59
|
+
- [7. Contributing](#7-contributing)
|
60
|
+
- [8. License](#8-license)
|
61
|
+
- [9. Code of Conduct](#9-code-of-conduct)
|
62
|
+
- [10. Acknowledgements](#10-acknowledgements)
|
65
63
|
|
66
64
|
## 1. Installation
|
67
65
|
|
@@ -101,7 +99,11 @@ NotionCache.instance.create_client token
|
|
101
99
|
|
102
100
|
db = Database.new id: database_id
|
103
101
|
db.query_database.each do |page|
|
104
|
-
|
102
|
+
unless page.icon
|
103
|
+
page.set_icon(emoji: "💿")
|
104
|
+
page.save
|
105
|
+
p page.id
|
106
|
+
end
|
105
107
|
end
|
106
108
|
```
|
107
109
|
|
@@ -119,7 +121,7 @@ tp = db.properties["TextTitle"]
|
|
119
121
|
query = tp.filter_is_not_empty.ascending(tp)
|
120
122
|
db.query_database(tp.filter_is_not_empty.ascending(tp)).each.with_index(1) do |page, index|
|
121
123
|
page.properties["NumberTitle"].number = index
|
122
|
-
page.
|
124
|
+
page.save
|
123
125
|
end
|
124
126
|
```
|
125
127
|
|
@@ -138,7 +140,7 @@ page = Page.find page_id # API access
|
|
138
140
|
print page.title # -> ABC\nDEF
|
139
141
|
tp = page.properties["Title"]
|
140
142
|
tp[1].text = "GHI"
|
141
|
-
page.
|
143
|
+
page.save # API access
|
142
144
|
print page.title # -> ABC\nGHI
|
143
145
|
```
|
144
146
|
|
@@ -148,7 +150,7 @@ print page.title # -> ABC\nGHI
|
|
148
150
|
page = Page.new id: page_id, assign: [TitleProperty, "Title"]
|
149
151
|
tp = page.properties["Title"]
|
150
152
|
tp << TextObject.new("JKL")
|
151
|
-
page.
|
153
|
+
page.save # API access
|
152
154
|
print page.title # -> JKL
|
153
155
|
```
|
154
156
|
|
@@ -209,9 +211,10 @@ to.text = "ABC" # TextObject can set text by ".text="
|
|
209
211
|
# or tp[1].text = "ABC"
|
210
212
|
|
211
213
|
np.number = 3.14159
|
214
|
+
page.save # Notion API call
|
212
215
|
```
|
213
216
|
|
214
|
-
After update some properties, `page.
|
217
|
+
After update some properties, `page.save` method sends `Notion API` and replace the page information using the response of API.
|
215
218
|
|
216
219
|
```Ruby
|
217
220
|
page.update # Notion API call
|
@@ -221,19 +224,27 @@ page.update # Notion API call
|
|
221
224
|
|
222
225
|
`page.set_icon` can change the page icon using emoji or external url.
|
223
226
|
|
227
|
+
[Breaking change on v0.2.2] `page.set_icon` has no longer calling the Notion API.
|
228
|
+
Please use `page.save` after `page.set_icon` if you want to update or create the page.
|
229
|
+
|
224
230
|
```Ruby
|
225
231
|
# both methods call Notion API
|
226
232
|
obj.set_icon emoji: "💿" # set emoji
|
233
|
+
obj.save
|
234
|
+
|
227
235
|
obj.set_icon url: "https://cdn.profile-image.st-hatena.com/users/hkob/profile.png" # set external url
|
236
|
+
obj.save
|
228
237
|
```
|
229
238
|
|
230
239
|
#### 4.1.4 other methods
|
231
240
|
|
241
|
+
- `page.save` call Notion API, and so on and replace object information.
|
242
|
+
- `page.new_record?` returns true if the page was generated by `create_child_page`.
|
232
243
|
- `page.title` returns plain_text string of `Title`.
|
233
244
|
- `page.icon` returns JSON hash for the page icon.
|
234
245
|
- `page[key]` returns a hash or an array object except "properties".
|
235
246
|
|
236
|
-
### 4.2
|
247
|
+
### 4.2 Database
|
237
248
|
|
238
249
|
#### 4.2.1 Retrieve a database
|
239
250
|
|
@@ -532,7 +543,18 @@ query13 = tp.filter_starts_with("A").ascending(tp)
|
|
532
543
|
[{"property" => "tp", "direction" => "ascending"}]
|
533
544
|
```
|
534
545
|
|
535
|
-
#### 4.2.3
|
546
|
+
#### 4.2.3 Create child page
|
547
|
+
|
548
|
+
`create_child_page` creates a child page object of the database.
|
549
|
+
After setting some properties, please call `page.save` to send page information to Notion.
|
550
|
+
|
551
|
+
```Ruby
|
552
|
+
page = db.create_child_page TitleProperty, "Name"
|
553
|
+
page.properties["Name"] << "New Page"
|
554
|
+
page.save
|
555
|
+
```
|
556
|
+
|
557
|
+
#### 4.2.4 Update database
|
536
558
|
|
537
559
|
=== under construction ===
|
538
560
|
|
@@ -822,6 +844,7 @@ p tp.property_values_json
|
|
822
844
|
```
|
823
845
|
|
824
846
|
`<<` method appends a new TextObject or a String.
|
847
|
+
|
825
848
|
```Ruby
|
826
849
|
to = TextObject.new "DEF"
|
827
850
|
to.bold = true
|
@@ -836,6 +859,7 @@ p tp.property_values_json
|
|
836
859
|
```
|
837
860
|
|
838
861
|
`delete_at(index)` method remove a TextObject at index.
|
862
|
+
|
839
863
|
```Ruby
|
840
864
|
tp.delete_at 1
|
841
865
|
tp << "GHI"
|
@@ -846,6 +870,7 @@ p tp.property_values_json
|
|
846
870
|
##### 4.5.3.9 CheckboxProperty
|
847
871
|
|
848
872
|
PeopleProperty can set a boolean value by `.checkbox=`.
|
873
|
+
|
849
874
|
```Ruby
|
850
875
|
cp = page.properties["CheckboxTitle"]
|
851
876
|
cp.checkbox = true
|
@@ -856,6 +881,7 @@ p cp.property_values_json
|
|
856
881
|
##### 4.5.3.10 EmailProperty
|
857
882
|
|
858
883
|
EmailProperty can set an email address by `.email=`.
|
884
|
+
|
859
885
|
```Ruby
|
860
886
|
ep = page.properties["MailTitle"]
|
861
887
|
ep.email = "hkobhkob@gmail.com"
|
@@ -893,9 +919,61 @@ p rp.property_values_json
|
|
893
919
|
# Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R2"}, {"id"=>"R3"}]}}
|
894
920
|
```
|
895
921
|
|
922
|
+
## 5. XXXObjects
|
923
|
+
|
924
|
+
### 5.1 RichTextObject
|
925
|
+
|
926
|
+
RichTextObject is an abstract class for TextObject and MentionObject.
|
927
|
+
It can store a link and some annotations.
|
928
|
+
|
929
|
+
There are common instance methods for its subclass objects.
|
930
|
+
|
931
|
+
- plain_text=(value)
|
932
|
+
- bold=(flag)
|
933
|
+
- italic=(flag)
|
934
|
+
- strikethrough=(flag)
|
935
|
+
- underline=(flag)
|
936
|
+
- code=(flag)
|
937
|
+
- color=(color)
|
938
|
+
|
939
|
+
### 5.2 TextObject
|
940
|
+
|
941
|
+
TextObject is a class for texts.
|
942
|
+
`TextObject.new(text)` creates a TextObject.
|
943
|
+
After creating or retrieving TextObject, `to.text=` replaces including text.
|
944
|
+
|
945
|
+
```Ruby
|
946
|
+
to = TextObject.new "first text"
|
947
|
+
to.text = "replaced text"
|
948
|
+
```
|
949
|
+
|
950
|
+
### 5.3 MentionObject
|
951
|
+
|
952
|
+
MentionObject is a class for mentions for user, page, database, date and template_mention.
|
953
|
+
|
954
|
+
```Ruby
|
955
|
+
mention_user = MentionObject.new user_id: "user_id", plain_text: "m_user"
|
956
|
+
mention_page = MentionObject.new page_id: "page_id", plain_text: "m_page"
|
957
|
+
mention_db = MentionObject.new database_id: "database_id", plain_text: "m_db"
|
958
|
+
mention_date = MentionObject.new start: "2022-03-17", plain_text: "m_date"
|
959
|
+
mention_today = MentionObject.new mention_template: "today"
|
960
|
+
mention_now = MentionObject.new mention_template: "now"
|
961
|
+
mention_user = MentionObject.new mention_template: "user"
|
962
|
+
```
|
963
|
+
|
964
|
+
### 5.4 UserObject
|
965
|
+
|
966
|
+
UserObject is a class for users.
|
967
|
+
|
968
|
+
```Ruby
|
969
|
+
u = User.new id: "user_id"
|
970
|
+
```
|
896
971
|
|
897
972
|
## 6. ChangeLog
|
898
973
|
|
974
|
+
- 2022/3/17 added template_mention objects, tools/an command
|
975
|
+
- 2022/3/16 added database.create_child_page and base.save instead of base.update/create
|
976
|
+
- 2022/3/15 Fixed not to reload from API when all contents are loaded
|
899
977
|
- 2022/3/14 Exclude notion-ruby-client, update Property values, update for Notion-Version 2022-02-22
|
900
978
|
- 2022/2/25 add_property_for_update -> assign_property, update README.md
|
901
979
|
- 2022/2/20 add support for MultiSelectProperty
|
@@ -907,18 +985,18 @@ p rp.property_values_json
|
|
907
985
|
- 2022/2/13 added Page#set_icon
|
908
986
|
- 2022/2/13 First commit
|
909
987
|
|
910
|
-
##
|
988
|
+
## 7. Contributing
|
911
989
|
|
912
990
|
Bug reports and pull requests are welcome on GitHub at <https://github.com/hkob/notion_ruby_mapping>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
|
913
991
|
|
914
|
-
##
|
992
|
+
## 8. License
|
915
993
|
|
916
994
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
917
995
|
|
918
|
-
##
|
996
|
+
## 9. Code of Conduct
|
919
997
|
|
920
998
|
Everyone interacting in the NotionRubyMapping project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/notion_ruby_mapping/blob/main/CODE_OF_CONDUCT.md).
|
921
999
|
|
922
|
-
##
|
1000
|
+
## 10. Acknowledgements
|
923
1001
|
|
924
1002
|
The code depends on [notion-ruby-client](https://github.com/orbit-love/notion-ruby-client).
|
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,22 +19,34 @@ module NotionRubyMapping
|
|
18
19
|
def each
|
19
20
|
return enum_for(:each) unless block_given?
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
yield object
|
26
|
-
elsif @has_more
|
27
|
-
if @database
|
28
|
-
@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
|
29
26
|
@json = @database.query_database @query
|
30
|
-
@index = 0
|
31
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
|
32
47
|
else
|
33
48
|
@has_content = false
|
34
49
|
end
|
35
|
-
else
|
36
|
-
@has_content = false
|
37
50
|
end
|
38
51
|
end
|
39
52
|
end
|
@@ -41,8 +41,33 @@ module NotionRubyMapping
|
|
41
41
|
"type" => "date",
|
42
42
|
"date" => @options.slice("start", "end", "time_zone"),
|
43
43
|
}
|
44
|
+
elsif @options.key? "template_mention"
|
45
|
+
sub = case @options["template_mention"]
|
46
|
+
when "today"
|
47
|
+
@options["plain_text"] = "@Today"
|
48
|
+
{
|
49
|
+
"type" => "template_mention_date",
|
50
|
+
"template_mention_date" => "today",
|
51
|
+
}
|
52
|
+
when "now"
|
53
|
+
@options["plain_text"] = "@Now"
|
54
|
+
{
|
55
|
+
"type" => "template_mention_date",
|
56
|
+
"template_mention_date" => "now",
|
57
|
+
}
|
58
|
+
else
|
59
|
+
@options["plain_text"] = "@Me"
|
60
|
+
{
|
61
|
+
"type" => "template_mention_user",
|
62
|
+
"template_mention_user" => "me",
|
63
|
+
}
|
64
|
+
end
|
65
|
+
{
|
66
|
+
"type" => "template_mention",
|
67
|
+
"template_mention" => sub,
|
68
|
+
}
|
44
69
|
else
|
45
|
-
raise StandardError, "Irregular mention type"
|
70
|
+
raise StandardError, "Irregular mention type: #{@options.keys}"
|
46
71
|
end
|
47
72
|
end
|
48
73
|
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]
|
@@ -32,8 +32,16 @@ module NotionRubyMapping
|
|
32
32
|
MentionObject.new options.merge({"database_id" => mention["database"]["id"]})
|
33
33
|
when "date"
|
34
34
|
MentionObject.new options.merge(mention["date"].slice("start", "end", "time_zone"))
|
35
|
+
when "template_mention"
|
36
|
+
template_mention = mention["template_mention"]
|
37
|
+
case template_mention["type"]
|
38
|
+
when "template_mention_date"
|
39
|
+
MentionObject.new options.merge({"template_mention" => template_mention["template_mention_date"]})
|
40
|
+
else
|
41
|
+
MentionObject.new options.merge({"template_mention" => template_mention["template_mention_user"]})
|
42
|
+
end
|
35
43
|
else
|
36
|
-
raise StandardError,
|
44
|
+
raise StandardError, "Unknown mention type: #{mention["type"]}"
|
37
45
|
end
|
38
46
|
else
|
39
47
|
raise StandardError, json
|
@@ -60,6 +68,54 @@ module NotionRubyMapping
|
|
60
68
|
}.merge annotations_json
|
61
69
|
end
|
62
70
|
|
71
|
+
# @param [String, RichTextObject] value
|
72
|
+
# @return [String] input text
|
73
|
+
def plain_text=(value)
|
74
|
+
text(value)
|
75
|
+
end
|
76
|
+
|
77
|
+
# @param [Boolean] flag
|
78
|
+
# @return [Boolean] input flag
|
79
|
+
def bold=(flag)
|
80
|
+
@will_update = true
|
81
|
+
@options["bold"] = flag
|
82
|
+
end
|
83
|
+
|
84
|
+
# @param [Boolean] flag
|
85
|
+
# @return [Boolean] input flag
|
86
|
+
def italic=(flag)
|
87
|
+
@will_update = true
|
88
|
+
@options["italic"] = flag
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param [Boolean] flag
|
92
|
+
# @return [Boolean] input flag
|
93
|
+
def strikethrough=(flag)
|
94
|
+
@will_update = true
|
95
|
+
@options["strikethrough"] = flag
|
96
|
+
end
|
97
|
+
|
98
|
+
# @param [Boolean] flag
|
99
|
+
# @return [Boolean] input flag
|
100
|
+
def underline=(flag)
|
101
|
+
@will_update = true
|
102
|
+
@options["underline"] = flag
|
103
|
+
end
|
104
|
+
|
105
|
+
# @param [Boolean] flag
|
106
|
+
# @return [Boolean] input flag
|
107
|
+
def code=(flag)
|
108
|
+
@will_update = true
|
109
|
+
@options["code"] = flag
|
110
|
+
end
|
111
|
+
|
112
|
+
# @param [String] color
|
113
|
+
# @return [String] input color
|
114
|
+
def color=(color)
|
115
|
+
@will_update = true
|
116
|
+
@options["color"] = color
|
117
|
+
end
|
118
|
+
|
63
119
|
protected
|
64
120
|
|
65
121
|
# @return [Hash] options
|
@@ -21,61 +21,12 @@ module NotionRubyMapping
|
|
21
21
|
@options = value.options
|
22
22
|
@text = value.text
|
23
23
|
else
|
24
|
-
p value
|
25
24
|
@text = value
|
26
25
|
@options["plain_text"] = value
|
27
26
|
end
|
28
27
|
self
|
29
28
|
end
|
30
29
|
|
31
|
-
# @param [String, RichTextObject] value
|
32
|
-
# @return [String] input text
|
33
|
-
def plain_text=(value)
|
34
|
-
text(value)
|
35
|
-
end
|
36
|
-
|
37
|
-
# @param [Boolean] flag
|
38
|
-
# @return [Boolean] input flag
|
39
|
-
def bold=(flag)
|
40
|
-
@will_update = true
|
41
|
-
@options["bold"] = flag
|
42
|
-
end
|
43
|
-
|
44
|
-
# @param [Boolean] flag
|
45
|
-
# @return [Boolean] input flag
|
46
|
-
def italic=(flag)
|
47
|
-
@will_update = true
|
48
|
-
@options["italic"] = flag
|
49
|
-
end
|
50
|
-
|
51
|
-
# @param [Boolean] flag
|
52
|
-
# @return [Boolean] input flag
|
53
|
-
def strikethrough=(flag)
|
54
|
-
@will_update = true
|
55
|
-
@options["strikethrough"] = flag
|
56
|
-
end
|
57
|
-
|
58
|
-
# @param [Boolean] flag
|
59
|
-
# @return [Boolean] input flag
|
60
|
-
def underline=(flag)
|
61
|
-
@will_update = true
|
62
|
-
@options["underline"] = flag
|
63
|
-
end
|
64
|
-
|
65
|
-
# @param [Boolean] flag
|
66
|
-
# @return [Boolean] input flag
|
67
|
-
def code=(flag)
|
68
|
-
@will_update = true
|
69
|
-
@options["code"] = flag
|
70
|
-
end
|
71
|
-
|
72
|
-
# @param [String] color
|
73
|
-
# @return [String] input color
|
74
|
-
def color=(color)
|
75
|
-
@will_update = true
|
76
|
-
@options["color"] = color
|
77
|
-
end
|
78
|
-
|
79
30
|
protected
|
80
31
|
|
81
32
|
def partial_property_values_json
|
data/tools/an
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "date"
|
5
|
+
require "notion_ruby_mapping"
|
6
|
+
|
7
|
+
module NotionRubyMapping
|
8
|
+
# you Notion API token
|
9
|
+
NOTION_API_TOKEN = "secret_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx"
|
10
|
+
# your task Database id
|
11
|
+
DATABASE_ID = "0123456789abcdef0123456789abcdef"
|
12
|
+
# your Title name
|
13
|
+
TITLE_NAME = "タスク名"
|
14
|
+
# your DateProperty name
|
15
|
+
DATE_NAME = "日付"
|
16
|
+
# your time_zone
|
17
|
+
TIME_ZONE = "Asia/Tokyo"
|
18
|
+
# set true if you want to open the created page in the Notion.app
|
19
|
+
OPEN_AS_APP = true
|
20
|
+
|
21
|
+
# print usage and exit
|
22
|
+
def usage
|
23
|
+
print [
|
24
|
+
"Usage:",
|
25
|
+
"\tan task-name",
|
26
|
+
"\t\tCreate a today task as 'task-name'",
|
27
|
+
"\tan task-name hh:mm",
|
28
|
+
"\t\tCreate a today 'task-name' task at 'hh:mm'",
|
29
|
+
"\tan task-name MM/DD",
|
30
|
+
"\t\tInput a 'task-name' task at 'MM/DD'",
|
31
|
+
"\tan task-name YYYY/MM/DD",
|
32
|
+
"\t\tInput a 'task-name' task at 'YYYY/MM/DD'",
|
33
|
+
"\tan task-name MM/DD hh:mm",
|
34
|
+
"\t\tInput a 'task-name' task at 'MM/DD hh:mm",
|
35
|
+
"\tan task-name MM/DD h1:m1 h2:m2",
|
36
|
+
"\t\tInput a 'task-name' task at 'MM/DD h1:m1 - h2:m2'",
|
37
|
+
"\tan task-name YYYY/MM/DD hh:mm",
|
38
|
+
"\t\tInput a 'task-name' task at 'YYYY/MM/DD hh:mm",
|
39
|
+
"\tan task-name YYYY/MM/DD h1:m1 h2:m2",
|
40
|
+
"\t\tInput a 'task-name' task at 'YYYY/MM/DD h1:m1 - h2:m2'",
|
41
|
+
].join("\n")
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
|
45
|
+
if ARGV.empty?
|
46
|
+
usage
|
47
|
+
else
|
48
|
+
date_str = nil
|
49
|
+
end_time = nil
|
50
|
+
start_time = nil
|
51
|
+
|
52
|
+
# check start_time and end_time
|
53
|
+
end_time = ARGV.pop if ARGV[-1] =~ /\d+:\d+/
|
54
|
+
if end_time
|
55
|
+
start_time = ARGV.pop if ARGV[-1] =~ /\d+:\d+/
|
56
|
+
unless start_time
|
57
|
+
start_time = end_time
|
58
|
+
end_time = nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# set date from date string or today
|
63
|
+
begin
|
64
|
+
date = Date.parse ARGV[-1]
|
65
|
+
# If the above Date.parse was success, the last parameter will remove.
|
66
|
+
date_str = ARGV.pop
|
67
|
+
rescue StandardError
|
68
|
+
date = nil
|
69
|
+
end
|
70
|
+
date ||= Date.today
|
71
|
+
|
72
|
+
# if task name does not exist, print usage and exit
|
73
|
+
if ARGV.empty?
|
74
|
+
print "`task-name' is required!!!"
|
75
|
+
usage
|
76
|
+
end
|
77
|
+
|
78
|
+
NotionCache.instance.create_client NOTION_API_TOKEN
|
79
|
+
|
80
|
+
# create database object without API call and create a child page
|
81
|
+
db = Database.new id: DATABASE_ID
|
82
|
+
page = db.create_child_page TitleProperty, TITLE_NAME, DateProperty, DATE_NAME
|
83
|
+
|
84
|
+
# obtain title and date properties and set values
|
85
|
+
tp, dp = page.properties.values_at TITLE_NAME, DATE_NAME
|
86
|
+
tp << ARGV.join(" ")
|
87
|
+
if end_time
|
88
|
+
dp.start_date = DateTime.parse "#{date_str} #{start_time}"
|
89
|
+
dp.end_date = DateTime.parse "#{date_str} #{end_time}"
|
90
|
+
dp.time_zone = TIME_ZONE
|
91
|
+
elsif start_time
|
92
|
+
dp.start_date = DateTime.parse "#{date_str} #{start_time}"
|
93
|
+
dp.time_zone = TIME_ZONE
|
94
|
+
else
|
95
|
+
dp.start_date = date
|
96
|
+
end
|
97
|
+
|
98
|
+
# Notion API call
|
99
|
+
page.save
|
100
|
+
url = "#{OPEN_AS_APP ? "notion" : "https"}://notion.so/#{page.id}"
|
101
|
+
system("open #{url}")
|
102
|
+
end
|
103
|
+
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.2.
|
4
|
+
version: 0.2.3
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/notion_ruby_mapping/version.rb
|
185
185
|
- notion_ruby_mapping.gemspec
|
186
186
|
- sig/notion_ruby_mapping.rbs
|
187
|
+
- tools/an
|
187
188
|
homepage: https://github.com/hkob/notion_ruby_mapping.git
|
188
189
|
licenses:
|
189
190
|
- MIT
|