notion_ruby_mapping 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -8
- data/lib/notion_ruby_mapping/base.rb +8 -3
- data/lib/notion_ruby_mapping/property.rb +2 -0
- 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: 30bf2ddaea8b93f043bee15eebc6ac4cd20af0717365ca6f1b51bbd2267f8484
|
4
|
+
data.tar.gz: 6a8914b322cbce8d5c86ee911cacb5980da56f1236856e7226a7b88b059674f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93a41accb8a2833fb6046cc01a283a93ac26aad3468334dafeafa95cce47d1ba87913d0f9b6b5180b3bc4b5674b51f506ffd5c84d7f34878fe828e464e654403
|
7
|
+
data.tar.gz: 325ca25b2820ae361149094f368a956581c50e9621b524051136b121636befb667af9434a1cb2da03889737130b9f8926bb746bd3c68f9804f5de088e66fb934
|
data/README.md
CHANGED
@@ -6,7 +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
|
-
- [
|
9
|
+
- [notion_ruby_mapping](#notion_ruby_mapping)
|
10
10
|
- [Table of Contents](#table-of-contents)
|
11
11
|
- [1. Installation](#1-installation)
|
12
12
|
- [2. Example code](#2-example-code)
|
@@ -31,6 +31,7 @@ Development note is here. → [Idea note of "notion_ruby_mapping"](https://www.n
|
|
31
31
|
- [4.2.6 Add a database property](#426-add-a-database-property)
|
32
32
|
- [4.2.7 Rename a database property](#427-rename-a-database-property)
|
33
33
|
- [4.2.8 Remove database properties](#428-remove-database-properties)
|
34
|
+
- [4.2.9 other methods](#429-other-methods)
|
34
35
|
- [4.3 List class](#43-list-class)
|
35
36
|
- [4.4 Block class](#44-block-class)
|
36
37
|
- [4.5 Property classes](#45-property-classes)
|
@@ -133,12 +134,13 @@ page = Page.find "c01166c6-13ae-45cb-b968-18b4ef2f5a77" # Notion API call
|
|
133
134
|
```
|
134
135
|
|
135
136
|
- result of dry run
|
137
|
+
|
136
138
|
```bash
|
137
139
|
#!/bin/sh
|
138
|
-
curl 'https://api.notion.com/v1/pages/c01166c6-13ae-45cb-b968-18b4ef2f5a77'\
|
139
|
-
-H 'Notion-Version: 2022-02-22'\
|
140
|
-
-H 'Authorization: Bearer '"$NOTION_API_KEY"''\
|
141
|
-
-H 'Content-Type: application/json'
|
140
|
+
curl 'https://api.notion.com/v1/pages/c01166c6-13ae-45cb-b968-18b4ef2f5a77' \
|
141
|
+
-H 'Notion-Version: 2022-02-22' \
|
142
|
+
-H 'Authorization: Bearer '"$NOTION_API_KEY"'' \
|
143
|
+
-H 'Content-Type: application/json'
|
142
144
|
```
|
143
145
|
|
144
146
|
`Page.new(id)` creates a Page object without the Notion API. Since Page.new does not acquire property information, so you need to assign yourself.
|
@@ -217,7 +219,7 @@ db = Database.find "c37a2c66-e3aa-4a0d-a447-73de3b80c253" # Notion API call
|
|
217
219
|
curl 'https://api.notion.com/v1/databases/c37a2c66-e3aa-4a0d-a447-73de3b80c253'\
|
218
220
|
-H 'Notion-Version: 2022-02-22'\
|
219
221
|
-H 'Authorization: Bearer '"$NOTION_API_KEY"''\
|
220
|
-
-H 'Content-Type: application/json'
|
222
|
+
-H 'Content-Type: application/json'
|
221
223
|
```
|
222
224
|
|
223
225
|
`Database.new(id)` creates a Database object without the Notion API. Since Database.new does not acquire property information, so you need to assign yourself.
|
@@ -522,7 +524,6 @@ print db.query_database query, dry_run: true
|
|
522
524
|
|
523
525
|
```
|
524
526
|
|
525
|
-
|
526
527
|
#### 4.2.3 Create child page
|
527
528
|
|
528
529
|
`create_child_page` creates a child page object of the database. After setting some properties, please call `page.save` to send page information to Notion.
|
@@ -534,6 +535,7 @@ page.save
|
|
534
535
|
```
|
535
536
|
|
536
537
|
- result of dry run
|
538
|
+
|
537
539
|
```bash
|
538
540
|
#!/bin/sh
|
539
541
|
curl -X POST 'https://api.notion.com/v1/pages'\
|
@@ -546,6 +548,7 @@ curl -X POST 'https://api.notion.com/v1/pages'\
|
|
546
548
|
#### 4.2.4 Create database
|
547
549
|
|
548
550
|
`create_child_database` method of an existing page creates a child database object. Some properties of the database can be arrange the option. Here is a sample script for creating a database that set all types of properties.
|
551
|
+
|
549
552
|
```Ruby
|
550
553
|
page = Page.find "a sample page id"
|
551
554
|
db = parent_page.create_child_database "New database title",
|
@@ -666,6 +669,19 @@ curl -X PATCH 'https://api.notion.com/v1/databases/c7697137d49f49c2bbcdd6a665c4f
|
|
666
669
|
--data '{"properties":{"renamed number property":null,"renamed url property":null}}'
|
667
670
|
```
|
668
671
|
|
672
|
+
#### 4.2.9 other methods
|
673
|
+
|
674
|
+
- `Database.find id, dry_run: true` create shell script for verification.
|
675
|
+
- `db.save` call Notion API, and so on and replace object information.
|
676
|
+
- `db.save dry_run: true` create shell script for verification.
|
677
|
+
- `db.new_record?` returns true if the database was generated by `create_child_database`.
|
678
|
+
- `db.database_title` returns plain_text string of `Database`.
|
679
|
+
- `db.title` returns plain_text string of `TitleProperty`.
|
680
|
+
- `db.icon` returns JSON hash for the page icon.
|
681
|
+
- `db[key]` returns a hash or an array object except "properties".
|
682
|
+
- `db.created_time` returns CreatedTimeProperty for filter
|
683
|
+
- `db.last_edited_time` returns LastEditedTimeProperty for filter
|
684
|
+
|
669
685
|
### 4.3 List class
|
670
686
|
|
671
687
|
`db.query_database` and other API list results returns a List object.
|
@@ -1016,7 +1032,6 @@ p rp.property_values_json
|
|
1016
1032
|
# Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R2"}, {"id"=>"R3"}]}}
|
1017
1033
|
```
|
1018
1034
|
|
1019
|
-
|
1020
1035
|
#### 4.5.4 create or update values for Database properties
|
1021
1036
|
|
1022
1037
|
Retrieving Database object with `find` method has database properties of XXXProperties with values. On the other hand, Assigned Database object has also XXXProperties, but they don't have any information for databases.
|
@@ -1046,6 +1061,7 @@ print sp.property_schema_json
|
|
1046
1061
|
```
|
1047
1062
|
|
1048
1063
|
If you want to edit existing values, you should access `edit_select_options` array. It sets `will_update` flag to true.
|
1064
|
+
|
1049
1065
|
```Ruby
|
1050
1066
|
sp.edit_select_options[0]["name"] = "new S1"
|
1051
1067
|
p sp.property_values_json
|
@@ -1064,6 +1080,7 @@ print msp.property_schema_json
|
|
1064
1080
|
```
|
1065
1081
|
|
1066
1082
|
If you want to edit existing values, you should access `edit_multi_select_options` array. It sets `will_update` flag to true.
|
1083
|
+
|
1067
1084
|
```Ruby
|
1068
1085
|
msp.edit_multi_select_options[0]["name"] = "new MS1"
|
1069
1086
|
p msp.property_values_json
|
@@ -41,7 +41,7 @@ module NotionRubyMapping
|
|
41
41
|
|
42
42
|
# @return [NotionRubyMapping::CreatedTimeProperty]
|
43
43
|
def created_time
|
44
|
-
@created_time ||= CreatedTimeProperty.new("
|
44
|
+
@created_time ||= CreatedTimeProperty.new("__timestamp__")
|
45
45
|
end
|
46
46
|
|
47
47
|
# @return [TrueClass, FalseClass] true if Database object
|
@@ -54,6 +54,11 @@ module NotionRubyMapping
|
|
54
54
|
self["icon"]
|
55
55
|
end
|
56
56
|
|
57
|
+
# @return [NotionRubyMapping::LastEditedTimeProperty]
|
58
|
+
def last_edited_time
|
59
|
+
@last_edited_time ||= LastEditedTimeProperty.new("__timestamp__")
|
60
|
+
end
|
61
|
+
|
57
62
|
# @return [Boolean] true if new record
|
58
63
|
def new_record?
|
59
64
|
@new_record
|
@@ -189,11 +194,11 @@ module NotionRubyMapping
|
|
189
194
|
shell = [
|
190
195
|
"#!/bin/sh\ncurl #{method == :get ? "" : "-X #{method.to_s.upcase}"} 'https://api.notion.com/#{path}'",
|
191
196
|
" -H 'Notion-Version: 2022-02-22'",
|
192
|
-
" -H 'Authorization: Bearer '\"$NOTION_API_KEY\"''"
|
197
|
+
" -H 'Authorization: Bearer '\"$NOTION_API_KEY\"''",
|
193
198
|
]
|
194
199
|
shell << " -H 'Content-Type: application/json'" unless path == :get
|
195
200
|
shell << " --data '#{JSON.generate json}'" if json
|
196
|
-
shell.join("
|
201
|
+
shell.join(" \\\n")
|
197
202
|
end
|
198
203
|
|
199
204
|
protected
|
@@ -91,6 +91,8 @@ module NotionRubyMapping
|
|
91
91
|
def make_filter_query(key, value, rollup = nil, rollup_type = nil)
|
92
92
|
if rollup
|
93
93
|
Query.new filter: {"property" => @name, rollup => {rollup_type => {key => value}}}
|
94
|
+
elsif @name == "__timestamp__"
|
95
|
+
Query.new filter: {"timestamp" => type, type => {key => value}}
|
94
96
|
else
|
95
97
|
Query.new filter: {"property" => @name, type => {key => value}}
|
96
98
|
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.3.
|
4
|
+
version: 0.3.1
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|