notion-sdk-ruby 0.4.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,339 +1,55 @@
1
- # Notion Ruby SDK
2
-
3
- [![ci](https://github.com/mgmarlow/notion-sdk-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/mgmarlow/notion-sdk-ruby/actions/workflows/ci.yml)
4
- [![Gem Version](https://badge.fury.io/rb/notion-sdk-ruby.svg)](https://badge.fury.io/rb/notion-sdk-ruby)
5
-
6
- Unofficial Ruby client for the [Notion APIs](https://developers.notion.com/).
7
-
8
- - [Notion Ruby SDK](#notion-ruby-sdk)
9
- - [Installation](#installation)
10
- - [Usage](#usage)
11
- - [API reference](#api-reference)
12
- - [Databases](#databases)
13
- - [databases#retrieve](#databasesretrieve)
14
- - [databases#list](#databaseslist)
15
- - [databases#query](#databasesquery)
16
- - [databases#create](#databasescreate)
17
- - [databases#update](#databasesupdate)
18
- - [Pages](#pages)
19
- - [pages#retrieve](#pagesretrieve)
20
- - [pages#create](#pagescreate)
21
- - [pages#update](#pagesupdate)
22
- - [Blocks](#blocks)
23
- - [blocks#retrieve](#blocksretrieve)
24
- - [blocks#update](#blocksupdate)
25
- - [blocks#children#list](#blockschildrenlist)
26
- - [blocks#children#append](#blockschildrenappend)
27
- - [Users](#users)
28
- - [users#retrieve](#usersretrieve)
29
- - [users#list](#userslist)
30
- - [Search](#search)
31
- - [#search](#search-1)
32
- - [Development](#development)
33
- - [Contributing](#contributing)
34
- - [License](#license)
35
-
36
- ## Installation
37
-
38
- Add this line to your application's Gemfile:
39
-
40
- ```ruby
41
- gem 'notion-sdk-ruby'
42
- ```
43
-
44
- And then execute:
45
-
46
- $ bundle install
47
-
48
- ## Usage
49
-
50
- Initialize `Notion::Client` with your app's [integration secret](https://developers.notion.com/docs/getting-started#create-a-new-integration).
51
-
52
- ```rb
53
- require "notion-sdk-ruby"
54
- client = Notion::Client.new(token: ENV["NOTION_API_SECRET"])
55
- ```
56
-
57
- ## API reference
58
-
59
- ### Databases
60
-
61
- #### databases#retrieve
62
-
63
- [API reference](https://developers.notion.com/reference/get-database)
64
-
65
- ```rb
66
- client.databases.retrieve("668d797c-76fa-4934-9b05-ad288df2d136")
67
- ```
68
-
69
- #### databases#list
70
-
71
- [API reference](https://developers.notion.com/reference/get-databases)
72
-
73
- ```rb
74
- client.databases.list
75
- ```
76
-
77
- #### databases#query
78
-
79
- [API reference](https://developers.notion.com/reference/post-database-query)
80
-
81
- ```rb
82
- client.databases.query("668d797c-76fa-4934-9b05-ad288df2d136", {
83
- filter: {
84
- or: [
85
- {
86
- property: "In stock",
87
- checkbox: {
88
- equals: true
89
- }
90
- },
91
- {
92
- property: "Cost of next trip",
93
- number: {
94
- greater_than_or_equal_to: 2
95
- }
96
- }
97
- ]
98
- },
99
- sorts: [
100
- {
101
- property: "Last ordered",
102
- direction: "ascending"
103
- }
104
- ]
105
- })
106
- ```
107
-
108
- #### databases#create
109
-
110
- [API reference](https://developers.notion.com/reference/create-a-database)
111
-
112
- ```rb
113
- client.databases.create({
114
- parent: {
115
- type: "page_id",
116
- page_id: "98ad959b-2b6a-4774-80ee-00246fb0ea9b"
117
- },
118
- title: [
119
- {
120
- type: "text",
121
- text: {
122
- content: "Grocery List",
123
- link: null
124
- }
125
- }
126
- ],
127
- properties: {
128
- Name: {
129
- title: {}
130
- }
131
- }
132
- })
133
- ```
134
-
135
- #### databases#update
136
-
137
- [API reference](https://developers.notion.com/reference/update-a-database)
138
-
139
- ```rb
140
- client.databases.update("668d797c-76fa-4934-9b05-ad288df2d136", {
141
- title: [
142
- {
143
- type: "text",
144
- text: {
145
- content: "Grocery List",
146
- link: null
147
- }
148
- }
149
- ],
150
- properties: {
151
- Name: {
152
- title: {}
153
- }
154
- }
155
- })
156
- ```
157
-
158
- ### Pages
159
-
160
- #### pages#retrieve
161
-
162
- [API reference](https://developers.notion.com/reference/get-page)
163
-
164
- ```rb
165
- client.pages.retrieve("b55c9c91-384d-452b-81db-d1ef79372b75")
166
- ```
167
-
168
- #### pages#create
169
-
170
- [API reference](https://developers.notion.com/reference/post-page)
171
-
172
- ```rb
173
- client.pages.create({
174
- parent: { database_id: "48f8fee9cd794180bc2fec0398253067" },
175
- properties: {
176
- Name: {
177
- title: [
178
- {
179
- text: {
180
- content: "Tuscan Kale"
181
- }
182
- }
183
- ]
184
- },
185
- Description: {
186
- rich_text: [
187
- {
188
- text: {
189
- content: "A dark green leafy vegetable"
190
- }
191
- }
192
- ]
193
- },
194
- Food group: {
195
- select: {
196
- name: "Vegetable"
197
- }
198
- },
199
- Price: { number: 2.5 }
200
- },
201
- children: []
202
- })
203
- ```
204
-
205
- #### pages#update
206
-
207
- [API reference](https://developers.notion.com/reference/patch-page)
208
-
209
- ```rb
210
- client.pages.update("b55c9c91-384d-452b-81db-d1ef79372b75", {
211
- properties: {
212
- "In stock": { checkbox: true }
213
- }
214
- })
215
- ```
216
-
217
- ### Blocks
218
-
219
- #### blocks#retrieve
220
-
221
- [API reference](https://developers.notion.com/reference/retrieve-a-block)
222
-
223
- ```rb
224
- client.blocks.retrieve("b55c9c91-384d-452b-81db-d1ef79372b75")
225
- ```
226
-
227
- #### blocks#update
228
-
229
- [API reference](https://developers.notion.com/reference/update-a-block)
230
-
231
- ```rb
232
- client.blocks.update("b55c9c91-384d-452b-81db-d1ef79372b75", {
233
- to_do: {
234
- text: [{
235
- text: { content: "Lacinato kale" }
236
- }],
237
- checked: false
238
- }
239
- })
240
- ```
241
-
242
- #### blocks#children#list
243
-
244
- [API reference](https://developers.notion.com/reference/get-block-children)
245
-
246
- ```rb
247
- client.blocks.children.list("b55c9c91-384d-452b-81db-d1ef79372b75", {
248
- page_size: 100
249
- })
250
- ```
251
-
252
- #### blocks#children#append
253
-
254
- [API reference](https://developers.notion.com/reference/patch-block-children)
255
-
256
- ```rb
257
- client.blocks.children.append("b54c9c91-384d-452b-81db-d1ef79372b75", {
258
- children: [
259
- {
260
- object: "block",
261
- type: "heading_1",
262
- heading_1: {
263
- text: [{ type: "text", text: { content: "Lacinato kale" } }]
264
- }
265
- },
266
- {
267
- object: "block",
268
- type: "paragraph",
269
- paragraph: {
270
- text: [
271
- {
272
- type: "text",
273
- text: {
274
- content: "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.",
275
- link: { url: "https://en.wikipedia.org/wiki/Lacinato_kale" }
276
- }
277
- }
278
- ]
279
- }
280
- }
281
- ]
282
- })
283
- ```
284
-
285
- ### Users
286
-
287
- #### users#retrieve
288
-
289
- [API reference](https://developers.notion.com/reference/get-user)
290
-
291
- ```rb
292
- client.users.retrieve("d40e767c-d7af-4b18-a86d-55c61f1e39a4")
293
- ```
294
-
295
- #### users#list
296
-
297
- [API reference](https://developers.notion.com/reference/get-users)
298
-
299
- ```rb
300
- client.users.list
301
- ```
302
-
303
- ### Search
304
-
305
- [API reference](https://developers.notion.com/reference/post-search)
306
-
307
- #### #search
308
-
309
- ```rb
310
- client.search({
311
- query: "External tasks",
312
- sort: {
313
- direction: "ascending",
314
- timestamp: "last_edited_time"
315
- }
316
- })
317
- ```
318
-
319
- ## Development
320
-
321
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
322
-
323
- Before using `bin/console` you need to create a new file, `.env`, at the root project directory. This will enable you to run commands directly against your [Notion integration](https://developers.notion.com/docs/getting-started).
324
-
325
- ```
326
- cat > .env <<EOF
327
- API_SECRET=<YOUR NOTION API SECRET HERE>
328
- EOF
329
- ```
330
-
331
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
332
-
333
- ## Contributing
334
-
335
- Bug reports and pull requests are welcome on GitHub at https://github.com/mgmarlow/notion-sdk-ruby.
336
-
337
- ## License
338
-
339
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1
+ # Notion Ruby SDK
2
+
3
+ [![ci](https://github.com/mgmarlow/notion-sdk-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/mgmarlow/notion-sdk-ruby/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/notion-sdk-ruby.svg)](https://badge.fury.io/rb/notion-sdk-ruby)
5
+
6
+ Unofficial Ruby client for the [Notion APIs](https://developers.notion.com/).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'notion-sdk-ruby'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```
19
+ $ bundle install
20
+ ```
21
+
22
+ ## Documentation
23
+
24
+ - [API documentation](https://mgmarlow.github.io/notion-sdk-ruby/Notion/Client.html)
25
+
26
+ ## Usage
27
+
28
+ Initialize `Notion::Client` with your app's [integration secret](https://developers.notion.com/docs/getting-started#create-a-new-integration).
29
+
30
+ ```rb
31
+ require "notion-sdk-ruby"
32
+ client = Notion::Client.new(token: ENV["NOTION_API_SECRET"])
33
+ ```
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ Before using `bin/console` you need to create a new file, `.env`, at the root project directory. This will enable you to run commands directly against your [Notion integration](https://developers.notion.com/docs/getting-started).
40
+
41
+ ```
42
+ cat > .env <<EOF
43
+ NOTION_API_KEY=<YOUR NOTION API SECRET HERE>
44
+ EOF
45
+ ```
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mgmarlow/notion-sdk-ruby.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,7 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- require "standard/rake"
4
-
5
- RSpec::Core::RakeTask.new(:spec)
6
-
7
- task default: [:spec, :standard]
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "standard/rake"
4
+ require "yard"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ YARD::Rake::YardocTask.new do |t|
9
+ t.files = ["lib/**/*.rb"]
10
+ end
11
+
12
+ task default: [:spec, :standard]
data/bin/console CHANGED
@@ -1,11 +1,11 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "pry"
5
- require 'dotenv/load'
6
-
7
- require "notion-sdk-ruby"
8
-
9
- $client = Notion::Client.new(token: ENV["API_SECRET"])
10
-
11
- Pry.start
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pry"
5
+ require 'dotenv/load'
6
+
7
+ require "notion-sdk-ruby"
8
+
9
+ $client = Notion::Client.new(token: ENV["API_SECRET"])
10
+
11
+ Pry.start
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,56 @@
1
+ module Notion
2
+ module Api
3
+ class BlocksMethods
4
+ include RequestClient
5
+
6
+ # @return [Notion::Api::BlocksChildrenMethods]
7
+ def children
8
+ BlocksChildrenMethods.new
9
+ end
10
+
11
+ # Retrieves a Block object using the ID specified.
12
+ # https://developers.notion.com/reference/retrieve-a-block
13
+ # @param [String] id block_id
14
+ # @return [Notion::Block]
15
+ def retrieve(id)
16
+ response = get("/v1/blocks/#{id}")
17
+ Block.new(response.body)
18
+ end
19
+
20
+ # Updates the content for the specified block_id based on the block type.
21
+ # https://developers.notion.com/reference/update-a-block
22
+ # @param [String] id block_id
23
+ # @param [Hash] body
24
+ # @return [Notion::Block]
25
+ def update(id, body)
26
+ response = patch("/v1/blocks/#{id}", body.to_json)
27
+ Block.new(response.body)
28
+ end
29
+ end
30
+
31
+ class BlocksChildrenMethods
32
+ include RequestClient
33
+
34
+ # Returns a paginated array of child block objects contained in the block
35
+ # using the ID specified.
36
+ # https://developers.notion.com/reference/get-block-children
37
+ # @param [String] id block_id
38
+ # @param [Hash] query
39
+ # @return [Array<Notion::Block>]
40
+ def list(id, query = {})
41
+ response = get("/v1/blocks/#{id}/children", query)
42
+ List.new(response.body)
43
+ end
44
+
45
+ # Creates and appends new children blocks to the parent block_id specified.
46
+ # https://developers.notion.com/reference/patch-block-children
47
+ # @param [String] id block_id
48
+ # @param [Hash] body
49
+ # @return [Array<Notion::Block>]
50
+ def append(id, body)
51
+ response = patch("/v1/blocks/#{id}/children", body.to_json)
52
+ List.new(response.body)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,47 @@
1
+ module Notion
2
+ module Api
3
+ class DatabasesMethods
4
+ include RequestClient
5
+
6
+ # Retrieves a Database object using the ID specified.
7
+ # https://developers.notion.com/reference/retrieve-a-database
8
+ # @param [String] id database_id
9
+ # @return [Notion::Database]
10
+ def retrieve(id)
11
+ response = get("/v1/databases/#{id}")
12
+ Database.new(response.body)
13
+ end
14
+
15
+ # Gets a list of Pages contained in the database, filtered and ordered according
16
+ # to the filter conditions and sort criteria provided in the request.
17
+ # https://developers.notion.com/reference/post-database-query
18
+ # @param [String] id database_id
19
+ # @param [Hash] body
20
+ # @return [Array<Notion::Database>]
21
+ def query(id, body)
22
+ response = post("/v1/databases/#{id}/query", body.to_json)
23
+ List.new(response.body)
24
+ end
25
+
26
+ # Creates a database as a subpage in the specified parent page, with the
27
+ # specified properties schema.
28
+ # https://developers.notion.com/reference/create-a-database
29
+ # @param [Hash] body
30
+ # @return [Notion::Database]
31
+ def create(body)
32
+ response = post("/v1/databases", body.to_json)
33
+ Database.new(response.body)
34
+ end
35
+
36
+ # Updates an existing database as specified by the parameters.
37
+ # https://developers.notion.com/reference/update-a-database
38
+ # @param [String] id database_id
39
+ # @param [Hash] body
40
+ # @return [Notion::Database]
41
+ def update(id, body)
42
+ response = patch("/v1/databases/#{id}", body.to_json)
43
+ Database.new(response.body)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,36 @@
1
+ module Notion
2
+ module Api
3
+ class PagesMethods
4
+ include RequestClient
5
+
6
+ # Retrieves a Page object using the ID specified.
7
+ # https://developers.notion.com/reference/retrieve-a-page
8
+ # @param [String] id page_id
9
+ # @return [Notion::Page]
10
+ def retrieve(id)
11
+ response = get("/v1/pages/#{id}")
12
+ Page.new(response.body)
13
+ end
14
+
15
+ # Creates a new page in the specified database or as a child of
16
+ # an existing page.
17
+ # https://developers.notion.com/reference/post-page
18
+ # @param [Hash] body
19
+ # @return [Notion::Page]
20
+ def create(body)
21
+ response = post("/v1/pages", body.to_json)
22
+ Page.new(response.body)
23
+ end
24
+
25
+ # Updates page property values for the specified page.
26
+ # https://developers.notion.com/reference/patch-page
27
+ # @param [String] id page_id
28
+ # @param [Hash] body
29
+ # @return [Notion::Page]
30
+ def update(id, body)
31
+ response = patch("/v1/pages/#{id}", body.to_json)
32
+ Page.new(response.body)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ module Notion
2
+ module Api
3
+ module SearchMethods
4
+ include RequestClient
5
+
6
+ # Searches all original pages, databases, and child pages/databases
7
+ # that are shared with the integration.
8
+ # https://developers.notion.com/reference/post-search
9
+ # @param [Hash] body
10
+ # @return [Array]
11
+ def search(body)
12
+ response = post("/v1/search", body.to_json)
13
+ List.new(response.body)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ module Notion
2
+ module Api
3
+ class UsersMethods
4
+ include RequestClient
5
+
6
+ # Returns a paginated list of Users for the workspace.
7
+ # https://developers.notion.com/reference/get-users
8
+ # @return [Array<Notion::User>]
9
+ def list
10
+ response = get("/v1/users")
11
+ List.new(response.body)
12
+ end
13
+
14
+ # Retrieves a User using the ID specified.
15
+ # https://developers.notion.com/reference/get-user
16
+ # @param [String] id user_id
17
+ # @return [Notion::User]
18
+ def retrieve(id)
19
+ response = get("/v1/users/#{id}")
20
+ User.new(response.body)
21
+ end
22
+ end
23
+ end
24
+ end