notion_rb 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ab0eb041c68351cf2c9a9749b78f01cfe13f7d1aae3b11aa452ba95f468c764
4
- data.tar.gz: 37ff8830acab646cb9d970846ea6fa2c388d75bacbcdcb684938536ead57a43b
3
+ metadata.gz: 264256397e48f5afb8cc9151375de8ec0db94f346827e4352a99c184c3d30d13
4
+ data.tar.gz: 185dc114380c1d5e12aa77602e33ff34d01d36b21965158dfa20ab2f49a18b13
5
5
  SHA512:
6
- metadata.gz: b2738bba8027e7f7e6b741ae67a5771c67d8c27678e5b3e8460da8d6679128d03109f748fb7e2065b091de213f076ee0fdeb0312e6de2421e491172f457f5002
7
- data.tar.gz: 36444104173a52ff3877d92288613bc0380f3fd5e281e87c436ab6a17bb97ee7fbd7d2d038a8cf60e94800d26e481f82d2ba5394a97e50de7e10b4377dbe15cc
6
+ metadata.gz: 8da865381828b1e3e39fd08c2a9457e09d70103ea1209dab194d880846f61ba1d36213b6a9fc228123b9a40b80bd3ec4d8a98a4c2abe850180defd495ca02244
7
+ data.tar.gz: 79a6398c608ef952b42001317aa45db1f3abf8d8a8932a0a7867980802fa242e8ddd80eacc75f6eaaceda6c82331e52af1a4a00d4169aa6284492f3719e2ac51
@@ -1 +1 @@
1
- 2.5.7
1
+ 2.5.8
@@ -3,7 +3,7 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.5.1
6
+ - 2.5.8
7
7
  branches:
8
8
  only:
9
9
  - master
@@ -3,6 +3,7 @@ PATH
3
3
  specs:
4
4
  notion_rb (0.1.2)
5
5
  mechanize
6
+ nokogiri (>= 1.10.8)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -43,13 +44,13 @@ GEM
43
44
  webrobots (>= 0.0.9, < 0.2)
44
45
  mime-types (3.3.1)
45
46
  mime-types-data (~> 3.2015)
46
- mime-types-data (3.2019.1009)
47
+ mime-types-data (3.2020.0425)
47
48
  mini_portile2 (2.4.0)
48
49
  minitest (5.13.0)
49
50
  net-http-digest_auth (1.4.1)
50
- net-http-persistent (3.1.0)
51
+ net-http-persistent (4.0.0)
51
52
  connection_pool (~> 2.2)
52
- nokogiri (1.10.7)
53
+ nokogiri (1.10.9)
53
54
  mini_portile2 (~> 2.4.0)
54
55
  ntlm-http (0.1.1)
55
56
  parallel (1.19.1)
@@ -57,7 +58,7 @@ GEM
57
58
  ast (~> 2.4.0)
58
59
  public_suffix (4.0.1)
59
60
  rainbow (3.0.0)
60
- rake (10.5.0)
61
+ rake (13.0.1)
61
62
  rspec (3.9.0)
62
63
  rspec-core (~> 3.9.0)
63
64
  rspec-expectations (~> 3.9.0)
@@ -86,7 +87,7 @@ GEM
86
87
  thread_safe (~> 0.1)
87
88
  unf (0.1.4)
88
89
  unf_ext
89
- unf_ext (0.0.7.6)
90
+ unf_ext (0.0.7.7)
90
91
  unicode-display_width (1.6.0)
91
92
  vcr (5.0.0)
92
93
  webmock (3.7.6)
@@ -104,7 +105,7 @@ DEPENDENCIES
104
105
  byebug
105
106
  factory_bot
106
107
  notion_rb!
107
- rake (~> 10.0)
108
+ rake (~> 13.0)
108
109
  rspec (~> 3.0)
109
110
  rubocop
110
111
  single_cov
@@ -20,6 +20,12 @@ require 'notion_rb/utils/uuid_validator'
20
20
 
21
21
  require 'notion_rb/block'
22
22
 
23
+ require 'notion_rb/transaction'
24
+ require 'notion_rb/operations/commands/factory'
25
+ require 'notion_rb/operations/factory'
26
+
27
+ require 'notion_rb/request_params'
28
+
23
29
  module NotionRb
