2
2
3
3
namespace FiveamCode \LaravelNotionApi \Endpoints ;
4
4
5
- use FiveamCode \LaravelNotionApi \Notion ;
6
- use FiveamCode \LaravelNotionApi \Exceptions \NotionException ;
7
- use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
5
+ use FiveamCode \LaravelNotionApi \Entities \Blocks \Block as BlockEntity ;
8
6
use FiveamCode \LaravelNotionApi \Entities \Collections \BlockCollection ;
7
+ use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
8
+ use FiveamCode \LaravelNotionApi \Exceptions \NotionException ;
9
+ use FiveamCode \LaravelNotionApi \Notion ;
9
10
10
11
/**
11
12
* Class Block
@@ -31,9 +32,29 @@ public function __construct(Notion $notion, string $blockId)
31
32
$ this ->blockId = $ blockId ;
32
33
}
33
34
35
+ /**
36
+ * Retrieve a block
37
+ * url: https://api.notion.com/{version}/blocks/{block_id}
38
+ * notion-api-docs: https://developers.notion.com/reference/retrieve-a-block
39
+ *
40
+ * @param string $blockId
41
+ * @return BlockEntity
42
+ * @throws HandlingException
43
+ * @throws NotionException
44
+ */
45
+ public function retrieve (): BlockEntity
46
+ {
47
+
48
+ $ response = $ this ->get (
49
+ $ this ->url (Endpoint::BLOCKS . '/ ' . $ this ->blockId )
50
+ );
51
+
52
+ return BlockEntity::fromResponse ($ response ->json ());
53
+ }
54
+
34
55
/**
35
56
* Retrieve block children
36
- * url: https://api.notion.com/{version}/blocks/{block_id}/children
57
+ * url: https://api.notion.com/{version}/blocks/{block_id}/children [get]
37
58
* notion-api-docs: https://developers.notion.com/reference/get-block-children
38
59
*
39
60
* @return BlockCollection
@@ -50,11 +71,37 @@ public function children(): BlockCollection
50
71
}
51
72
52
73
/**
53
- * @return array
74
+ * Append one Block or an array of Blocks
75
+ * url: https://api.notion.com/{version}/blocks/{block_id}/children [patch]
76
+ * notion-api-docs: https://developers.notion.com/reference/patch-block-children
77
+ *
78
+ * @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block
54
79
* @throws HandlingException
55
80
*/
56
- public function create ( ): array
81
+ public function append ( array | BlockEntity $ appendices ): BlockEntity
57
82
{
58
- throw new HandlingException ('Not implemented ' );
83
+ if (!is_array ($ appendices )) {
84
+ $ appendices = [$ appendices ];
85
+ }
86
+ $ children = [];
87
+
88
+ foreach ($ appendices as $ block ) {
89
+ $ children [] = [
90
+ "object " => "block " ,
91
+ "type " => $ block ->getType (),
92
+ $ block ->getType () => $ block ->getRawContent ()
93
+ ];
94
+ }
95
+
96
+ $ body = [
97
+ "children " => $ children
98
+ ];
99
+
100
+ $ response = $ this ->patch (
101
+ $ this ->url (Endpoint::BLOCKS . '/ ' . $ this ->blockId . '/children ' . "" ),
102
+ $ body
103
+ );
104
+
105
+ return new BlockEntity ($ response ->json ());
59
106
}
60
107
}
0 commit comments