notion 1.1.3 → 1.1.4
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/lib/notion_api/blocks.rb +1 -0
- data/lib/notion_api/client.rb +2 -2
- data/lib/notion_api/core.rb +57 -28
- data/lib/notion_api/notion_types/link_block.rb +51 -0
- data/lib/notion_api/utils.rb +7 -7
- data/lib/notion_api/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f33fd46038d04e6945365a27f4c06bf271606c26738e0f829b303cf62bbb516d
|
4
|
+
data.tar.gz: 92e51354718ea8c3d947e77f1aa9073cb654312e8783f9e375d246b8f2145188
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0c40153c1ec62514f1c6cea7c3a1c6e48bd5180c1eff123b92873527368ca64922a24ab1a9de28c33084a1e248e8a9d702456f3b7efc412bca9b9487dbb947e
|
7
|
+
data.tar.gz: a67029c37053b49be748fb5268ec1022be91194723fd9a4e68657cbc1baf9d0d1e13a5cf75e1f23dc2a4851ae611cf511c46aff2afc59e0fbcad347e256ef6c3
|
data/lib/notion_api/blocks.rb
CHANGED
@@ -17,6 +17,7 @@ require_relative "notion_types/table_of_contents_block"
|
|
17
17
|
require_relative "notion_types/text_block"
|
18
18
|
require_relative "notion_types/todo_block"
|
19
19
|
require_relative "notion_types/toggle_block"
|
20
|
+
require_relative "notion_types/link_block"
|
20
21
|
|
21
22
|
Classes = NotionAPI.constants.select { |c| NotionAPI.const_get(c).is_a? Class and c.to_s != 'BlockTemplate' and c.to_s != 'Core' and c.to_s !='Client' }
|
22
23
|
notion_types = []
|
data/lib/notion_api/client.rb
CHANGED
data/lib/notion_api/core.rb
CHANGED
@@ -72,6 +72,35 @@ module NotionAPI
|
|
72
72
|
jsonified_record_response["block"][clean_id]["value"]["content"] || []
|
73
73
|
end
|
74
74
|
|
75
|
+
def extract_id(url_or_id)
|
76
|
+
# ! parse and clean the URL or ID object provided.
|
77
|
+
# ! url_or_id -> the block ID or URL : ``str``
|
78
|
+
http_or_https = url_or_id.match(/^(http|https)/) # true if http or https in url_or_id...
|
79
|
+
collection_view_match = url_or_id.match(/(\?v=)/)
|
80
|
+
|
81
|
+
if (url_or_id.length == 36) && ((url_or_id.split("-").length == 5) && !http_or_https)
|
82
|
+
# passes if url_or_id is perfectly formatted already...
|
83
|
+
url_or_id
|
84
|
+
elsif (http_or_https && (url_or_id.split("-").last.length == 32)) || (!http_or_https && (url_or_id.length == 32)) || (collection_view_match)
|
85
|
+
# passes if either:
|
86
|
+
# 1. a URL is passed as url_or_id and the ID at the end is 32 characters long or
|
87
|
+
# 2. a URL is not passed and the ID length is 32 [aka unformatted]
|
88
|
+
pattern = [8, 13, 18, 23]
|
89
|
+
if collection_view_match
|
90
|
+
id_without_view = url_or_id.split("?")[0]
|
91
|
+
clean_id = id_without_view.split("/").last
|
92
|
+
pattern.each { |index| clean_id.insert(index, "-") }
|
93
|
+
clean_id
|
94
|
+
else
|
95
|
+
id = url_or_id.split("-").last
|
96
|
+
pattern.each { |index| id.insert(index, "-") }
|
97
|
+
id
|
98
|
+
end
|
99
|
+
else
|
100
|
+
raise ArgumentError, "Expected a Notion page URL or a page ID. Please consult the documentation for further information."
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
75
104
|
private
|
76
105
|
|
77
106
|
def get_notion_id(body)
|
@@ -205,34 +234,34 @@ module NotionAPI
|
|
205
234
|
jsonified_record_response["block"][clean_id]["value"]["view_ids"] || []
|
206
235
|
end
|
207
236
|
|
208
|
-
def extract_id(url_or_id)
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
end
|
237
|
+
# def extract_id(url_or_id)
|
238
|
+
# # ! parse and clean the URL or ID object provided.
|
239
|
+
# # ! url_or_id -> the block ID or URL : ``str``
|
240
|
+
# http_or_https = url_or_id.match(/^(http|https)/) # true if http or https in url_or_id...
|
241
|
+
# collection_view_match = url_or_id.match(/(\?v=)/)
|
242
|
+
|
243
|
+
# if (url_or_id.length == 36) && ((url_or_id.split("-").length == 5) && !http_or_https)
|
244
|
+
# # passes if url_or_id is perfectly formatted already...
|
245
|
+
# url_or_id
|
246
|
+
# elsif (http_or_https && (url_or_id.split("-").last.length == 32)) || (!http_or_https && (url_or_id.length == 32)) || (collection_view_match)
|
247
|
+
# # passes if either:
|
248
|
+
# # 1. a URL is passed as url_or_id and the ID at the end is 32 characters long or
|
249
|
+
# # 2. a URL is not passed and the ID length is 32 [aka unformatted]
|
250
|
+
# pattern = [8, 13, 18, 23]
|
251
|
+
# if collection_view_match
|
252
|
+
# id_without_view = url_or_id.split("?")[0]
|
253
|
+
# clean_id = id_without_view.split("/").last
|
254
|
+
# pattern.each { |index| clean_id.insert(index, "-") }
|
255
|
+
# clean_id
|
256
|
+
# else
|
257
|
+
# id = url_or_id.split("-").last
|
258
|
+
# pattern.each { |index| id.insert(index, "-") }
|
259
|
+
# id
|
260
|
+
# end
|
261
|
+
# else
|
262
|
+
# raise ArgumentError, "Expected a Notion page URL or a page ID. Please consult the documentation for further information."
|
263
|
+
# end
|
264
|
+
# end
|
236
265
|
|
237
266
|
def extract_collection_schema(collection_id, view_id, response = {})
|
238
267
|
# ! retrieve the collection scehma. Useful for 'building' the backbone for a table.
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module NotionAPI
|
2
|
+
|
3
|
+
# simiilar to code block but for mathematical functions.
|
4
|
+
class LinkBlock < BlockTemplate
|
5
|
+
@notion_type = "link_to_page"
|
6
|
+
@type = "link_to_page"
|
7
|
+
|
8
|
+
def type
|
9
|
+
NotionAPI::LinkBlock.notion_type
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_reader :notion_type, :type
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create(block_id, new_block_id, block_title, target, position_command, request_ids, options)
|
17
|
+
block_title = super.extract_id(block_title)
|
18
|
+
|
19
|
+
cookies = Core.options["cookies"]
|
20
|
+
headers = Core.options["headers"]
|
21
|
+
|
22
|
+
create_block_hash = Utils::BlockComponents.create(new_block_id, self.notion_type)
|
23
|
+
block_location_hash = Utils::BlockComponents.block_location_add(block_id, block_id, block_title, new_block_id, position_command)
|
24
|
+
last_edited_time_hash = Utils::BlockComponents.last_edited_time(block_id)
|
25
|
+
remove_item_hash = Utils::BlockComponents.block_location_remove( super.parent_id, new_block_id)
|
26
|
+
|
27
|
+
operations = [
|
28
|
+
create_block_hash,
|
29
|
+
block_location_hash,
|
30
|
+
last_edited_time_hash,
|
31
|
+
remove_item_hash
|
32
|
+
]
|
33
|
+
|
34
|
+
request_url = URLS[:UPDATE_BLOCK]
|
35
|
+
request_body = Utils::BlockComponents.build_payload(operations, request_ids)
|
36
|
+
|
37
|
+
response = HTTParty.post(
|
38
|
+
request_url,
|
39
|
+
body: request_body.to_json,
|
40
|
+
cookies: cookies,
|
41
|
+
headers: headers,
|
42
|
+
)
|
43
|
+
|
44
|
+
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}.
|
45
|
+
Please try again, and if issues persist open an issue in GitHub."; end
|
46
|
+
|
47
|
+
self.new(new_block_id, block_title, block_id)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/lib/notion_api/utils.rb
CHANGED
@@ -11,7 +11,7 @@ module Utils
|
|
11
11
|
class BlockComponents
|
12
12
|
# ! Each function defined here builds one component that is included in each request sent to Notions backend.
|
13
13
|
# ! Each request sent will contain multiple components.
|
14
|
-
|
14
|
+
|
15
15
|
def self.build_payload(operations, request_ids)
|
16
16
|
# ! properly formats the payload for Notions backend.
|
17
17
|
# ! operations -> an array of hashes that define the operations to perform : ``Array[Hash]``
|
@@ -351,14 +351,14 @@ module Utils
|
|
351
351
|
# ! new_block_id -> the ID of the new ImageBlock: ``str``
|
352
352
|
# ! block_url -> the URL of the ImageBlock: ``str``
|
353
353
|
{
|
354
|
-
|
355
|
-
|
356
|
-
|
354
|
+
id: new_block_id,
|
355
|
+
table: "block",
|
356
|
+
path: [
|
357
357
|
"format",
|
358
358
|
],
|
359
|
-
|
360
|
-
|
361
|
-
|
359
|
+
command: "update",
|
360
|
+
args: {
|
361
|
+
display_source: block_url,
|
362
362
|
},
|
363
363
|
}
|
364
364
|
end
|
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.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Murphy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/notion_api/notion_types/header_block.rb
|
123
123
|
- lib/notion_api/notion_types/image_block.rb
|
124
124
|
- lib/notion_api/notion_types/latex_block.rb
|
125
|
+
- lib/notion_api/notion_types/link_block.rb
|
125
126
|
- lib/notion_api/notion_types/numbered_block.rb
|
126
127
|
- lib/notion_api/notion_types/page_block.rb
|
127
128
|
- lib/notion_api/notion_types/quote_block.rb
|