notion_ruby_mapping 3.0.5 → 3.0.6

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: 129deebb939e145eb0c9adc431cbec81edb0d67cbefca8f38dfb7e2550a221b4
4
- data.tar.gz: f82b0f5d77b8de97d0e31cd8f2cb583ba8ce80e58c68b9698359600e59b221e4
3
+ metadata.gz: a52b1e5d063d287acdc0bb5bfa88f48c666c3f8d550115db524cc4243dda5cc6
4
+ data.tar.gz: 4d38fd4b35fb0ac10c0302d04d726aaa5f43672e46c32700c8758ee5d481b406
5
5
  SHA512:
6
- metadata.gz: 9bf2499aa0a6f91b97206325534eeb1bafa027727b1bc5a24798ad7c6fc7040aa3e24e84c02179f9916994c2bb59ba60600f3e7d7faaedeb5c61a721fd0e5d33
7
- data.tar.gz: 624eb4a6364d528ceb413b7dda9dd946d41d72914372545f51c8785df4f654a9ee138615aac56d409b2f781ecc3d3933cbc14fa132943903a7a5841d5669a49a
6
+ metadata.gz: e2c267cbffaa97b9cb1c70f9b254c7e1976dd7956bb9359929d151905b82ee0ef459d75e585943765022aa921d5ec91176a40459b10b072a0feac00ef07da9bf
7
+ data.tar.gz: b8b05c7683b1bb6969db57dfce0656cf1c92529ec7167a5f9250c1cf80453e44df8dc7fc55501c4fab6515b3b10587e1d247c2aec9049eac4f520fdb7053b9d2
data/README.md CHANGED
@@ -136,6 +136,7 @@ NotionRubyMapping.configuration { |c| c.notion_token = ENV["NOTION_API_TOKEN"] }
136
136
 
137
137
  ## 3. ChangeLog
138
138
 
139
+ - 2026/1/25 [v3.0.6] add move page, list templates, and create child page to page
139
140
  - 2025/12/15 [v3.0.5] add AudioBlock
140
141
  - 2025/12/9 [v3.0.4] Fix the issue where page.parent could not be executed for pages with a data source as parent
141
142
  - 2025/10/25 [v3.0.3] Add default template option for create_child_page and build_child_page
@@ -7,7 +7,7 @@ module NotionRubyMapping
7
7
  # @param [Hash, nil] json
8
8
  # @param [String, nil] id
9
9
  # @param [Array<Property, Class, String>] assign
10
- def initialize(json: nil, id: nil, assign: [], parent: nil, template_page: nil)
10
+ def initialize(json: nil, id: nil, assign: [], parent: nil, template_page: nil, position: nil)
11
11
  @nc = NotionCache.instance
12
12
  @json = json
13
13
  @id = @nc.hex_id(id || @json && @json["id"])
@@ -23,6 +23,11 @@ module NotionRubyMapping
23
23
  elsif template_page
24
24
  payload_json["template"] = {"type" => "template_id", "template_id" => template_page.id}
25
25
  end
26
+ if %w[page_start page_end].include? position
27
+ payload_json["position"] = {"type" => position}
28
+ elsif position
29
+ payload_json["position"] = {"type" => "after_block", "after_block" => {"id" => position}}
30
+ end
26
31
  @payload = Payload.new(payload_json)
27
32
  @property_cache = nil
28
33
  @created_time = nil
@@ -126,6 +126,13 @@ module NotionRubyMapping
126
126
  self
127
127
  end
128
128
 
129
+ # @param [Integer] page_size
130
+ # @return [NotionRubyMapping::List] List of Template object
131
+ def templates(page_size: nil)
132
+ json = @nc.list_data_source_templates_request(id, page_size: page_size)
133
+ List.new type: "template", value: id, json: json, query: Query.new
134
+ end
135
+
129
136
  # @return [Hash] created json for property schemas (for update data_source)
130
137
  def update_property_schema_json
131
138
  @payload.update_property_schema_json @property_cache, data_source_title
@@ -23,6 +23,8 @@ module NotionRubyMapping
23
23
  @user_object = value
24
24
  when "search"
25
25
  @search = value
26
+ when "template"
27
+ @template = value
26
28
  end
27
29
  @query = query
28
30
  @index = 0
@@ -82,6 +84,11 @@ module NotionRubyMapping
82
84
  query: -> { @nc.search @search.payload.merge(@query.query_json) },
