notion_scribe 0.1.0
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 +7 -0
- data/lib/notion_client.rb +26 -0
- data/lib/notion_scribe/version.rb +5 -0
- data/lib/notion_scribe.rb +7 -0
- data/lib/notion_template.rb +199 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: baebcc42630ffe456f4bab067aa631c3ff90dce82ca9fade05f11e2aecbe2cc4
|
|
4
|
+
data.tar.gz: c01222153978bddcfb12e685b5cfd5eef160f550657e4e307aad17bdb3927bde
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3d0594e54e78560e606992c9343dae0424fdadab5dd5e80372ed443c5f27f936bccf10c39382d4c674f692eaceebeb4cd652a40e9679e0839afd9f2a620dbf21
|
|
7
|
+
data.tar.gz: 83d9d4614852a0514c1a56c8390b6b8b4643701a38b5d15ead23a86b4fee057a02b2876f4f31e4dd3c0a109a87c28d0c2de3571b493511b97ede5e23df28b02c
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
class NotionClient
|
|
5
|
+
API_URL = 'https://api.notion.com/v1/pages'
|
|
6
|
+
|
|
7
|
+
def initialize(api_token)
|
|
8
|
+
@api_token = api_token
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create_page(content)
|
|
12
|
+
uri = URI(API_URL)
|
|
13
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
14
|
+
http.use_ssl = true
|
|
15
|
+
|
|
16
|
+
request = Net::HTTP::Post.new(uri)
|
|
17
|
+
request['Authorization'] = "Bearer #{@api_token}"
|
|
18
|
+
request['Content-Type'] = 'application/json'
|
|
19
|
+
request['Notion-Version'] = '2022-06-28'
|
|
20
|
+
|
|
21
|
+
request.body = content.to_json
|
|
22
|
+
|
|
23
|
+
response = http.request(request)
|
|
24
|
+
puts response.body
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
class NotionTemplate
|
|
2
|
+
def initialize(client, title, &block)
|
|
3
|
+
@client = client
|
|
4
|
+
@title = title
|
|
5
|
+
@blocks = []
|
|
6
|
+
instance_eval(&block)
|
|
7
|
+
send_to_notion
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def header(text)
|
|
11
|
+
@blocks << {
|
|
12
|
+
object: "block",
|
|
13
|
+
type: "heading_1",
|
|
14
|
+
heading_1: {
|
|
15
|
+
rich_text: [{
|
|
16
|
+
type: "text",
|
|
17
|
+
text: { content: text }
|
|
18
|
+
}]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def subheader(text)
|
|
24
|
+
@blocks << {
|
|
25
|
+
object: "block",
|
|
26
|
+
type: "heading_2",
|
|
27
|
+
heading_2: {
|
|
28
|
+
rich_text: [{
|
|
29
|
+
type: "text",
|
|
30
|
+
text: { content: text }
|
|
31
|
+
}]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def subsubheader(text)
|
|
37
|
+
@blocks << {
|
|
38
|
+
object: "block",
|
|
39
|
+
type: "heading_3",
|
|
40
|
+
heading_3: {
|
|
41
|
+
rich_text: [{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: { content: text }
|
|
44
|
+
}]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def paragraph(text)
|
|
50
|
+
@blocks << {
|
|
51
|
+
object: "block",
|
|
52
|
+
type: "paragraph",
|
|
53
|
+
paragraph: {
|
|
54
|
+
rich_text: [{
|
|
55
|
+
type: "text",
|
|
56
|
+
text: { content: text }
|
|
57
|
+
}]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def bulleted_list(*items)
|
|
63
|
+
items.each do |item|
|
|
64
|
+
@blocks << {
|
|
65
|
+
object: "block",
|
|
66
|
+
type: "bulleted_list_item",
|
|
67
|
+
bulleted_list_item: {
|
|
68
|
+
rich_text: [{
|
|
69
|
+
type: "text",
|
|
70
|
+
text: { content: item }
|
|
71
|
+
}]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def numbered_list(*items)
|
|
78
|
+
items.each do |item|
|
|
79
|
+
@blocks << {
|
|
80
|
+
object: "block",
|
|
81
|
+
type: "numbered_list_item",
|
|
82
|
+
numbered_list_item: {
|
|
83
|
+
rich_text: [{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: { content: item }
|
|
86
|
+
}]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def to_do(text, checked: false)
|
|
93
|
+
@blocks << {
|
|
94
|
+
object: "block",
|
|
95
|
+
type: "to_do",
|
|
96
|
+
to_do: {
|
|
97
|
+
rich_text: [{
|
|
98
|
+
type: "text",
|
|
99
|
+
text: { content: text }
|
|
100
|
+
}],
|
|
101
|
+
checked: checked
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def quote(text)
|
|
107
|
+
@blocks << {
|
|
108
|
+
object: "block",
|
|
109
|
+
type: "quote",
|
|
110
|
+
quote: {
|
|
111
|
+
rich_text: [{
|
|
112
|
+
type: "text",
|
|
113
|
+
text: { content: text }
|
|
114
|
+
}]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def image(url)
|
|
120
|
+
@blocks << {
|
|
121
|
+
object: "block",
|
|
122
|
+
type: "image",
|
|
123
|
+
image: {
|
|
124
|
+
type: "external",
|
|
125
|
+
external: { url: url }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def callout(text, color = "purple") # Default color set to purple
|
|
131
|
+
@blocks << {
|
|
132
|
+
object: "block",
|
|
133
|
+
type: "callout",
|
|
134
|
+
callout: {
|
|
135
|
+
rich_text: [{
|
|
136
|
+
type: "text",
|
|
137
|
+
text: { content: text }
|
|
138
|
+
}],
|
|
139
|
+
icon: { type: "emoji", emoji: "🔔" }, # Optional icon
|
|
140
|
+
color: "gray_background" # Set the color of the callout
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def toggle(text, &block)
|
|
146
|
+
toggle_block = {
|
|
147
|
+
object: "block",
|
|
148
|
+
type: "toggle",
|
|
149
|
+
toggle: {
|
|
150
|
+
rich_text: [{
|
|
151
|
+
type: "text",
|
|
152
|
+
text: { content: text }
|
|
153
|
+
}],
|
|
154
|
+
children: []
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if block_given?
|
|
159
|
+
# Capture nested blocks
|
|
160
|
+
instance_eval(&block)
|
|
161
|
+
toggle_block[:toggle][:children] = @blocks
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
@blocks << toggle_block
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def divider
|
|
168
|
+
@blocks << {
|
|
169
|
+
object: "block",
|
|
170
|
+
type: "divider",
|
|
171
|
+
divider: {}
|
|
172
|
+
}
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def table_of_contents
|
|
176
|
+
@blocks << {
|
|
177
|
+
object: "block",
|
|
178
|
+
type: "table_of_contents",
|
|
179
|
+
table_of_contents: {}
|
|
180
|
+
}
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def send_to_notion
|
|
184
|
+
page_content = {
|
|
185
|
+
parent: { page_id: "10a58974-264e-8020-abf0-f43003c5457f" }, # or database_id as necessary
|
|
186
|
+
properties: {
|
|
187
|
+
title: [
|
|
188
|
+
{
|
|
189
|
+
type: "text",
|
|
190
|
+
text: { content: @title }
|
|
191
|
+
}
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
children: @blocks
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@client.create_page(page_content)
|
|
198
|
+
end
|
|
199
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: notion_scribe
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Your Name
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-09-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.13.7
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.13.7
|
|
27
|
+
description: This gem allows users to create and customize Notion pages with a simple
|
|
28
|
+
Ruby DSL.
|
|
29
|
+
email:
|
|
30
|
+
- azzen.abidi@gmail.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- lib/notion_client.rb
|
|
36
|
+
- lib/notion_scribe.rb
|
|
37
|
+
- lib/notion_scribe/version.rb
|
|
38
|
+
- lib/notion_template.rb
|
|
39
|
+
homepage: https://github.com/azzenabidi/notion_scribe
|
|
40
|
+
licenses:
|
|
41
|
+
- MIT
|
|
42
|
+
metadata: {}
|
|
43
|
+
post_install_message:
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '3.0'
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 3.5.11
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: A Ruby DSL to create Notion pages effortlessly.
|
|
62
|
+
test_files: []
|