24
30
  def self.config
25
31
  @config ||= {}
@@ -22,52 +22,15 @@ module NotionRb
22
22
  end
23
23
 
24
24
  def params
25
- {
26
- requestId: SecureRandom.uuid,
27
- transactions: [{
28
- id: SecureRandom.uuid,
29
- operations: [{
30
- id: @notion_id,
31
- table: 'block',
32
- path: [],
33
- command: 'set',
34
- args: { type: 'text', id: @notion_id, version: 1 }
35
- }, {
36
- id: @notion_id,
37
- table: 'block',
38
- path: [],
39
- command: 'update',
40
- args: { parent_id: @parent_id, parent_table: 'block', alive: true }
41
- }, {
42
- id: @parent_id,
43
- table: 'block',
44
- path: ['content'],
45
- command: 'listAfter',
46
- args: { id: @notion_id }
47
- }, {
48
- id: @notion_id,
49
- table: 'block',
50
- path: %w[
51
- properties
52
- title
53
- ],
54
- command: 'set',
55
- args: []
56
- }, {
57
- id: @notion_id,
58
- table: 'block',
59
- path: ['created_time'],
60
- command: 'set',
61
- args: @created_at
62
- }, {
63
- id: @notion_id,
64
- table: 'block',
65
- path: ['last_edited_time'],
66
- command: 'set',
67
- args: @created_at
68
- }]
69
- }]
70
- }
25
+ NotionRb::RequestParams.new.add_transaction.tap do |transaction|
26
+ transaction
27
+ .add_operation(:set_block_type, @notion_id, 'block')
28
+ .add_operation(:update_parent, @notion_id, @parent_id)
29
+ .add_operation(:list_after, @parent_id, @notion_id)
30
+ .add_operation(:set_block_title, @notion_id, [])
31
+ .add_operation(:set_block_created_time, @notion_id, @created_at)
32
+ .add_operation(:set_block_last_edited_time, @notion_id, @created_at)
33
+ end.to_h
71
34
  end
72
35
  end