83
85
  create_object: ->(json) { Base.create_from_json json },
84
86
  &block
87
+ elsif @template
88
+ each_sub base: @template,
89
+ query: -> { @nc.list_data_source_templates_request @template, start_cursor: @query.start_cursor },
90
+ create_object: ->(json) { TemplateObject.new json: json },
91
+ &block
85
92
  end
86
93
  self
87
94
  end
@@ -125,7 +132,7 @@ module NotionRubyMapping
125
132
 
126
133
  # @return [Hash]
127
134
  def results
128
- @json["results"]
135
+ @json[@template ? "templates" : "results"]
129
136
  end
130
137
  end
131
138
  end
@@ -59,6 +59,40 @@ module NotionRubyMapping
59
59
  db.save dry_run: dry_run
60
60
  end
61
61
 
62
+ # @return [NotionRubyMapping::Base]
63
+ def build_child_page(template_page: nil, position: nil)
64
+ page = Page.new assign: [TitleProperty, "title"], parent: {"type" => "page_id", "page_id" => @id},
65
+ template_page: template_page, position: position
66
+ pp = page.properties
67
+ pp.clear_will_update
68
+ yield page, pp if block_given?
69
+ page
70
+ end
71
+
72
+ # @param [Boolean] dry_run true if dry_run
73
+ # @return [NotionRubyMapping::Base]
74
+ def create_child_page(template_page: nil, position: nil, dry_run: false)
75
+ page = Page.new assign: [TitleProperty, "title"], parent: {"type" => "page_id", "page_id" => @id},
76
+ template_page: template_page, position: position
77
+ pp = page.properties
78
+ pp.clear_will_update
79
+ yield page, pp if block_given?
80
+ page.save dry_run: dry_run
81
+ end
82
+
83
+ # @param [Page, DataSource] page_or_data_source
84
+ # @param [Boolean] dry_run true if dry_run
85
+ # @return [NotionRubyMapping::Page, String]
86
+ def move_to(page_or_data_source, dry_run: false)
87
+ key = page_or_data_source.is_a?(Page) ? "page_id" : "data_source_id"
88
+ json = {"parent" => {"type" => key, key => page_or_data_source.id}}
89
+ if dry_run
90
+ self.class.dry_run_script :post, @nc.move_page_path(@id), json
91
+ else
92
+ update_json @nc.move_page_request(@id, json)
93
+ end
94
+ end
95
+
62
96
  # @return [String] 公開URL
63
97
  def public_url
64
98
  @json["public_url"]
@@ -243,6 +243,38 @@ module NotionRubyMapping
243
243
  "NotionCache"
244
244
  end
245
245
 
246
+ # @param [String] data_source_id
247
+ # @param [Integer] page_size
248
+ # @param [String] start_cursor
249
+ # @return [Hash] response hash
250
+ def list_data_source_templates_request(data_source_id, page_size: nil, start_cursor: nil)
251
+ options = []
252
+ options << "page_size=#{page_size}" if page_size
253
+ options << "start_cursor=#{start_cursor}" if start_cursor
254
+ option_str = options.empty? ? "" : "?" + options.join("&")
255
+ request :get, list_data_source_templates_path(data_source_id, option_str)
256
+ end
257
+
258
+ # @param [String] data_source_id
259
+ # @param [String] options
260
+ # @return [String] path
261
+ def list_data_source_templates_path(data_source_id, options = "")
262
+ "v1/data_sources/#{data_source_id}/templates#{options}"
263
+ end
264
+
265
+ # @param [String] page_id
266
+ # @param [Hash] payload
267
+ # @return [Hash] response hash
268
+ def move_page_request(page_id, payload)
269
+ request :post, move_page_path(page_id), payload
270
+ end
271
+
272
+ # @param [String] page_id
273
+ # @return [String] move_page_path
274
+ def move_page_path(page_id)
275
+ "v1/pages/#{page_id}/move"
276
+ end
277
+
246
278
  # @param [String] path
247
279
  # @param [String] fname
248
280
  # @param [Hash] options
@@ -427,7 +459,7 @@ module NotionRubyMapping
427
459
  request :get, user_path(user_id)
428
460
  end
429
461
 
430
- # @return [Array<NotionRubyMapping::UserObject>] UserObject array
462
+ # @return [NotionRubyMapping::ListObject] List Object for UserObject
431
463
  def users
