notion-sdk-ruby 0.3.1 → 0.4.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 +4 -4
- data/.github/workflows/ci.yml +34 -34
- data/.gitignore +13 -13
- data/.rspec +3 -3
- data/.travis.yml +6 -6
- data/.vscode/settings.json +3 -3
- data/Gemfile +4 -4
- data/Gemfile.lock +3 -3
- data/LICENSE.txt +21 -21
- data/README.md +263 -263
- data/Rakefile +7 -7
- data/bin/console +11 -11
- data/bin/setup +8 -8
- data/lib/notion-sdk-ruby.rb +27 -27
- data/lib/notion-sdk-ruby/client.rb +26 -26
- data/lib/notion-sdk-ruby/config.rb +5 -5
- data/lib/notion-sdk-ruby/error.rb +52 -52
- data/lib/notion-sdk-ruby/operations/search.rb +9 -9
- data/lib/notion-sdk-ruby/request_client.rb +50 -50
- data/lib/notion-sdk-ruby/resources/blocks.rb +17 -17
- data/lib/notion-sdk-ruby/resources/databases.rb +19 -15
- data/lib/notion-sdk-ruby/resources/pages.rb +15 -15
- data/lib/notion-sdk-ruby/resources/users.rb +11 -11
- data/lib/notion-sdk-ruby/version.rb +3 -3
- data/notion-sdk-ruby.gemspec +37 -37
- metadata +7 -7
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
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/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
|
data/lib/notion-sdk-ruby.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
require "httparty"
|
2
|
-
require "forwardable"
|
3
|
-
|
4
|
-
require "notion-sdk-ruby/version"
|
5
|
-
|
6
|
-
require "notion-sdk-ruby/config"
|
7
|
-
require "notion-sdk-ruby/resources/blocks"
|
8
|
-
require "notion-sdk-ruby/resources/databases"
|
9
|
-
require "notion-sdk-ruby/resources/pages"
|
10
|
-
require "notion-sdk-ruby/resources/users"
|
11
|
-
require "notion-sdk-ruby/operations/search"
|
12
|
-
require "notion-sdk-ruby/error"
|
13
|
-
require "notion-sdk-ruby/request_client"
|
14
|
-
require "notion-sdk-ruby/client"
|
15
|
-
|
16
|
-
module Notion
|
17
|
-
@config = Config.new
|
18
|
-
|
19
|
-
class << self
|
20
|
-
extend Forwardable
|
21
|
-
|
22
|
-
attr_reader :config
|
23
|
-
|
24
|
-
def_delegators :@config, :api_token, :api_token=
|
25
|
-
def_delegators :@config, :notion_version, :notion_version=
|
26
|
-
end
|
27
|
-
end
|
1
|
+
require "httparty"
|
2
|
+
require "forwardable"
|
3
|
+
|
4
|
+
require "notion-sdk-ruby/version"
|
5
|
+
|
6
|
+
require "notion-sdk-ruby/config"
|
7
|
+
require "notion-sdk-ruby/resources/blocks"
|
8
|
+
require "notion-sdk-ruby/resources/databases"
|
9
|
+
require "notion-sdk-ruby/resources/pages"
|
10
|
+
require "notion-sdk-ruby/resources/users"
|
11
|
+
require "notion-sdk-ruby/operations/search"
|
12
|
+
require "notion-sdk-ruby/error"
|
13
|
+
require "notion-sdk-ruby/request_client"
|
14
|
+
require "notion-sdk-ruby/client"
|
15
|
+
|
16
|
+
module Notion
|
17
|
+
@config = Config.new
|
18
|
+
|
19
|
+
class << self
|
20
|
+
extend Forwardable
|
21
|
+
|
22
|
+
attr_reader :config
|
23
|
+
|
24
|
+
def_delegators :@config, :api_token, :api_token=
|
25
|
+
def_delegators :@config, :notion_version, :notion_version=
|
26
|
+
end
|
27
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
module Notion
|
2
|
-
class Client
|
3
|
-
include Operations::Search
|
4
|
-
|
5
|
-
def initialize(token:, notion_version: "2021-05-13")
|
6
|
-
Notion.api_token = token
|
7
|
-
Notion.notion_version = notion_version
|
8
|
-
end
|
9
|
-
|
10
|
-
def blocks
|
11
|
-
Blocks.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def databases
|
15
|
-
Databases.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def pages
|
19
|
-
Pages.new
|
20
|
-
end
|
21
|
-
|
22
|
-
def users
|
23
|
-
Users.new
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
1
|
+
module Notion
|
2
|
+
class Client
|
3
|
+
include Operations::Search
|
4
|
+
|
5
|
+
def initialize(token:, notion_version: "2021-05-13")
|
6
|
+
Notion.api_token = token
|
7
|
+
Notion.notion_version = notion_version
|
8
|
+
end
|
9
|
+
|
10
|
+
def blocks
|
11
|
+
Blocks.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def databases
|
15
|
+
Databases.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def pages
|
19
|
+
Pages.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def users
|
23
|
+
Users.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module Notion
|
2
|
-
class Config
|
3
|
-
attr_accessor :api_token, :notion_version
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Notion
|
2
|
+
class Config
|
3
|
+
attr_accessor :api_token, :notion_version
|
4
|
+
end
|
5
|
+
end
|
@@ -1,52 +1,52 @@
|
|
1
|
-
# Sourced from notion-sdk-js:
|
2
|
-
# https://github.com/makenotion/notion-sdk-js/blob/main/src/errors.ts
|
3
|
-
module Notion
|
4
|
-
API_ERROR_CODE = {
|
5
|
-
unauthorized: "unauthorized",
|
6
|
-
restricted_resource: "restricted_resource",
|
7
|
-
object_not_found: "object_not_found",
|
8
|
-
rate_limited: "rate_limited",
|
9
|
-
invalid_json: "invalid_json",
|
10
|
-
invalid_request_url: "invalid_request_url",
|
11
|
-
invalid_request: "invalid_request",
|
12
|
-
validation_error: "validation_error",
|
13
|
-
conflict_error: "conflict_error",
|
14
|
-
internal_server_error: "internal_server_error",
|
15
|
-
service_unavailable: "service_unavailable"
|
16
|
-
}
|
17
|
-
|
18
|
-
class ErrorFactory
|
19
|
-
def self.create(error = {})
|
20
|
-
return NotionError.new("Unknown error.") if error["message"].nil?
|
21
|
-
|
22
|
-
if API_ERROR_CODE.value?(error["code"])
|
23
|
-
APIResponseError.new(error["message"], body: error)
|
24
|
-
elsif error["request"] && error["response"] && error["timings"]
|
25
|
-
HTTPResponseError.new(error["message"], body: error)
|
26
|
-
elsif error["request"] && error["timings"]
|
27
|
-
RequestTimeoutError.new(error["message"], body: error)
|
28
|
-
else
|
29
|
-
NotionError.new(error["message"])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class NotionError < StandardError
|
35
|
-
attr_reader :message, :body
|
36
|
-
|
37
|
-
def initialize(message = nil, body: nil)
|
38
|
-
@message = message
|
39
|
-
@body = body
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class RequestTimeoutError < NotionError; end
|
44
|
-
|
45
|
-
class HTTPResponseError < NotionError; end
|
46
|
-
|
47
|
-
class APIResponseError < NotionError
|
48
|
-
def code
|
49
|
-
body["code"]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
# Sourced from notion-sdk-js:
|
2
|
+
# https://github.com/makenotion/notion-sdk-js/blob/main/src/errors.ts
|
3
|
+
module Notion
|
4
|
+
API_ERROR_CODE = {
|
5
|
+
unauthorized: "unauthorized",
|
6
|
+
restricted_resource: "restricted_resource",
|
7
|
+
object_not_found: "object_not_found",
|
8
|
+
rate_limited: "rate_limited",
|
9
|
+
invalid_json: "invalid_json",
|
10
|
+
invalid_request_url: "invalid_request_url",
|
11
|
+
invalid_request: "invalid_request",
|
12
|
+
validation_error: "validation_error",
|
13
|
+
conflict_error: "conflict_error",
|
14
|
+
internal_server_error: "internal_server_error",
|
15
|
+
service_unavailable: "service_unavailable"
|
16
|
+
}
|
17
|
+
|
18
|
+
class ErrorFactory
|
19
|
+
def self.create(error = {})
|
20
|
+
return NotionError.new("Unknown error.") if error["message"].nil?
|
21
|
+
|
22
|
+
if API_ERROR_CODE.value?(error["code"])
|
23
|
+
APIResponseError.new(error["message"], body: error)
|
24
|
+
elsif error["request"] && error["response"] && error["timings"]
|
25
|
+
HTTPResponseError.new(error["message"], body: error)
|
26
|
+
elsif error["request"] && error["timings"]
|
27
|
+
RequestTimeoutError.new(error["message"], body: error)
|
28
|
+
else
|
29
|
+
NotionError.new(error["message"])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class NotionError < StandardError
|
35
|
+
attr_reader :message, :body
|
36
|
+
|
37
|
+
def initialize(message = nil, body: nil)
|
38
|
+
@message = message
|
39
|
+
@body = body
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class RequestTimeoutError < NotionError; end
|
44
|
+
|
45
|
+
class HTTPResponseError < NotionError; end
|
46
|
+
|
47
|
+
class APIResponseError < NotionError
|
48
|
+
def code
|
49
|
+
body["code"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module Notion
|
2
|
-
module Operations
|
3
|
-
module Search
|
4
|
-
def search(body)
|
5
|
-
RequestClient.active_client.post("/v1/search", body: body.to_json)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module Notion
|
2
|
+
module Operations
|
3
|
+
module Search
|
4
|
+
def search(body)
|
5
|
+
RequestClient.active_client.post("/v1/search", body: body.to_json)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
module Notion
|
2
|
-
class RequestClient
|
3
|
-
include HTTParty
|
4
|
-
|
5
|
-
base_uri "https://api.notion.com"
|
6
|
-
headers "Content-Type": "application/json"
|
7
|
-
|
8
|
-
def self.active_client
|
9
|
-
RequestClient.new(Notion.config)
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(config)
|
13
|
-
self.class.headers Authorization: "Bearer #{config.api_token}"
|
14
|
-
self.class.headers "Notion-Version": config.notion_version
|
15
|
-
end
|
16
|
-
|
17
|
-
def get(*args, &block)
|
18
|
-
response = self.class.get(*args, &block)
|
19
|
-
raise_on_failure(response)
|
20
|
-
end
|
21
|
-
|
22
|
-
def post(*args, &block)
|
23
|
-
response = self.class.post(*args, &block)
|
24
|
-
raise_on_failure(response)
|
25
|
-
end
|
26
|
-
|
27
|
-
def patch(*args, &block)
|
28
|
-
response = self.class.patch(*args, &block)
|
29
|
-
raise_on_failure(response)
|
30
|
-
end
|
31
|
-
|
32
|
-
def put(*args, &block)
|
33
|
-
response = self.class.put(*args, &block)
|
34
|
-
raise_on_failure(response)
|
35
|
-
end
|
36
|
-
|
37
|
-
def delete(*args, &block)
|
38
|
-
response = self.class.delete(*args, &block)
|
39
|
-
raise_on_failure(response)
|
40
|
-
end
|
41
|
-
|
42
|
-
def raise_on_failure(response)
|
43
|
-
if response.success?
|
44
|
-
response
|
45
|
-
else
|
46
|
-
raise ErrorFactory.create(response)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
module Notion
|
2
|
+
class RequestClient
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
base_uri "https://api.notion.com"
|
6
|
+
headers "Content-Type": "application/json"
|
7
|
+
|
8
|
+
def self.active_client
|
9
|
+
RequestClient.new(Notion.config)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(config)
|
13
|
+
self.class.headers Authorization: "Bearer #{config.api_token}"
|
14
|
+
self.class.headers "Notion-Version": config.notion_version
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(*args, &block)
|
18
|
+
response = self.class.get(*args, &block)
|
19
|
+
raise_on_failure(response)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(*args, &block)
|
23
|
+
response = self.class.post(*args, &block)
|
24
|
+
raise_on_failure(response)
|
25
|
+
end
|
26
|
+
|
27
|
+
def patch(*args, &block)
|
28
|
+
response = self.class.patch(*args, &block)
|
29
|
+
raise_on_failure(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def put(*args, &block)
|
33
|
+
response = self.class.put(*args, &block)
|
34
|
+
raise_on_failure(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(*args, &block)
|
38
|
+
response = self.class.delete(*args, &block)
|
39
|
+
raise_on_failure(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def raise_on_failure(response)
|
43
|
+
if response.success?
|
44
|
+
response
|
45
|
+
else
|
46
|
+
raise ErrorFactory.create(response)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module Notion
|
2
|
-
class Blocks
|
3
|
-
def children
|
4
|
-
Children.new
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
class Children
|
9
|
-
def list(block_id, query: {})
|
10
|
-
RequestClient.active_client.get("/v1/blocks/#{block_id}/children", query: query)
|
11
|
-
end
|
12
|
-
|
13
|
-
def append(block_id, body)
|
14
|
-
RequestClient.active_client.patch("/v1/blocks/#{block_id}/children", body: body.to_json)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
module Notion
|
2
|
+
class Blocks
|
3
|
+
def children
|
4
|
+
Children.new
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Children
|
9
|
+
def list(block_id, query: {})
|
10
|
+
RequestClient.active_client.get("/v1/blocks/#{block_id}/children", query: query)
|
11
|
+
end
|
12
|
+
|
13
|
+
def append(block_id, body)
|
14
|
+
RequestClient.active_client.patch("/v1/blocks/#{block_id}/children", body: body.to_json)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,15 +1,19 @@
|
|
1
|
-
module Notion
|
2
|
-
class Databases
|
3
|
-
def retrieve(id)
|
4
|
-
RequestClient.active_client.get("/v1/databases/#{id}")
|
5
|
-
end
|
6
|
-
|
7
|
-
def list
|
8
|
-
RequestClient.active_client.get("/v1/databases")
|
9
|
-
end
|
10
|
-
|
11
|
-
def query(id, body)
|
12
|
-
RequestClient.active_client.post("/v1/databases/#{id}/query", body: body.to_json)
|
13
|
-
end
|
14
|
-
|
15
|
-
|
1
|
+
module Notion
|
2
|
+
class Databases
|
3
|
+
def retrieve(id)
|
4
|
+
RequestClient.active_client.get("/v1/databases/#{id}")
|
5
|
+
end
|
6
|
+
|
7
|
+
def list
|
8
|
+
RequestClient.active_client.get("/v1/databases")
|
9
|
+
end
|
10
|
+
|
11
|
+
def query(id, body)
|
12
|
+
RequestClient.active_client.post("/v1/databases/#{id}/query", body: body.to_json)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(body)
|
16
|
+
RequestClient.active_client.post("/v1/databases", body: body.to_json)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|