notion 1.0.1 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +116 -4
- data/lib/notion_api/blocks.rb +19 -982
- data/lib/notion_api/core.rb +85 -6
- data/lib/notion_api/notion_types/bulleted_block.rb +17 -0
- data/lib/notion_api/notion_types/callout_block.rb +16 -0
- data/lib/notion_api/notion_types/code_block.rb +16 -0
- data/lib/notion_api/notion_types/collection_view_blocks.rb +316 -0
- data/lib/notion_api/notion_types/column_list_block.rb +16 -0
- data/lib/notion_api/notion_types/divider_block.rb +15 -0
- data/lib/notion_api/notion_types/header_block.rb +16 -0
- data/lib/notion_api/notion_types/image_block.rb +16 -0
- data/lib/notion_api/notion_types/latex_block.rb +16 -0
- data/lib/notion_api/notion_types/numbered_block.rb +15 -0
- data/lib/notion_api/notion_types/page_block.rb +130 -0
- data/lib/notion_api/notion_types/quote_block.rb +16 -0
- data/lib/notion_api/notion_types/sub_header_block.rb +16 -0
- data/lib/notion_api/notion_types/sub_sub_header.rb +16 -0
- data/lib/notion_api/notion_types/table_of_contents_block.rb +15 -0
- data/lib/notion_api/notion_types/template.rb +360 -0
- data/lib/notion_api/notion_types/text_block.rb +16 -0
- data/lib/notion_api/notion_types/todo_block.rb +60 -0
- data/lib/notion_api/notion_types/toggle_block.rb +16 -0
- data/lib/notion_api/utils.rb +35 -4
- data/lib/notion_api/version.rb +1 -1
- metadata +21 -2
@@ -0,0 +1,16 @@
|
|
1
|
+
module NotionAPI
|
2
|
+
|
3
|
+
# good for just about anything (-:
|
4
|
+
class TextBlock < BlockTemplate
|
5
|
+
@notion_type = 'text'
|
6
|
+
@type = 'text'
|
7
|
+
|
8
|
+
def type
|
9
|
+
NotionAPI::TextBlock.notion_type
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :notion_type, :type
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module NotionAPI
|
2
|
+
|
3
|
+
# To-Do block: best for checklists and tracking to-dos.
|
4
|
+
class TodoBlock < BlockTemplate
|
5
|
+
@notion_type = 'to_do'
|
6
|
+
@type = 'to_do'
|
7
|
+
|
8
|
+
def type
|
9
|
+
NotionAPI::TodoBlock.notion_type
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :notion_type, :type
|
14
|
+
end
|
15
|
+
|
16
|
+
def checked=(checked_value)
|
17
|
+
# ! change the checked property of the Todo Block.
|
18
|
+
# ! checked_value -> boolean value used to determine whether the block should be checked [yes] or not [no] : ``str``
|
19
|
+
# set static variables for request
|
20
|
+
cookies = Core.options['cookies']
|
21
|
+
headers = Core.options['headers']
|
22
|
+
request_url = URLS[:UPDATE_BLOCK]
|
23
|
+
|
24
|
+
# set unique values for request
|
25
|
+
request_id = extract_id(SecureRandom.hex(16))
|
26
|
+
transaction_id = extract_id(SecureRandom.hex(16))
|
27
|
+
space_id = extract_id(SecureRandom.hex(16))
|
28
|
+
request_ids = {
|
29
|
+
request_id: request_id,
|
30
|
+
transaction_id: transaction_id,
|
31
|
+
space_id: space_id
|
32
|
+
}
|
33
|
+
|
34
|
+
if %w[yes no].include?(checked_value.downcase)
|
35
|
+
checked_hash = Utils::BlockComponents.checked_todo(@id, checked_value.downcase)
|
36
|
+
last_edited_time_parent_hash = Utils::BlockComponents.last_edited_time(@parent_id)
|
37
|
+
last_edited_time_child_hash = Utils::BlockComponents.last_edited_time(@id)
|
38
|
+
|
39
|
+
operations = [
|
40
|
+
checked_hash,
|
41
|
+
last_edited_time_parent_hash,
|
42
|
+
last_edited_time_child_hash
|
43
|
+
]
|
44
|
+
request_body = build_payload(operations, request_ids)
|
45
|
+
response = HTTParty.post(
|
46
|
+
request_url,
|
47
|
+
body: request_body.to_json,
|
48
|
+
cookies: cookies,
|
49
|
+
headers: headers
|
50
|
+
)
|
51
|
+
unless response.code == 200; raise "There was an issue completing your request. Here is the response from Notion: #{response.body}, and here is the payload that was sent: #{operations}.
|
52
|
+
Please try again, and if issues persist open an issue in GitHub."; end
|
53
|
+
|
54
|
+
true
|
55
|
+
else
|
56
|
+
false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module NotionAPI
|
2
|
+
|
3
|
+
# Toggle block: best for storing children blocks
|
4
|
+
class ToggleBlock < BlockTemplate
|
5
|
+
@notion_type = 'toggle'
|
6
|
+
@type = 'toggle'
|
7
|
+
|
8
|
+
def type
|
9
|
+
NotionAPI::ToggleBlock.notion_type
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :notion_type, :type
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/notion_api/utils.rb
CHANGED
@@ -127,7 +127,7 @@ module Utils
|
|
127
127
|
}
|
128
128
|
end
|
129
129
|
|
130
|
-
def self.duplicate(block_type, block_title, block_id, new_block_id, user_notion_id, contents)
|
130
|
+
def self.duplicate(block_type, block_title, block_id, new_block_id, user_notion_id, contents, properties, formatting)
|
131
131
|
# ! payload for duplicating a block. Most properties should be
|
132
132
|
# ! inherited from the block class the method is invoked on.
|
133
133
|
# ! block_type -> type of block that is being duplicated : ``cls``
|
@@ -150,9 +150,8 @@ module Utils
|
|
150
150
|
id: new_block_id,
|
151
151
|
version: 10,
|
152
152
|
type: block_type,
|
153
|
-
properties:
|
154
|
-
|
155
|
-
},
|
153
|
+
properties: properties,
|
154
|
+
format: formatting,
|
156
155
|
content: contents, # root-level blocks
|
157
156
|
created_time: timestamp,
|
158
157
|
last_edited_time: timestamp,
|
@@ -274,6 +273,14 @@ module Utils
|
|
274
273
|
},
|
275
274
|
}
|
276
275
|
end
|
276
|
+
def self.add_emoji_icon(block_id, icon)
|
277
|
+
{
|
278
|
+
id: block_id,
|
279
|
+
table:"block",
|
280
|
+
path:["format","page_icon"],
|
281
|
+
command:"set","args": icon
|
282
|
+
}
|
283
|
+
end
|
277
284
|
end
|
278
285
|
|
279
286
|
class CollectionViewComponents
|
@@ -547,6 +554,30 @@ module Utils
|
|
547
554
|
args: args,
|
548
555
|
}
|
549
556
|
end
|
557
|
+
|
558
|
+
def self.update_property_value(page_id, column_name, new_value)
|
559
|
+
# ! update the specified column_name to new_value
|
560
|
+
# ! page_id -> the ID of the page: ``str``
|
561
|
+
# ! column_name -> the name of the column ["property"] to update: ``str``
|
562
|
+
# ! new_value -> the new value to assign to that column ["property"]: ``str``
|
563
|
+
table = "block"
|
564
|
+
path = [
|
565
|
+
"properties",
|
566
|
+
column_name
|
567
|
+
]
|
568
|
+
command = "set"
|
569
|
+
args = [[
|
570
|
+
new_value
|
571
|
+
]]
|
572
|
+
|
573
|
+
{
|
574
|
+
id: page_id,
|
575
|
+
table: table,
|
576
|
+
path: path,
|
577
|
+
command: command,
|
578
|
+
args: args
|
579
|
+
}
|
580
|
+
end
|
550
581
|
end
|
551
582
|
|
552
583
|
def build_payload(operations, request_ids)
|
data/lib/notion_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Murphy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -113,6 +113,25 @@ files:
|
|
113
113
|
- lib/notion_api/client.rb
|
114
114
|
- lib/notion_api/core.rb
|
115
115
|
- lib/notion_api/markdown.rb
|
116
|
+
- lib/notion_api/notion_types/bulleted_block.rb
|
117
|
+
- lib/notion_api/notion_types/callout_block.rb
|
118
|
+
- lib/notion_api/notion_types/code_block.rb
|
119
|
+
- lib/notion_api/notion_types/collection_view_blocks.rb
|
120
|
+
- lib/notion_api/notion_types/column_list_block.rb
|
121
|
+
- lib/notion_api/notion_types/divider_block.rb
|
122
|
+
- lib/notion_api/notion_types/header_block.rb
|
123
|
+
- lib/notion_api/notion_types/image_block.rb
|
124
|
+
- lib/notion_api/notion_types/latex_block.rb
|
125
|
+
- lib/notion_api/notion_types/numbered_block.rb
|
126
|
+
- lib/notion_api/notion_types/page_block.rb
|
127
|
+
- lib/notion_api/notion_types/quote_block.rb
|
128
|
+
- lib/notion_api/notion_types/sub_header_block.rb
|
129
|
+
- lib/notion_api/notion_types/sub_sub_header.rb
|
130
|
+
- lib/notion_api/notion_types/table_of_contents_block.rb
|
131
|
+
- lib/notion_api/notion_types/template.rb
|
132
|
+
- lib/notion_api/notion_types/text_block.rb
|
133
|
+
- lib/notion_api/notion_types/todo_block.rb
|
134
|
+
- lib/notion_api/notion_types/toggle_block.rb
|
116
135
|
- lib/notion_api/utils.rb
|
117
136
|
- lib/notion_api/version.rb
|
118
137
|
homepage: https://danmurphy1217.github.io/notion-ruby/
|