432
464
  List.new json: users_request, type: "user_object", value: true
433
465
  end
@@ -0,0 +1,19 @@
1
+ module NotionRubyMapping
2
+ class TemplateObject
3
+ def initialize(json: json)
4
+ @id = json["id"]
5
+ @name = json["name"]
6
+ @is_default = json["is_default"]
7
+ end
8
+ attr_reader :id, :name, :is_default
9
+
10
+ # @return [Hash{String->String, Boolean}]
11
+ def property_values_json
12
+ {
13
+ "id" => @id,
14
+ "name" => @name,
15
+ "is_default" => @is_default
16
+ }
17
+ end
18
+ end
19
+ end
@@ -157,7 +157,7 @@ module NotionRubyMapping
157
157
  !instance_of? Property
158
158
  end
159
159
 
160
- # @param [Symbol] key query parameter
160
+ # @param [String] key query parameter
161
161
  # @param [Object] value query value
162
162
  # @return [NotionRubyMapping::Query] generated Query object
163
163
  def make_filter_query(key, value, condition: nil, another_type: nil)
@@ -30,6 +30,17 @@ module NotionRubyMapping
30
30
  @json = json
31
31
  end
32
32
 
33
+ ## DataSource only methods
34
+
35
+ # @param [String, Number] value Query value
36
+ # @param [String] condition rollup Rollup name
37
+ # @param [String] another_type rollup_type Rollup type
38
+ # @return [NotionRubyMapping::Query] generated Query object
39
+ # @see https://www.notion.so/hkob/CheckboxProperty-ac1edbdb8e264af5ad1432b522b429fd#5f07c4ebc4744986bfc99a43827349fc
40
+ def filter_status(value, condition: nil, another_type: nil)
41
+ make_filter_query "status", value, condition: condition, another_type: another_type
42
+ end
43
+
33
44
  ## Page property only methods
34
45
 
35
46
  # @return [Hash]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRubyMapping
4
- VERSION = "3.0.5"
4
+ VERSION = "3.0.6"
5
5
  NOTION_VERSION = "2025-09-03"
6
6
  end
@@ -15,7 +15,7 @@ require_relative "notion_ruby_mapping/version"
15
15
  controllers: %w[notion_cache payload property_cache query rich_text_array discussion_thread search mermaid
16
16
  mermaid_data_source],
17
17
  objects: %w[rich_text_object emoji_object equation_object file_object mention_object text_object user_object
18
- comment_object file_upload_object],
18
+ comment_object file_upload_object template_object],
19
19
  properties: %w[property checkbox_property multi_property created_by_property date_base_property created_time_property
20
20
  date_property email_property files_property formula_property last_edited_by_property
21
21
  last_edited_time_property multi_select_property number_property people_property phone_number_property
@@ -38,6 +38,9 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency "faraday-multipart"
39
39
  spec.add_dependency "mime-types"
40
40
 
41
+ spec.add_development_dependency "pry"
42
+ spec.add_development_dependency "pry-byebug"
43
+ spec.add_development_dependency "rb-readline"
41
44
  spec.add_development_dependency "guard"
42
45
  spec.add_development_dependency "guard-rspec"
43
46
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_ruby_mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki KOBAYASHI
@@ -51,6 +51,48 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: pry
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: pry-byebug
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rb-readline
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
54
96
  - !ruby/object:Gem::Dependency
55
97
  name: guard
56
98
  requirement: !ruby/object:Gem::Requirement
@@ -238,6 +280,7 @@ files:
238
280
  - lib/notion_ruby_mapping/objects/file_upload_object.rb
239
281
  - lib/notion_ruby_mapping/objects/mention_object.rb
240
282
  - lib/notion_ruby_mapping/objects/rich_text_object.rb
283
+ - lib/notion_ruby_mapping/objects/template_object.rb
241
284
  - lib/notion_ruby_mapping/objects/text_object.rb
242
285
  - lib/notion_ruby_mapping/objects/user_object.rb
243
286
  - lib/notion_ruby_mapping/properties/button_property.rb
@@ -289,7 +332,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
332
  - !ruby/object:Gem::Version
290
333
  version: '0'
291
334
  requirements: []
292
- rubygems_version: 4.0.0
335
+ rubygems_version: 4.0.3
293
336
  specification_version: 4
294
337
  summary: Notion Ruby mapping tool
295
338
  test_files: []