notion-sdk-ruby 0.4.0 → 0.4.1

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.
@@ -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-08-16")
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,25 @@
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
+
7
+ def retrieve(block_id)
8
+ RequestClient.active_client.get("/v1/blocks/#{block_id}")
9
+ end
10
+
11
+ def update(block_id, body)
12
+ RequestClient.active_client.patch("/v1/blocks/#{block_id}", body: body.to_json)
13
+ end
14
+ end
15
+
16
+ class Children
17
+ def list(block_id, query: {})
18
+ RequestClient.active_client.get("/v1/blocks/#{block_id}/children", query: query)
19
+ end
20
+
21
+ def append(block_id, body)
22
+ RequestClient.active_client.patch("/v1/blocks/#{block_id}/children", body: body.to_json)
23
+ end
24
+ end
25
+ end
@@ -1,19 +1,25 @@
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
1
+ module Notion
2
+ class Databases
3
+ def retrieve(id)
4
+ RequestClient.active_client.get("/v1/databases/#{id}")
5
+ end
6
+
7
+ # DEPRECATED
8
+ def list
9
+ warn "DEPRECATED: client.databases.list is deprecated."
10
+ RequestClient.active_client.get("/v1/databases")
11
+ end
12
+
13
+ def query(id, body)
14
+ RequestClient.active_client.post("/v1/databases/#{id}/query", body: body.to_json)
15
+ end
16
+
17
+ def create(body)
18
+ RequestClient.active_client.post("/v1/databases", body: body.to_json)
19
+ end
20
+
21
+ def update(id, body)
22
+ RequestClient.active_client.patch("/v1/databases/#{id}", body: body.to_json)
23
+ end
24
+ end
25
+ end
@@ -1,15 +1,15 @@
1
- module Notion
2
- class Pages
3
- def retrieve(id)
4
- RequestClient.active_client.get("/v1/pages/#{id}")
5
- end
6
-
7
- def create(body)
8
- RequestClient.active_client.post("/v1/pages", body: body.to_json)
9
- end
10
-
11
- def update(id, body)
12
- RequestClient.active_client.patch("/v1/pages/#{id}", body: body.to_json)
13
- end
14
- end
15
- end
1
+ module Notion
2
+ class Pages
3
+ def retrieve(id)
4
+ RequestClient.active_client.get("/v1/pages/#{id}")
5
+ end
6
+
7
+ def create(body)
8
+ RequestClient.active_client.post("/v1/pages", body: body.to_json)
9
+ end
10
+
11
+ def update(id, body)
12
+ RequestClient.active_client.patch("/v1/pages/#{id}", body: body.to_json)
13
+ end
14
+ end
15
+ end
@@ -1,11 +1,11 @@
1
- module Notion
2
- class Users
3
- def list
4
- RequestClient.active_client.get("/v1/users")
5
- end
6
-
7
- def retrieve(id)
8
- RequestClient.active_client.get("/v1/users/#{id}")
9
- end
10
- end
11
- end
1
+ module Notion
2
+ class Users
3
+ def list
4
+ RequestClient.active_client.get("/v1/users")
5
+ end
6
+
7
+ def retrieve(id)
8
+ RequestClient.active_client.get("/v1/users/#{id}")
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
- module Notion
2
- VERSION = "0.4.0"
3
- end
1
+ module Notion
2
+ VERSION = "0.4.1"
3
+ end
@@ -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,37 +1,37 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require_relative "lib/notion-sdk-ruby/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "notion-sdk-ruby"
7
- spec.version = Notion::VERSION
8
- spec.authors = ["Graham Marlow"]
9
- spec.email = ["mgmarlow@hey.com"]
10
-
11
- spec.summary = "Notion SDK"
12
- spec.homepage = "https://github.com/mgmarlow/notion-sdk-ruby"
13
- spec.license = "MIT"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
-
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby"
18
- spec.metadata["changelog_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby/blob/master/CHANGELOG.md"
19
-
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
- end
25
- spec.bindir = "exe"
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
-
29
- spec.add_dependency "httparty", "~> 0.18.1"
30
-
31
- spec.add_development_dependency "rake", "~> 12.0"
32
- spec.add_development_dependency "rspec", "~> 3.0"
33
- spec.add_development_dependency "standardrb", "~> 1.0"
34
- spec.add_development_dependency "webmock", "~> 3.12"
35
- spec.add_development_dependency "pry", "~> 0.14.1"
36
- spec.add_development_dependency "dotenv", "~> 2.7"
37
- end
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require_relative "lib/notion-sdk-ruby/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "notion-sdk-ruby"
7
+ spec.version = Notion::VERSION
8
+ spec.authors = ["Graham Marlow"]
9
+ spec.email = ["mgmarlow@hey.com"]
10
+
11
+ spec.summary = "Notion SDK"
12
+ spec.homepage = "https://github.com/mgmarlow/notion-sdk-ruby"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby"
18
+ spec.metadata["changelog_uri"] = "https://github.com/mgmarlow/notion-sdk-ruby/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "httparty", "~> 0.18.1"
30
+
31
+ spec.add_development_dependency "rake", "~> 12.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "standardrb", "~> 1.0"
34
+ spec.add_development_dependency "webmock", "~> 3.12"
35
+ spec.add_development_dependency "pry", "~> 0.14.1"
36
+ spec.add_development_dependency "dotenv", "~> 2.7"
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Graham Marlow
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-22 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2.7'
111
- description:
111
+ description:
112
112
  email:
113
113
  - mgmarlow@hey.com
114
114
  executables: []
@@ -146,7 +146,7 @@ metadata:
146
146
  homepage_uri: https://github.com/mgmarlow/notion-sdk-ruby
147
147
  source_code_uri: https://github.com/mgmarlow/notion-sdk-ruby
148
148
  changelog_uri: https://github.com/mgmarlow/notion-sdk-ruby/blob/master/CHANGELOG.md
149
- post_install_message:
149
+ post_install_message:
150
150
  rdoc_options: []
151
151
  require_paths:
152
152
  - lib
@@ -161,8 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubygems_version: 3.2.3
165
- signing_key:
164
+ rubygems_version: 3.1.2
165
+ signing_key:
166
166
  specification_version: 4
167
167
  summary: Notion SDK
168
168
  test_files: []