notion_ruby_mapping 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +500 -141
- data/env.yml.sample +2 -0
- data/examples/change_title.md +26 -0
- data/examples/renumbering_pages.md +20 -0
- data/examples/set_icon_to_all_icon_unsettled_pages.md +30 -0
- data/lib/notion_ruby_mapping/base.rb +130 -73
- data/lib/notion_ruby_mapping/checkbox_property.rb +27 -12
- data/lib/notion_ruby_mapping/created_by_property.rb +22 -10
- data/lib/notion_ruby_mapping/created_time_property.rb +16 -14
- data/lib/notion_ruby_mapping/database.rb +78 -8
- data/lib/notion_ruby_mapping/date_property.rb +67 -42
- data/lib/notion_ruby_mapping/email_property.rb +26 -16
- data/lib/notion_ruby_mapping/files_property.rb +40 -24
- data/lib/notion_ruby_mapping/formula_property.rb +51 -10
- data/lib/notion_ruby_mapping/last_edited_by_property.rb +22 -9
- data/lib/notion_ruby_mapping/last_edited_time_property.rb +16 -14
- data/lib/notion_ruby_mapping/list.rb +27 -19
- data/lib/notion_ruby_mapping/mention_object.rb +26 -1
- data/lib/notion_ruby_mapping/multi_select_property.rb +83 -21
- data/lib/notion_ruby_mapping/notion_cache.rb +25 -10
- data/lib/notion_ruby_mapping/number_property.rb +71 -10
- data/lib/notion_ruby_mapping/page.rb +33 -5
- data/lib/notion_ruby_mapping/payload.rb +23 -5
- data/lib/notion_ruby_mapping/people_property.rb +47 -19
- data/lib/notion_ruby_mapping/phone_number_property.rb +26 -15
- data/lib/notion_ruby_mapping/property.rb +140 -49
- data/lib/notion_ruby_mapping/property_cache.rb +31 -3
- data/lib/notion_ruby_mapping/query.rb +10 -0
- data/lib/notion_ruby_mapping/relation_property.rb +74 -21
- data/lib/notion_ruby_mapping/rich_text_array.rb +81 -0
- data/lib/notion_ruby_mapping/rich_text_object.rb +58 -1
- data/lib/notion_ruby_mapping/rich_text_property.rb +12 -1
- data/lib/notion_ruby_mapping/rollup_property.rb +82 -10
- data/lib/notion_ruby_mapping/select_property.rb +88 -13
- data/lib/notion_ruby_mapping/text_object.rb +0 -51
- data/lib/notion_ruby_mapping/text_property.rb +19 -45
- data/lib/notion_ruby_mapping/title_property.rb +12 -1
- data/lib/notion_ruby_mapping/url_property.rb +26 -15
- data/lib/notion_ruby_mapping/user_object.rb +4 -4
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/lib/notion_ruby_mapping.rb +2 -1
- data/tools/an +103 -0
- metadata +7 -2
@@ -12,61 +12,35 @@ module NotionRubyMapping
|
|
12
12
|
include StartsWithEndsWith
|
13
13
|
include IsEmptyIsNotEmpty
|
14
14
|
|
15
|
+
### Public announced methods
|
16
|
+
|
17
|
+
## Page property only methods
|
18
|
+
|
19
|
+
attr_reader :text_objects
|
20
|
+
|
21
|
+
def_delegators :@text_objects, :[], :<<, :each, :full_text, :delete_at
|
22
|
+
|
23
|
+
### Not public announced methods
|
24
|
+
|
25
|
+
## Common methods
|
26
|
+
|
15
27
|
# @param [String] name
|
16
|
-
# @param [Hash] json
|
28
|
+
# @param [Hash, Array] json
|
17
29
|
# @param [Array<RichTextObject>] text_objects
|
18
|
-
def initialize(name, will_update: false, json: nil, text_objects: nil)
|
30
|
+
def initialize(name, will_update: false, base_type: :page, json: nil, text_objects: nil)
|
19
31
|
raise StandardError, "TextObject is abstract class. Please use RichTextProperty." if instance_of? TextProperty
|
20
32
|
|
21
|
-
super name, will_update: will_update
|
22
|
-
@text_objects = if
|
23
|
-
|
24
|
-
elsif json
|
25
|
-
json.map { |to| RichTextObject.create_from_json to }
|
33
|
+
super name, will_update: will_update, base_type: base_type
|
34
|
+
@text_objects = if database?
|
35
|
+
json || {}
|
26
36
|
else
|
27
|
-
|
37
|
+
RichTextArray.new "title", json: json, text_objects: text_objects
|
28
38
|
end
|
29
39
|
end
|
30
|
-
attr_reader :text_objects
|
31
40
|
|
32
41
|
# @return [TrueClass, FalseClass] will update?
|
33
42
|
def will_update
|
34
|
-
@will_update || @text_objects.
|
35
|
-
end
|
36
|
-
|
37
|
-
# @param [Proc] block
|
38
|
-
# @return [Enumerator]
|
39
|
-
def each(&block)
|
40
|
-
return enum_for(:each) unless block
|
41
|
-
|
42
|
-
@text_objects.each(&block)
|
43
|
-
end
|
44
|
-
|
45
|
-
# @param [String, RichTextObject] to
|
46
|
-
# @return [NotionRubyMapping::RichTextObject] added RichTextObject
|
47
|
-
def <<(to)
|
48
|
-
@will_update = true
|
49
|
-
rto = RichTextObject.text_object(to)
|
50
|
-
@text_objects << rto
|
51
|
-
rto
|
52
|
-
end
|
53
|
-
|
54
|
-
# @param [Numeric] index index number
|
55
|
-
# @return [RichTextObject] selected RichTextObject
|
56
|
-
def [](index)
|
57
|
-
@text_objects[index]
|
58
|
-
end
|
59
|
-
|
60
|
-
# @param [Numeric] index
|
61
|
-
# @return [NotionRubyMapping::RichTextObject] removed RichTextObject
|
62
|
-
def delete_at(index)
|
63
|
-
@will_update = true
|
64
|
-
@text_objects[index]
|
65
|
-
end
|
66
|
-
|
67
|
-
# @return [String] full_text
|
68
|
-
def full_text
|
69
|
-
map(&:text).join ""
|
43
|
+
@will_update || page? && @text_objects.will_update
|
70
44
|
end
|
71
45
|
end
|
72
46
|
end
|
@@ -5,14 +5,25 @@ module NotionRubyMapping
|
|
5
5
|
class TitleProperty < TextProperty
|
6
6
|
TYPE = "title"
|
7
7
|
|
8
|
+
### Not public announced methods
|
9
|
+
|
10
|
+
## Common methods
|
11
|
+
|
8
12
|
# @param [Hash] json
|
9
13
|
def update_from_json(json)
|
10
14
|
@will_update = false
|
11
|
-
|
15
|
+
if database?
|
16
|
+
@json = json || {}
|
17
|
+
else
|
18
|
+
@text_objects = RichTextArray.new "rich_text", json: json["title"]
|
19
|
+
end
|
12
20
|
end
|
13
21
|
|
22
|
+
## Page property only methods
|
23
|
+
|
14
24
|
# @return [Hash] created json
|
15
25
|
def property_values_json
|
26
|
+
assert_page_property __method__
|
16
27
|
text_json = map(&:property_values_json)
|
17
28
|
{
|
18
29
|
@name => {
|
@@ -9,28 +9,39 @@ module NotionRubyMapping
|
|
9
9
|
include IsEmptyIsNotEmpty
|
10
10
|
TYPE = "url"
|
11
11
|
|
12
|
+
### Public announced methods
|
13
|
+
|
14
|
+
## Common methods
|
15
|
+
|
16
|
+
# @return [String, Hash, nil] url (Page), {} (Database)
|
17
|
+
def url
|
18
|
+
@json
|
19
|
+
end
|
20
|
+
|
21
|
+
## Page property only methods
|
22
|
+
|
23
|
+
def url=(url)
|
24
|
+
@will_update = true
|
25
|
+
@json = url
|
26
|
+
end
|
27
|
+
|
28
|
+
### Not public announced methods
|
29
|
+
|
30
|
+
## Common methods
|
31
|
+
|
12
32
|
# @param [String] name Property name
|
13
33
|
# @param [String] url url value (optional)
|
14
|
-
def initialize(name, will_update: false,
|
15
|
-
super name, will_update: will_update
|
16
|
-
@
|
34
|
+
def initialize(name, will_update: false, base_type: :page, json: nil)
|
35
|
+
super name, will_update: will_update, base_type: base_type
|
36
|
+
@json = json || (database? ? {} : nil)
|
17
37
|
end
|
18
|
-
attr_reader :url
|
19
38
|
|
20
|
-
|
21
|
-
def update_from_json(json)
|
22
|
-
@will_update = false
|
23
|
-
@url = json["url"]
|
24
|
-
end
|
39
|
+
## Page property only methods
|
25
40
|
|
26
41
|
# @return [Hash]
|
27
42
|
def property_values_json
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def url=(url)
|
32
|
-
@will_update = true
|
33
|
-
@url = url
|
43
|
+
assert_page_property __method__
|
44
|
+
{@name => {"url" => @json, "type" => "url"}}
|
34
45
|
end
|
35
46
|
end
|
36
47
|
end
|
@@ -14,11 +14,11 @@ module NotionRubyMapping
|
|
14
14
|
|
15
15
|
# @param [UserObject, String] uo
|
16
16
|
# @return [UserObject] self or created UserObject
|
17
|
-
def self.user_object(
|
18
|
-
if
|
19
|
-
|
17
|
+
def self.user_object(user_id_or_user)
|
18
|
+
if user_id_or_user.is_a? UserObject
|
19
|
+
user_id_or_user
|
20
20
|
else
|
21
|
-
UserObject.new user_id:
|
21
|
+
UserObject.new user_id: user_id_or_user
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
data/lib/notion_ruby_mapping.rb
CHANGED
@@ -6,6 +6,7 @@ require "yaml"
|
|
6
6
|
url_property email_property phone_number_property number_property checkbox_property select_property multi_property
|
7
7
|
multi_select_property date_base_property date_property created_time_property last_edited_time_property
|
8
8
|
people_property created_by_property last_edited_by_property files_property relation_property formula_property
|
9
|
-
rollup_property query payload property_cache rich_text_object text_object mention_object user_object
|
9
|
+
rollup_property query payload property_cache rich_text_object text_object mention_object user_object
|
10
|
+
rich_text_array].each do |k|
|
10
11
|
require_relative "notion_ruby_mapping/#{k}"
|
11
12
|
end
|
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.
|
4
|
+
version: 0.3.0
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -141,6 +141,9 @@ files:
|
|
141
141
|
- bin/console
|
142
142
|
- bin/setup
|
143
143
|
- env.yml.sample
|
144
|
+
- examples/change_title.md
|
145
|
+
- examples/renumbering_pages.md
|
146
|
+
- examples/set_icon_to_all_icon_unsettled_pages.md
|
144
147
|
- images/post_set_icon.png
|
145
148
|
- images/pre_set_icon.png
|
146
149
|
- images/serial_number.png
|
@@ -172,6 +175,7 @@ files:
|
|
172
175
|
- lib/notion_ruby_mapping/property_cache.rb
|
173
176
|
- lib/notion_ruby_mapping/query.rb
|
174
177
|
- lib/notion_ruby_mapping/relation_property.rb
|
178
|
+
- lib/notion_ruby_mapping/rich_text_array.rb
|
175
179
|
- lib/notion_ruby_mapping/rich_text_object.rb
|
176
180
|
- lib/notion_ruby_mapping/rich_text_property.rb
|
177
181
|
- lib/notion_ruby_mapping/rollup_property.rb
|
@@ -184,6 +188,7 @@ files:
|
|
184
188
|
- lib/notion_ruby_mapping/version.rb
|
185
189
|
- notion_ruby_mapping.gemspec
|
186
190
|
- sig/notion_ruby_mapping.rbs
|
191
|
+
- tools/an
|
187
192
|
homepage: https://github.com/hkob/notion_ruby_mapping.git
|
188
193
|
licenses:
|
189
194
|
- MIT
|