notionrb 1.3.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/.devcontainer/Dockerfile +5 -0
- data/.devcontainer/boot.sh +1 -0
- data/.devcontainer/devcontainer.json +30 -0
- data/.github/workflows/ci.yml +15 -0
- data/.github/workflows/rubocop.yml +17 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.rubocop.yml +55 -0
- data/.rubocop_todo.yml +86 -0
- data/CHANGELOG.md +144 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +51 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +95 -0
- data/LICENSE.md +21 -0
- data/README.md +677 -0
- data/Rakefile +18 -0
- data/bin/console +31 -0
- data/lib/notion/api/endpoints/blocks.rb +100 -0
- data/lib/notion/api/endpoints/comments.rb +61 -0
- data/lib/notion/api/endpoints/data_sources.rb +102 -0
- data/lib/notion/api/endpoints/databases.rb +134 -0
- data/lib/notion/api/endpoints/pages.rb +95 -0
- data/lib/notion/api/endpoints/search.rb +41 -0
- data/lib/notion/api/endpoints/users.rb +48 -0
- data/lib/notion/api/endpoints.rb +23 -0
- data/lib/notion/api/error.rb +6 -0
- data/lib/notion/api/errors/internal_error.rb +12 -0
- data/lib/notion/api/errors/notion_error.rb +15 -0
- data/lib/notion/api/errors/too_many_requests.rb +15 -0
- data/lib/notion/api/errors.rb +23 -0
- data/lib/notion/client.rb +28 -0
- data/lib/notion/config.rb +54 -0
- data/lib/notion/faraday/connection.rb +37 -0
- data/lib/notion/faraday/request.rb +45 -0
- data/lib/notion/faraday/response/raise_error.rb +31 -0
- data/lib/notion/faraday/response/wrap_error.rb +22 -0
- data/lib/notion/logger.rb +14 -0
- data/lib/notion/messages/message.rb +17 -0
- data/lib/notion/pagination/cursor.rb +53 -0
- data/lib/notion/version.rb +5 -0
- data/lib/notion-ruby-client.rb +28 -0
- data/lib/notion.rb +2 -0
- data/lib/notion_ruby_client.rb +2 -0
- data/notionrb.gemspec +31 -0
- data/spec/fixtures/notion/block.yml +146 -0
- data/spec/fixtures/notion/block_append_children.yml +149 -0
- data/spec/fixtures/notion/block_children.yml +152 -0
- data/spec/fixtures/notion/create_data_source.yml +29 -0
- data/spec/fixtures/notion/create_database.yml +149 -0
- data/spec/fixtures/notion/create_discussion_comment.yml +110 -0
- data/spec/fixtures/notion/create_page.yml +152 -0
- data/spec/fixtures/notion/create_page_comment.yml +110 -0
- data/spec/fixtures/notion/create_page_with_data_source.yml +29 -0
- data/spec/fixtures/notion/create_page_with_parent_page.yml +128 -0
- data/spec/fixtures/notion/data_source.yml +27 -0
- data/spec/fixtures/notion/data_source_query.yml +29 -0
- data/spec/fixtures/notion/database.yml +150 -0
- data/spec/fixtures/notion/database_query.yml +154 -0
- data/spec/fixtures/notion/delete_block.yml +145 -0
- data/spec/fixtures/notion/page.yml +150 -0
- data/spec/fixtures/notion/page_property_item.yml +143 -0
- data/spec/fixtures/notion/paginated_block_children.yml +575 -0
- data/spec/fixtures/notion/paginated_data_source_query.yml +29 -0
- data/spec/fixtures/notion/paginated_database_query.yml +152 -0
- data/spec/fixtures/notion/paginated_databases_list.yml +150 -0
- data/spec/fixtures/notion/paginated_search.yml +301 -0
- data/spec/fixtures/notion/paginated_users_list.yml +146 -0
- data/spec/fixtures/notion/retrieve_comments.yml +106 -0
- data/spec/fixtures/notion/search.yml +160 -0
- data/spec/fixtures/notion/search_with_query.yml +152 -0
- data/spec/fixtures/notion/update_block.yml +148 -0
- data/spec/fixtures/notion/update_data_source.yml +29 -0
- data/spec/fixtures/notion/update_database.yml +152 -0
- data/spec/fixtures/notion/update_page.yml +152 -0
- data/spec/fixtures/notion/users.yml +145 -0
- data/spec/fixtures/notion/users_list.yml +146 -0
- data/spec/fixtures/notion/users_me.yml +144 -0
- data/spec/notion/api/endpoints/blocks_spec.rb +72 -0
- data/spec/notion/api/endpoints/comments_spec.rb +49 -0
- data/spec/notion/api/endpoints/data_sources_spec.rb +61 -0
- data/spec/notion/api/endpoints/databases_spec.rb +70 -0
- data/spec/notion/api/endpoints/pages_spec.rb +127 -0
- data/spec/notion/api/endpoints/search_spec.rb +26 -0
- data/spec/notion/api/endpoints/users_spec.rb +31 -0
- data/spec/notion/config_spec.rb +16 -0
- data/spec/notion/pagination/cursor_spec.rb +126 -0
- data/spec/notion/version_spec.rb +8 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/token.rb +10 -0
- data/spec/support/vcr.rb +16 -0
- metadata +358 -0
data/bin/console
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "dotenv/load"
|
|
6
|
+
require "notion-ruby-client"
|
|
7
|
+
|
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
10
|
+
|
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
12
|
+
# require "pry"
|
|
13
|
+
# Pry.start
|
|
14
|
+
|
|
15
|
+
require "irb"
|
|
16
|
+
|
|
17
|
+
def reload!(print = true)
|
|
18
|
+
puts 'Reloading ...' if print
|
|
19
|
+
# Main project directory.
|
|
20
|
+
root_dir = File.expand_path('..', __dir__)
|
|
21
|
+
# Directories within the project that should be reloaded.
|
|
22
|
+
reload_dirs = %w{lib}
|
|
23
|
+
# Loop through and reload every file in all relevant project directories.
|
|
24
|
+
reload_dirs.each do |dir|
|
|
25
|
+
Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
|
|
26
|
+
end
|
|
27
|
+
# Return true when complete.
|
|
28
|
+
true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
IRB.start(__FILE__)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Notion
|
|
4
|
+
module Api
|
|
5
|
+
module Endpoints
|
|
6
|
+
module Blocks
|
|
7
|
+
#
|
|
8
|
+
# Retrieves a Block object using the ID specified.
|
|
9
|
+
#
|
|
10
|
+
# @option options [id] :block_id
|
|
11
|
+
# Block to get children info on.
|
|
12
|
+
def block(options = {})
|
|
13
|
+
throw ArgumentError.new('Required arguments :block_id missing') if options[:block_id].nil?
|
|
14
|
+
get("blocks/#{options[:block_id]}")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
# Updates the content for the specified block_id based on
|
|
19
|
+
# the block type. Supported fields based on the block object
|
|
20
|
+
# type (see Block object for available fields and the
|
|
21
|
+
# expected input for each field).
|
|
22
|
+
#
|
|
23
|
+
# @option options [id] :block_id
|
|
24
|
+
# Block to get children info on.
|
|
25
|
+
#
|
|
26
|
+
# @option options [string] {type}
|
|
27
|
+
# The block object type value with the properties to be
|
|
28
|
+
# updated. Currently only text (for supported block types)
|
|
29
|
+
# and checked (for to_do blocks) fields can be updated.
|
|
30
|
+
def update_block(options = {})
|
|
31
|
+
block_id = options.delete(:block_id)
|
|
32
|
+
throw ArgumentError.new('Required arguments :block_id missing') if block_id.nil?
|
|
33
|
+
patch("blocks/#{block_id}", options)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Sets a Block object, including page blocks, to archived: true
|
|
38
|
+
# using the ID specified. Note: in the Notion UI application, this
|
|
39
|
+
# moves the block to the "Trash" where it can still be accessed and
|
|
40
|
+
# restored.
|
|
41
|
+
#
|
|
42
|
+
# To restore the block with the API, use the Update a block or
|
|
43
|
+
# Update page respectively.
|
|
44
|
+
#
|
|
45
|
+
# @option options [id] :block_id
|
|
46
|
+
# Block to get children info on.
|
|
47
|
+
def delete_block(options = {})
|
|
48
|
+
throw ArgumentError.new('Required arguments :block_id missing') if options[:block_id].nil?
|
|
49
|
+
delete("blocks/#{options[:block_id]}")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
#
|
|
53
|
+
# Returns a paginated array of Block objects contained in the
|
|
54
|
+
# block of the requested path using the ID specified.
|
|
55
|
+
#
|
|
56
|
+
# Returns a 404 HTTP response if any of the following are true:
|
|
57
|
+
# - the ID does not exist
|
|
58
|
+
# - the bot doesn't have access to the block with the given ID
|
|
59
|
+
#
|
|
60
|
+
# Returns a 400 or 429 HTTP response if the request exceeds Notion's Request limits.
|
|
61
|
+
#
|
|
62
|
+
# @option options [id] :block_id
|
|
63
|
+
# Block to get children info on.
|
|
64
|
+
def block_children(options = {})
|
|
65
|
+
throw ArgumentError.new('Required arguments :block_id missing') if options[:block_id].nil?
|
|
66
|
+
if block_given?
|
|
67
|
+
Pagination::Cursor.new(self, :block_children, options).each do |page|
|
|
68
|
+
yield page
|
|
69
|
+
end
|
|
70
|
+
else
|
|
71
|
+
block_id = options.delete(:block_id)
|
|
72
|
+
get("blocks/#{block_id}/children", options)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#
|
|
77
|
+
# Creates and appends new children blocks to the parent block
|
|
78
|
+
# in the requested path using the ID specified. Returns the Block
|
|
79
|
+
# object being appended to.
|
|
80
|
+
#
|
|
81
|
+
# Returns a 404 HTTP response if any of the following are true:
|
|
82
|
+
# - the ID does not exist
|
|
83
|
+
# - the bot doesn't have access to the block with the given ID
|
|
84
|
+
#
|
|
85
|
+
# Returns a 400 or 429 HTTP response if the request exceeds Notion's Request limits.
|
|
86
|
+
#
|
|
87
|
+
# @option options [id] :block_id
|
|
88
|
+
# Block to append children to.
|
|
89
|
+
#
|
|
90
|
+
# @option options [[Object]] :children
|
|
91
|
+
# Children blocks to append
|
|
92
|
+
def block_append_children(options = {})
|
|
93
|
+
block_id = options.delete(:block_id)
|
|
94
|
+
throw ArgumentError.new('Required arguments :block_id missing') if block_id.nil?
|
|
95
|
+
patch("blocks/#{block_id}/children", options)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Notion
|
|
3
|
+
module Api
|
|
4
|
+
module Endpoints
|
|
5
|
+
module Comments
|
|
6
|
+
#
|
|
7
|
+
# Retrieves a list of un-resolved Comment objects from a page or block.
|
|
8
|
+
#
|
|
9
|
+
# @option options [id] :block_id
|
|
10
|
+
# Block or page id to fetch comments for.
|
|
11
|
+
#
|
|
12
|
+
# @option options [start_cursor] :start_cursor
|
|
13
|
+
# If supplied, this endpoint will return a page
|
|
14
|
+
# of results starting after the cursor provided.
|
|
15
|
+
# If not supplied, this endpoint will return the
|
|
16
|
+
# first page of results.
|
|
17
|
+
#
|
|
18
|
+
# @option options [page_size] :page_size
|
|
19
|
+
# The number of items from the full list desired in the response.
|
|
20
|
+
# Maximum: 100
|
|
21
|
+
#
|
|
22
|
+
def retrieve_comments(options = {})
|
|
23
|
+
throw ArgumentError.new('Required arguments :block_id missing') if options[:block_id].nil?
|
|
24
|
+
if block_given?
|
|
25
|
+
Pagination::Cursor.new(self, :retrieve_comments, options).each do |page|
|
|
26
|
+
yield page
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
get('comments', options)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# Creates a comment in a page or existing discussion thread.
|
|
35
|
+
# There are two locations you can add a new comment to:
|
|
36
|
+
# - A page
|
|
37
|
+
# - An existing discussion thread
|
|
38
|
+
# If the intention is to add a new comment to a page, a parent object
|
|
39
|
+
# must be provided in the body params. Alternatively, if a new comment
|
|
40
|
+
# is being added to an existing discussion thread, the discussion_id string
|
|
41
|
+
# must be provided in the body params. Exactly one of these parameters must be provided.
|
|
42
|
+
#
|
|
43
|
+
# @option options [Object] :parent
|
|
44
|
+
# A page parent. Either this or a discussion_id is required (not both).
|
|
45
|
+
#
|
|
46
|
+
# @option options [UUID] :discussion_id
|
|
47
|
+
# A UUID identifier for a discussion thread. Either this or a parent object is required (not both).
|
|
48
|
+
#
|
|
49
|
+
# @option options [Object] :rich_text
|
|
50
|
+
# A rich text object.
|
|
51
|
+
def create_comment(options = {})
|
|
52
|
+
if options.dig(:parent, :page_id).nil? && options[:discussion_id].nil?
|
|
53
|
+
throw ArgumentError.new('Required argument :page_id or :discussion_id missing')
|
|
54
|
+
end
|
|
55
|
+
throw ArgumentError.new('Required argument :rich_text missing') if options[:rich_text].nil?
|
|
56
|
+
post('comments', options)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Notion
|
|
4
|
+
module Api
|
|
5
|
+
module Endpoints
|
|
6
|
+
module DataSources
|
|
7
|
+
#
|
|
8
|
+
# Gets a paginated array of Page objects contained in the requested data source,
|
|
9
|
+
# filtered and ordered according to the filter and sort objects provided in the request.
|
|
10
|
+
#
|
|
11
|
+
# Starting with Notion-Version 2025-09-03, databases can contain multiple data
|
|
12
|
+
# sources. Querying is done against a data source, not the database itself.
|
|
13
|
+
# Use #database to look up a database's data source ids.
|
|
14
|
+
#
|
|
15
|
+
# @option options [id] :data_source_id
|
|
16
|
+
# Data source to query.
|
|
17
|
+
#
|
|
18
|
+
# @option options [Object] :filter
|
|
19
|
+
# When supplied, limits which pages are returned based on the provided criteria.
|
|
20
|
+
#
|
|
21
|
+
# @option options [[Object]] :sorts
|
|
22
|
+
# When supplied, sorts the results based on the provided criteria.
|
|
23
|
+
#
|
|
24
|
+
# @option options [UUID] :start_cursor
|
|
25
|
+
# Paginate through collections of data by setting the cursor parameter
|
|
26
|
+
# to a start_cursor attribute returned by a previous request's next_cursor.
|
|
27
|
+
# Default value fetches the first "page" of the collection.
|
|
28
|
+
# See pagination for more detail.
|
|
29
|
+
#
|
|
30
|
+
# @option options [integer] :page_size
|
|
31
|
+
# The number of items from the full list desired in the response. Maximum: 100
|
|
32
|
+
def data_source_query(options = {})
|
|
33
|
+
throw ArgumentError.new('Required arguments :data_source_id missing') if options[:data_source_id].nil?
|
|
34
|
+
if block_given?
|
|
35
|
+
Pagination::Cursor.new(self, :data_source_query, options).each do |page|
|
|
36
|
+
yield page
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
data_source_id = options.delete(:data_source_id)
|
|
40
|
+
post("data_sources/#{data_source_id}/query", options)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#
|
|
45
|
+
# Adds a new data source to an existing database.
|
|
46
|
+
#
|
|
47
|
+
# @option options [Object] :parent
|
|
48
|
+
# Parent of the data source, referencing an existing database via :database_id.
|
|
49
|
+
#
|
|
50
|
+
# @option options [Object] :properties
|
|
51
|
+
# Property schema of data source.
|
|
52
|
+
# The keys are the names of properties as they appear in Notion and the values are
|
|
53
|
+
# property schema objects. Each data source must have exactly one property schema
|
|
54
|
+
# object of type "title".
|
|
55
|
+
#
|
|
56
|
+
# @option options [Object] :title
|
|
57
|
+
# Title of this data source.
|
|
58
|
+
def create_data_source(options = {})
|
|
59
|
+
throw ArgumentError.new('Required arguments :parent.database_id missing') if options.dig(:parent, :database_id).nil?
|
|
60
|
+
throw ArgumentError.new('Required arguments :properties missing') if options.dig(:properties).nil?
|
|
61
|
+
post('data_sources', options)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
#
|
|
65
|
+
# Updates an existing data source as specified by the parameters.
|
|
66
|
+
#
|
|
67
|
+
# @option options [id] :data_source_id
|
|
68
|
+
# Data source to update.
|
|
69
|
+
#
|
|
70
|
+
# @option options [Object] :title
|
|
71
|
+
# Title of data source as it appears in Notion. An array of rich text objects.
|
|
72
|
+
# If omitted, the title will remain unchanged.
|
|
73
|
+
#
|
|
74
|
+
# @option options [Object] :properties
|
|
75
|
+
# Updates to the property schema of a data source.
|
|
76
|
+
# If updating an existing property, the keys are the names or IDs
|
|
77
|
+
# of the properties as they appear in Notion and the values
|
|
78
|
+
# are property schema objects. If adding a new property, the key is
|
|
79
|
+
# the name of the property and the value is a property schema object.
|
|
80
|
+
def update_data_source(options = {})
|
|
81
|
+
data_source_id = options.delete(:data_source_id)
|
|
82
|
+
throw ArgumentError.new('Required arguments :data_source_id missing') if data_source_id.nil?
|
|
83
|
+
patch("data_sources/#{data_source_id}", options)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
#
|
|
87
|
+
# Retrieves a Data source object using the ID specified in the request.
|
|
88
|
+
#
|
|
89
|
+
# Returns a 404 HTTP response if the data source doesn't exist, or if the bot
|
|
90
|
+
# doesn't have access to the data source. Returns a 429 HTTP response if the
|
|
91
|
+
# request exceeds Notion's Request limits.
|
|
92
|
+
#
|
|
93
|
+
# @option options [id] :data_source_id
|
|
94
|
+
# Data source to get info on.
|
|
95
|
+
def data_source(options = {})
|
|
96
|
+
throw ArgumentError.new('Required arguments :data_source_id missing') if options[:data_source_id].nil?
|
|
97
|
+
get("data_sources/#{options[:data_source_id]}")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Notion
|
|
4
|
+
module Api
|
|
5
|
+
module Endpoints
|
|
6
|
+
module Databases
|
|
7
|
+
#
|
|
8
|
+
# Gets a paginated array of Page object s contained in the requested database,
|
|
9
|
+
# filtered and ordered according to the filter and sort objects provided in the request.
|
|
10
|
+
#
|
|
11
|
+
# Filters are similar to the filters provided in the Notion UI. Filters operate
|
|
12
|
+
# on database properties and can be combined. If no filter is provided, all the
|
|
13
|
+
# pages in the database will be returned with pagination.
|
|
14
|
+
#
|
|
15
|
+
# Sorts are similar to the sorts provided in the Notion UI. Sorts operate on
|
|
16
|
+
# database properties and can be combined. The order of the sorts in the request
|
|
17
|
+
# matter, with earlier sorts taking precedence over later ones.
|
|
18
|
+
#
|
|
19
|
+
# @deprecated As of Notion-Version 2025-09-03, databases can hold multiple data
|
|
20
|
+
# sources, and querying is performed against a data source id, not a database
|
|
21
|
+
# id. Use {#data_source_query} instead, resolving the data source id via
|
|
22
|
+
# {#database}'s :data_sources field.
|
|
23
|
+
#
|
|
24
|
+
# @option options [id] :database_id
|
|
25
|
+
# Database to query.
|
|
26
|
+
#
|
|
27
|
+
# @option options [Object] :filter
|
|
28
|
+
# When supplied, limits which pages are returned based on the provided criteria.
|
|
29
|
+
#
|
|
30
|
+
# @option options [[Object]] :sorts
|
|
31
|
+
# When supplied, sorts the results based on the provided criteria.
|
|
32
|
+
#
|
|
33
|
+
# @option options [UUID] :start_cursor
|
|
34
|
+
# Paginate through collections of data by setting the cursor parameter
|
|
35
|
+
# to a start_cursor attribute returned by a previous request's next_cursor.
|
|
36
|
+
# Default value fetches the first "page" of the collection.
|
|
37
|
+
# See pagination for more detail.
|
|
38
|
+
#
|
|
39
|
+
# @option options [integer] :page_size
|
|
40
|
+
# The number of items from the full list desired in the response. Maximum: 100
|
|
41
|
+
def database_query(options = {})
|
|
42
|
+
throw ArgumentError.new('Required arguments :database_id missing') if options[:database_id].nil?
|
|
43
|
+
logger.warn('[DEPRECATED] #database_query is deprecated as of Notion-Version 2025-09-03 ' \
|
|
44
|
+
'and only works for databases with a single data source. Use #data_source_query instead.')
|
|
45
|
+
if block_given?
|
|
46
|
+
Pagination::Cursor.new(self, :database_query, options).each do |page|
|
|
47
|
+
yield page
|
|
48
|
+
end
|
|
49
|
+
else
|
|
50
|
+
database_id = options.delete(:database_id)
|
|
51
|
+
post("databases/#{database_id}/query", options)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
#
|
|
56
|
+
# Creates a new database, with a single data source, in the specified page.
|
|
57
|
+
#
|
|
58
|
+
# As of Notion-Version 2025-09-03, the property schema is nested under
|
|
59
|
+
# :initial_data_source instead of being a top-level :properties argument. For
|
|
60
|
+
# convenience, a top-level :properties option is still accepted here and is
|
|
61
|
+
# wrapped into :initial_data_source automatically.
|
|
62
|
+
#
|
|
63
|
+
# @option options [Object] :parent
|
|
64
|
+
# Parent of the database, which is always going to be a page.
|
|
65
|
+
#
|
|
66
|
+
# @option options [Object] :title
|
|
67
|
+
# Title of this database.
|
|
68
|
+
#
|
|
69
|
+
# @option options [Object] :initial_data_source
|
|
70
|
+
# The initial data source for this database, e.g. { properties: { ... } }.
|
|
71
|
+
#
|
|
72
|
+
# @option options [Object] :properties
|
|
73
|
+
# Shorthand for initial_data_source[:properties]. Property schema of the
|
|
74
|
+
# database's initial data source.
|
|
75
|
+
# The keys are the names of properties as they appear in Notion and the values are
|
|
76
|
+
# property schema objects. Property Schema Object is a metadata that controls
|
|
77
|
+
# how a database property behaves, e.g. {"checkbox": {}}.
|
|
78
|
+
# Each database must have exactly one database property schema object of type "title".
|
|
79
|
+
def create_database(options = {})
|
|
80
|
+
throw ArgumentError.new('Required arguments :parent.page_id missing') if options.dig(:parent, :page_id).nil?
|
|
81
|
+
throw ArgumentError.new('Required arguments :title missing') if options.dig(:title).nil?
|
|
82
|
+
|
|
83
|
+
properties = options.delete(:properties)
|
|
84
|
+
if options[:initial_data_source].nil?
|
|
85
|
+
throw ArgumentError.new('Required arguments :properties missing') if properties.nil?
|
|
86
|
+
|
|
87
|
+
options[:initial_data_source] = { properties: properties }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
post('databases', options)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
# Updates an existing database as specified by the parameters.
|
|
95
|
+
#
|
|
96
|
+
# As of Notion-Version 2025-09-03, this endpoint only accepts database-level
|
|
97
|
+
# fields (:title, :description, :icon, :cover, :is_inline, :in_trash,
|
|
98
|
+
# :is_locked, :parent). Updating a :properties schema is now done per data
|
|
99
|
+
# source via {#update_data_source}.
|
|
100
|
+
#
|
|
101
|
+
# @option options [id] :database_id
|
|
102
|
+
# Database to update.
|
|
103
|
+
#
|
|
104
|
+
# @option options [Object] :title
|
|
105
|
+
# Title of database as it appears in Notion. An array of rich text objects.
|
|
106
|
+
# If omitted, the database title will remain unchanged.
|
|
107
|
+
#
|
|
108
|
+
def update_database(options = {})
|
|
109
|
+
database_id = options.delete(:database_id)
|
|
110
|
+
throw ArgumentError.new('Required arguments :database_id missing') if database_id.nil?
|
|
111
|
+
patch("databases/#{database_id}", options)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
#
|
|
115
|
+
# Retrieves a Database object using the ID specified in the request.
|
|
116
|
+
#
|
|
117
|
+
# Returns a 404 HTTP response if the database doesn't exist, or if the bot
|
|
118
|
+
# doesn't have access to the database. Returns a 429 HTTP response if the
|
|
119
|
+
# request exceeds Notion's Request limits.
|
|
120
|
+
#
|
|
121
|
+
# As of Notion-Version 2025-09-03, the response's :data_sources field lists
|
|
122
|
+
# the data source ids and names that belong to this database, for use with
|
|
123
|
+
# {#data_source_query}, {#data_source} and {#update_data_source}.
|
|
124
|
+
#
|
|
125
|
+
# @option options [id] :database_id
|
|
126
|
+
# Database to get info on.
|
|
127
|
+
def database(options = {})
|
|
128
|
+
throw ArgumentError.new('Required arguments :database_id missing') if options[:database_id].nil?
|
|
129
|
+
get("databases/#{options[:database_id]}")
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Notion
|
|
4
|
+
module Api
|
|
5
|
+
module Endpoints
|
|
6
|
+
module Pages
|
|
7
|
+
#
|
|
8
|
+
# Retrieves a 📄Page object using the ID specified in the request path.
|
|
9
|
+
# Note that this version of the API only exposes page properties, not page content
|
|
10
|
+
#
|
|
11
|
+
# @option options [id] :page_id
|
|
12
|
+
# Page to get info on.
|
|
13
|
+
#
|
|
14
|
+
# @option options [bool] :archived
|
|
15
|
+
# Set to true to retrieve an archived page; must be false or omitted to
|
|
16
|
+
# retrieve a page that has not been archived. Defaults to false.
|
|
17
|
+
def page(options = {})
|
|
18
|
+
throw ArgumentError.new('Required argument :page_id missing') if options[:page_id].nil?
|
|
19
|
+
get("pages/#{options[:page_id]}")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# Creates a new page in the specified database (or data source) or as a child of an existing page.
|
|
24
|
+
# Note that this iteration of the API will only expose page properties, not
|
|
25
|
+
# page content, as described in the data model.
|
|
26
|
+
#
|
|
27
|
+
# As of Notion-Version 2025-09-03, pages should be created under a data source
|
|
28
|
+
# (:parent.data_source_id) rather than a database. :parent.database_id remains
|
|
29
|
+
# supported for databases with a single data source.
|
|
30
|
+
#
|
|
31
|
+
# @option options [Object] :parent
|
|
32
|
+
# Parent of the page: a data source, a database, or a page.
|
|
33
|
+
#
|
|
34
|
+
# @option options [Object] :properties
|
|
35
|
+
# Properties of this page.
|
|
36
|
+
# The schema for the page's keys and values is described by the properties of
|
|
37
|
+
# the data source this page belongs to. key string Name of a property as it
|
|
38
|
+
# appears in Notion, or property ID. value object Object containing a value
|
|
39
|
+
# specific to the property type, e.g. {"checkbox": true}.
|
|
40
|
+
#
|
|
41
|
+
# @option options [Object] :children
|
|
42
|
+
# An optional array of Block objects representing the Page’s content
|
|
43
|
+
def create_page(options = {})
|
|
44
|
+
if options.dig(:parent, :data_source_id).nil? &&
|
|
45
|
+
options.dig(:parent, :database_id).nil? &&
|
|
46
|
+
options.dig(:parent, :page_id).nil?
|
|
47
|
+
throw ArgumentError.new('Required argument :parent.data_source_id, :parent.database_id or :parent.page_id required')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
post("pages", options)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#
|
|
54
|
+
# Updates a page by setting the values of any properties specified in the
|
|
55
|
+
# JSON body of the request. Properties that are not set via parameters will
|
|
56
|
+
# remain unchanged.
|
|
57
|
+
#
|
|
58
|
+
# Note that this iteration of the API will only expose page properties, not page
|
|
59
|
+
# content, as described in the data model.
|
|
60
|
+
#
|
|
61
|
+
# @option options [id] :page_id
|
|
62
|
+
# Page to get info on.
|
|
63
|
+
#
|
|
64
|
+
# @option options [Object] :properties
|
|
65
|
+
# Properties of this page.
|
|
66
|
+
# The schema for the page's keys and values is described by the properties of
|
|
67
|
+
# the database this page belongs to. key string Name of a property as it
|
|
68
|
+
# appears in Notion, or property ID. value object Object containing a value
|
|
69
|
+
# specific to the property type, e.g. {"checkbox": true}.
|
|
70
|
+
def update_page(options = {})
|
|
71
|
+
page_id = options.delete(:page_id)
|
|
72
|
+
throw ArgumentError.new('Required argument :page_id missing') if page_id.nil?
|
|
73
|
+
patch("pages/#{page_id}", options)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#
|
|
77
|
+
# Retrieves a `property_item` object for a given `page_id` and `property_id`.
|
|
78
|
+
# Depending on the property type, the object returned will either be a value
|
|
79
|
+
# or a paginated list of property item values.
|
|
80
|
+
#
|
|
81
|
+
# @option options [id] :page_id
|
|
82
|
+
# Page to get info on.
|
|
83
|
+
#
|
|
84
|
+
# @option options [id] :property_id
|
|
85
|
+
# Property to get info on.
|
|
86
|
+
#
|
|
87
|
+
def page_property_item(options = {})
|
|
88
|
+
throw ArgumentError.new('Required argument :page_id missing') if options[:page_id].nil?
|
|
89
|
+
throw ArgumentError.new('Required argument :property_id missing') if options[:property_id].nil?
|
|
90
|
+
get("pages/#{options[:page_id]}/properties/#{options[:property_id]}")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Notion
|
|
4
|
+
module Api
|
|
5
|
+
module Endpoints
|
|
6
|
+
module Search
|
|
7
|
+
#
|
|
8
|
+
# Searches all pages and child pages that are shared with the integration.
|
|
9
|
+
# The results may include databases.
|
|
10
|
+
#
|
|
11
|
+
# @option options [string] :query
|
|
12
|
+
# When supplied, limits which pages are returned by comparing the query to the page title.
|
|
13
|
+
#
|
|
14
|
+
# @option options [Object] :filter
|
|
15
|
+
# When supplied, filters the results based on the provided criteria.
|
|
16
|
+
#
|
|
17
|
+
# @option options [[Object]] :sorts
|
|
18
|
+
# When supplied, sorts the results based on the provided criteria.
|
|
19
|
+
# Limitation: Currently only a single sort is allowed and is limited to last_edited_time.
|
|
20
|
+
#
|
|
21
|
+
# @option options [UUID] :start_cursor
|
|
22
|
+
# Paginate through collections of data by setting the cursor parameter
|
|
23
|
+
# to a start_cursor attribute returned by a previous request's next_cursor.
|
|
24
|
+
# Default value fetches the first "page" of the collection.
|
|
25
|
+
# See pagination for more detail.
|
|
26
|
+
#
|
|
27
|
+
# @option options [integer] :page_size
|
|
28
|
+
# The number of items from the full list desired in the response. Maximum: 100
|
|
29
|
+
def search(options = {})
|
|
30
|
+
if block_given?
|
|
31
|
+
Pagination::Cursor.new(self, :search, options).each do |page|
|
|
32
|
+
yield page
|
|
33
|
+
end
|
|
34
|
+
else
|
|
35
|
+
post('search', options)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Notion
|
|
4
|
+
module Api
|
|
5
|
+
module Endpoints
|
|
6
|
+
module Users
|
|
7
|
+
#
|
|
8
|
+
# Retrieves the bot User associated with the API token provided in
|
|
9
|
+
# the authorization header. The bot will have an `owner` field with
|
|
10
|
+
# information about the person who authorized the integration.
|
|
11
|
+
def me
|
|
12
|
+
get("users/me")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
#
|
|
16
|
+
# Retrieves a User object using the ID specified in the request.
|
|
17
|
+
#
|
|
18
|
+
# @option options [id] :user_id
|
|
19
|
+
# User to get info on.
|
|
20
|
+
def user(options = {})
|
|
21
|
+
throw ArgumentError.new('Required arguments :user_id missing') if options[:user_id].nil?
|
|
22
|
+
get("users/#{options[:user_id]}")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#
|
|
26
|
+
# Returns a paginated list of User objects for the workspace.
|
|
27
|
+
#
|
|
28
|
+
# @option options [UUID] :start_cursor
|
|
29
|
+
# Paginate through collections of data by setting the cursor parameter
|
|
30
|
+
# to a start_cursor attribute returned by a previous request's next_cursor.
|
|
31
|
+
# Default value fetches the first "page" of the collection.
|
|
32
|
+
# See pagination for more detail.
|
|
33
|
+
#
|
|
34
|
+
# @option options [integer] :page_size
|
|
35
|
+
# The number of items from the full list desired in the response. Maximum: 100
|
|
36
|
+
def users_list(options = {})
|
|
37
|
+
if block_given?
|
|
38
|
+
Pagination::Cursor.new(self, :users_list, options).each do |page|
|
|
39
|
+
yield page
|
|
40
|
+
end
|
|
41
|
+
else
|
|
42
|
+
get("users", options)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'endpoints/blocks'
|
|
4
|
+
require_relative 'endpoints/databases'
|
|
5
|
+
require_relative 'endpoints/data_sources'
|
|
6
|
+
require_relative 'endpoints/pages'
|
|
7
|
+
require_relative 'endpoints/users'
|
|
8
|
+
require_relative 'endpoints/search'
|
|
9
|
+
require_relative 'endpoints/comments'
|
|
10
|
+
|
|
11
|
+
module Notion
|
|
12
|
+
module Api
|
|
13
|
+
module Endpoints
|
|
14
|
+
include Blocks
|
|
15
|
+
include Databases
|
|
16
|
+
include DataSources
|
|
17
|
+
include Pages
|
|
18
|
+
include Users
|
|
19
|
+
include Search
|
|
20
|
+
include Comments
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Notion
|
|
3
|
+
module Api
|
|
4
|
+
module Errors
|
|
5
|
+
class ServerError < InternalError; end
|
|
6
|
+
class ParsingError < ServerError; end
|
|
7
|
+
class HttpRequestError < ServerError; end
|
|
8
|
+
class TimeoutError < HttpRequestError; end
|
|
9
|
+
class UnavailableError < HttpRequestError; end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Notion
|
|
3
|
+
module Api
|
|
4
|
+
module Errors
|
|
5
|
+
class NotionError < ::Faraday::Error
|
|
6
|
+
attr_reader :response
|
|
7
|
+
|
|
8
|
+
def initialize(message, details, response = nil)
|
|
9
|
+
super("#{message} #{details}")
|
|
10
|
+
@response = response
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|