22
33namespace FiveamCode \LaravelNotionApi \Endpoints ;
44
5- use FiveamCode \LaravelNotionApi \Notion ;
6- use FiveamCode \LaravelNotionApi \Exceptions \NotionException ;
7- use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
8- use FiveamCode \LaravelNotionApi \Entities \Collections \BlockCollection ;
95use FiveamCode \LaravelNotionApi \Entities \Blocks \Block as BlockEntity ;
6+ use FiveamCode \LaravelNotionApi \Entities \Collections \BlockCollection ;
7+ use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
8+ use FiveamCode \LaravelNotionApi \Exceptions \NotionException ;
9+ use FiveamCode \LaravelNotionApi \Notion ;
10+
1011/**
1112 * Class Block
1213 * @package FiveamCode\LaravelNotionApi\Endpoints
@@ -52,7 +53,7 @@ public function retrieve(): BlockEntity {
5253
5354 /**
5455 * Retrieve block children
55- * url: https://api.notion.com/{version}/blocks/{block_id}/children
56+ * url: https://api.notion.com/{version}/blocks/{block_id}/children [get]
5657 * notion-api-docs: https://developers.notion.com/reference/get-block-children
5758 *
5859 * @return BlockCollection
@@ -69,11 +70,37 @@ public function children(): BlockCollection
6970 }
7071
7172 /**
72- * @return array
73+ * Append one Block or an array of Blocks
74+ * url: https://api.notion.com/{version}/blocks/{block_id}/children [patch]
75+ * notion-api-docs: https://developers.notion.com/reference/patch-block-children
76+ *
77+ * @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block
7378 * @throws HandlingException
7479 */
75- public function create ( ): array
80+ public function append ( array | BlockEntity $ appendices ): BlockEntity
7681 {
77- throw new HandlingException ('Not implemented ' );
82+ if (!is_array ($ appendices )) {
83+ $ appendices = [$ appendices ];
84+ }
85+ $ children = [];
86+
87+ foreach ($ appendices as $ block ) {
88+ $ children [] = [
89+ "object " => "block " ,
90+ "type " => $ block ->getType (),
91+ $ block ->getType () => $ block ->getRawContent ()
92+ ];
93+ }
94+
95+ $ body = [
96+ "children " => $ children
97+ ];
98+
99+ $ response = $ this ->patch (
100+ $ this ->url (Endpoint::BLOCKS . '/ ' . $ this ->blockId . '/children ' . "" ),
101+ $ body
102+ );
103+
104+ return new BlockEntity ($ response ->json ());
78105 }
79106}
0 commit comments