notion_ruby_mapping 0.2.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00e3fdb4888f3e3c321215b91e3bb281e2b7683be35109f258b653febca4b697
4
- data.tar.gz: 90ffb01da47b66c38b6bf0300b7e53f0302e7ce194ec35dba140a807b38e5239
3
+ metadata.gz: ab8de3fcc36d0cc0d489fdf31b50845e5c86aea51891067f4412733f605ac76e
4
+ data.tar.gz: 454a657be8a1acea1d14444bb811704c6183fb8e1fb624ad656fdbf403671031
5
5
  SHA512:
6
- metadata.gz: 41ba458e34fc7f322c470e2a3a3a2b47cc091811267ed014066fc3eea5a9f29d99e48ce6d3e8e3a166cda06682612bd9429b42f2dea70c9072404fa66a76c311
7
- data.tar.gz: 5f4205dd334fc5d31bf1e56f2e5ca4cc769feff7f3d5310e9b56c1b93658d837341786936eb1641f5f84cb3fc903c342a3a019cd340d39c837370be6e54d6a04
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 Page](#42-page)
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 Update database](#423-update-database)
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
- - [6. Contributing](#6-contributing)
59
- - [7. License](#7-license)
60
- - [8. Code of Conduct](#8-code-of-conduct)
61
- - [9. Acknowledgements](#9-acknowledgements)
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
 
@@ -548,9 +546,12 @@ query13 = tp.filter_starts_with("A").ascending(tp)
548
546
  #### 4.2.3 Create child page
549
547
 
550
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.
551
550
 
552
551
  ```Ruby
553
552
  page = db.create_child_page TitleProperty, "Name"
553
+ page.properties["Name"] << "New Page"
554
+ page.save
554
555
  ```
555
556
 
556
557
  #### 4.2.4 Update database
@@ -843,6 +844,7 @@ p tp.property_values_json
843
844
  ```
844
845
 
845
846
  `<<` method appends a new TextObject or a String.
847
+
846
848
  ```Ruby
847
849
  to = TextObject.new "DEF"
848
850
  to.bold = true
@@ -857,6 +859,7 @@ p tp.property_values_json
857
859
  ```
858
860
 
859
861
  `delete_at(index)` method remove a TextObject at index.
862
+
860
863
  ```Ruby
861
864
  tp.delete_at 1
862
865
  tp << "GHI"
@@ -867,6 +870,7 @@ p tp.property_values_json
867
870
  ##### 4.5.3.9 CheckboxProperty
868
871
 
869
872
  PeopleProperty can set a boolean value by `.checkbox=`.
873
+
870
874
  ```Ruby
871
875
  cp = page.properties["CheckboxTitle"]
872
876
  cp.checkbox = true
@@ -877,6 +881,7 @@ p cp.property_values_json
877
881
  ##### 4.5.3.10 EmailProperty
878
882
 
879
883
  EmailProperty can set an email address by `.email=`.
884
+
880
885
  ```Ruby
881
886
  ep = page.properties["MailTitle"]
882
887
  ep.email = "hkobhkob@gmail.com"
@@ -914,9 +919,61 @@ p rp.property_values_json
914
919
  # Result => {"rp"=>{"type"=>"relation", "relation"=>[{"id"=>"R2"}, {"id"=>"R3"}]}}
915
920
  ```
916
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
+ ```
917
971
 
918
972
  ## 6. ChangeLog
919
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
920
977
  - 2022/3/14 Exclude notion-ruby-client, update Property values, update for Notion-Version 2022-02-22
921
978
  - 2022/2/25 add_property_for_update -> assign_property, update README.md
922
979
  - 2022/2/20 add support for MultiSelectProperty
@@ -928,18 +985,18 @@ p rp.property_values_json
928
985
  - 2022/2/13 added Page#set_icon
929
986
  - 2022/2/13 First commit
930
987
 
931
- ## 6. Contributing
988
+ ## 7. Contributing
932
989
 
933
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).
934
991
 
935
- ## 7. License
992
+ ## 8. License
936
993
 
937
994
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
938
995
 
939
- ## 8. Code of Conduct
996
+ ## 9. Code of Conduct
940
997
 
941
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).
942
999
 
943
- ## 9. Acknowledgements
1000
+ ## 10. Acknowledgements
944
1001
 
945
1002
  The code depends on [notion-ruby-client](https://github.com/orbit-love/notion-ruby-client).
@@ -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
@@ -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, json
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  NOTION_VERSION = "2022-02-22"
6
6
  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.2.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-15 00:00:00.000000000 Z
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