73
36
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ module Commands
6
+ class Base
7
+ attr_reader :id, :command, :table, :args, :path
8
+
9
+ def initialize(id, opts = {})
10
+ @id = id
11
+ @command = opts.fetch(:command) do
12
+ raise ArgumentError, 'Commands must specify command action key'
13
+ end
14
+ @table = opts[:table]
15
+ @args = opts[:args]
16
+ @path = opts.fetch(:path, [])
17
+ end
18
+
19
+ def to_h
20
+ {
21
+ id: id,
22
+ table: table,
23
+ path: path,
24
+ command: command,
25
+ args: args
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './base'
4
+ require_relative './list_after'
5
+ require_relative './set'
6
+ require_relative './update'
7
+
8
+ module NotionRb
9
+ module Operations
10
+ module Commands
11
+ COMMANDS = Hash[
12
+ [
13
+ ListAfter,
14
+ Set,
15
+ Update
16
+ ].map { |klass| [klass::NAME, klass] }
17
+ ]
18
+
19
+ class Factory
20
+ def self.build(command_name, id, opts = {})
21
+ COMMANDS.fetch(command_name).new(
22
+ id,
23
+ opts
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ module Commands
6
+ class ListAfter < Base
7
+ COMMAND = 'listAfter'
8
+ NAME = :list_after
9
+
10
+ def initialize(id, opts = {})
11
+ opts.merge!(command: COMMAND)
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ module Commands
6
+ class Set < Base
7
+ COMMAND = 'set'
8
+ NAME = :set
9
+
10
+ def initialize(id, opts = {})
11
+ opts.merge!(command: COMMAND)
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ module Commands
6
+ class Update < Base
7
+ COMMAND = 'update'
8
+ NAME = :update
9
+
10
+ def initialize(id, opts = {})
11
+ opts.merge!(command: COMMAND)
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './set_block_type'
4
+ require_relative './set_block_last_edited_time'
5
+ require_relative './set_block_created_time'
6
+ require_relative './set_block_title'
7
+ require_relative './list_after'
8
+ require_relative './update_parent'
9
+
10
+ module NotionRb
11
+ module Operations
12
+ class Factory
13
+ OPERATIONS = Hash[
14
+ [
15
+ ListAfter,
16
+ SetBlockCreatedTime,
17
+ SetBlockLastEditedTime,
18
+ SetBlockTitle,
19
+ SetBlockType,
20
+ UpdateParent
21
+ ].map { |klass| [klass::OPERATION_NAME, klass] }
22
+ ]
23
+
24
+ def self.build(operation_name, *args)
25
+ OPERATIONS.fetch(operation_name).new(
26
+ *args
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ class ListAfter
6
+ COMMAND_TYPE = :list_after
7
+ OPERATION_NAME = :list_after
8
+ DEFAULT_TABLE = 'block'
9
+ DEFAULT_PATH = ['content']
10
+
11
+ attr_reader :id, :list_after_id, :table, :path
12
+
13
+ def initialize(id, list_after_id, opts={})
14
+ @id = id
15
+ @list_after_id = list_after_id
16
+ @table = opts.fetch(:table, DEFAULT_TABLE)
17
+ @path = opts.fetch(:path, DEFAULT_PATH)
18
+ end
19
+
20
+ def commands
21
+ [
22
+ Commands::Factory.build(
23
+ COMMAND_TYPE,
24
+ id,
25
+ args: args,
26
+ table: table,
27
+ path: path
28
+ )
29
+ ]
30
+ end
31
+
32
+ def args
33
+ {
34
+ id: list_after_id
35
+ }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ class SetBlockCreatedTime < SetBlockLastEditedTime
6
+ OPERATION_NAME = :set_block_created_time
7
+ DEFAULT_PATH = ['created_time'].freeze
8
+
9
+ def initialize(id, time, opts = {})
10
+ opts[:path] ||= DEFAULT_PATH
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ class SetBlockLastEditedTime
6
+ COMMAND_TYPE = :set
7
+ OPERATION_NAME = :set_block_last_edited_time
8
+ DEFAULT_PATH = ['last_edited_time'].freeze
9
+ TABLE = 'block'
10
+
11
+ attr_reader :id, :time, :path
12
+
13
+ def initialize(id, time, opts = {})
14
+ @id = id
15
+ @time = time
16
+ @path = opts.fetch(:path, DEFAULT_PATH)
17
+ end
18
+
19
+ def commands
20
+ [
21
+ Commands::Factory.build(
22
+ COMMAND_TYPE,
23
+ id,
24
+ args: args,
25
+ table: TABLE,
26
+ path: path
27
+ )
28
+ ]
29
+ end
30
+
31
+ def args
32
+ time
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ class SetBlockTitle
6
+ COMMAND_TYPE = :set
7
+ OPERATION_NAME = :set_block_title
8
+ TABLE = 'block'
9
+ DEFAULT_PATH = %w[properties title].freeze
10
+
11
+ attr_reader :id, :title, :path
12
+
13
+ def initialize(id, title = nil, opts = {})
14
+ @id = id
15
+ @title = title
16
+ @path = opts.fetch(:path, DEFAULT_PATH)
17
+ end
18
+
19
+ def commands
20
+ [
21
+ Commands::Factory.build(
22
+ COMMAND_TYPE,
23
+ id,
24
+ args: args,
25
+ table: TABLE,
26
+ path: path
27
+ )
28
+ ]
29
+ end
30
+
31
+ def args
32
+ return [] if title.nil?
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ class SetBlockType
6
+ DEFAULT_VERSION = 1
7
+ COMMAND_TYPE = :set
8
+ OPERATION_NAME = :set_block_type
9
+ TABLE = 'block'
10
+
11
+ attr_reader :id, :type
12
+
13
+ def initialize(id, type)
14
+ @id = id
15
+ @type = type
16
+ end
17
+
18
+ def commands
19
+ [
20
+ Commands::Factory.build(
21
+ :set,
22
+ id,
23
+ args: args,
24
+ table: TABLE
25
+ )
26
+ ]
27
+ end
28
+
29
+ def args
30
+ {
31
+ type: type,
32
+ version: DEFAULT_VERSION,
33
+ id: id
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ module Operations
5
+ class UpdateParent
6
+ COMMAND_TYPE = :update
7
+ OPERATION_NAME = :update_parent
8
+ TABLE = 'block'
9
+ DEFAULT_PARENT_TABLE = TABLE
10
+ DEFAULT_ALIVE_VALUE = true
11
+
12
+ attr_reader :id, :parent_id, :parent_table, :alive
13
+
14
+ def initialize(id, parent_id, opts = {})
15
+ @id = id
16
+ @parent_id = parent_id
17
+ @parent_table = opts.fetch(:parent_table, DEFAULT_PARENT_TABLE)
18
+ @alive = opts.fetch(:alive, DEFAULT_ALIVE_VALUE)
19
+ end
20
+
21
+ def commands
22
+ [
23
+ Commands::Factory.build(
24
+ COMMAND_TYPE,
25
+ id,
26
+ args: args,
27
+ table: TABLE
28
+ )
29
+ ]
30
+ end
31
+
32
+ def args
33
+ {
34
+ parent_id: parent_id,
35
+ parent_table: parent_table,
36
+ alive: alive
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ class RequestParams
5
+ attr_reader :transactions, :request_id
6
+
7
+ def initialize
8
+ @request_id = SecureRandom.uuid
9
+ @transactions = []
10
+ end
11
+
12
+ def add_transaction
13
+ Transaction.new.tap { |t| @transactions.push(t) }
14
+ end
15
+
16
+ def to_h
17
+ {
18
+ requestId: request_id,
19
+ transactions: transactions.map(&:to_h)
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotionRb
4
+ class Transaction
5
+ attr_reader :id, :operations
6
+
7
+ def initialize
8
+ @id = SecureRandom.uuid
9
+ @operations = []
10
+ end
11
+
12
+ def add_operation(operation_name, *args)
13
+ operations.push(
14
+ Operations::Factory.build(operation_name, *args)
15
+ )
16
+ self
17
+ end
18
+
19
+ def to_h
20
+ { id: id, operations: operations.flat_map { |o| o.commands.map(&:to_h) } }
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRb
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -28,11 +28,12 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
 
30
30
  spec.add_runtime_dependency 'mechanize'
31
+ spec.add_runtime_dependency 'nokogiri', '>= 1.10.8'
31
32
 
32
33
  spec.add_development_dependency 'bundler', '~> 1.17.0'
33
34
  spec.add_development_dependency 'byebug'
34
35
  spec.add_development_dependency 'factory_bot'
35
- spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rake', '~> 13.0'
36
37
  spec.add_development_dependency 'rspec', '~> 3.0'
37
38
  spec.add_development_dependency 'rubocop'
38
39
  spec.add_development_dependency 'single_cov'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Gunther
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.10.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.10.8
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,14 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '10.0'
89
+ version: '13.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '10.0'
96
+ version: '13.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -180,6 +194,20 @@ files:
180
194
  - lib/notion_rb/api/restore.rb
181
195
  - lib/notion_rb/api/update.rb
182
196
  - lib/notion_rb/block.rb
197
+ - lib/notion_rb/operations/commands/base.rb
198
+ - lib/notion_rb/operations/commands/factory.rb
199
+ - lib/notion_rb/operations/commands/list_after.rb
200
+ - lib/notion_rb/operations/commands/set.rb
201
+ - lib/notion_rb/operations/commands/update.rb
202
+ - lib/notion_rb/operations/factory.rb
203
+ - lib/notion_rb/operations/list_after.rb
204
+ - lib/notion_rb/operations/set_block_created_time.rb
205
+ - lib/notion_rb/operations/set_block_last_edited_time.rb
206
+ - lib/notion_rb/operations/set_block_title.rb
207
+ - lib/notion_rb/operations/set_block_type.rb
208
+ - lib/notion_rb/operations/update_parent.rb
209
+ - lib/notion_rb/request_params.rb
210
+ - lib/notion_rb/transaction.rb
183
211
  - lib/notion_rb/utils/block_cache.rb
184
212
  - lib/notion_rb/utils/converter.rb
185
213
  - lib/notion_rb/utils/parser.rb