Skip to content

Commit 6215438

Browse files
committed
add CollectionViewPage class
1 parent c69bdfa commit 6215438

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/notion_api/core.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ def get_page(url_or_id)
4242
end
4343

4444
block_id = clean_id
45-
block_title = extract_title(clean_id, jsonified_record_response)
4645
block_type = extract_type(clean_id, jsonified_record_response)
4746
block_parent_id = extract_parent_id(clean_id, jsonified_record_response)
4847

49-
raise 'the URL or ID passed to the get_page method must be that of a Page Block.' if block_type != 'page'
48+
raise 'the URL or ID passed to the get_page method must be that of a Page Block.' if !['collection_view_page', 'page'].include?(block_type)
5049

51-
PageBlock.new(block_id, block_title, block_parent_id)
50+
if block_type == "page"
51+
block_title = extract_title(clean_id, jsonified_record_response)
52+
PageBlock.new(block_id, block_title, block_parent_id)
53+
elsif block_type == "collection_view_page"
54+
collection_id = extract_collection_id(block_id, jsonified_record_response)
55+
block_title = extract_collection_title(clean_id, collection_id, jsonified_record_response)
56+
view_id = extract_view_ids(block_id, jsonified_record_response)[0]
57+
58+
CollectionViewPage.new(block_id, block_title, block_parent_id, collection_id, view_id)
59+
end
5260
end
5361

5462
def children(url_or_id = @id)

lib/notion_api/notion_types/collection_view_blocks.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,19 @@ def initialize(id, parent_id, collection_id, view_id)
225225
@view_id = view_id
226226
end
227227
end
228+
229+
class CollectionViewPage < CollectionView
230+
@notion_type = 'collection_view_page'
231+
@type = 'collection_view_page'
232+
233+
def type
234+
NotionAPI::CollectionViewRow.notion_type
235+
end
236+
237+
class << self
238+
attr_reader :notion_type, :type, :parent_id
239+
end
240+
241+
attr_reader :parent_id, :id
242+
end
228243
end

lib/notion_api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module NotionAPI
2-
VERSION = '1.0.3'
2+
VERSION = '1.0.4'
33
end

0 commit comments

Comments
 (0)