From e1de3e85bc6747319cfee323a6db6ca23c3c543b Mon Sep 17 00:00:00 2001 From: JohGuentner <3506359+johguentner@users.noreply.github.com> Date: Sat, 11 Sep 2021 20:27:47 +0200 Subject: [PATCH 01/10] full implementation for block creation + tests - implemented static creation-function for all modifiable blocks - implemented append-function to Block-Endpoint - implemented tests-function, in which all block-creation-functions are tested - added todo/warning for notion-version-change to test-function --- src/Endpoints/Block.php | 35 ++- src/Entities/Blocks/Block.php | 5 + src/Entities/Blocks/BulletedListItem.php | 11 + src/Entities/Blocks/HeadingOne.php | 11 + src/Entities/Blocks/HeadingThree.php | 11 + src/Entities/Blocks/HeadingTwo.php | 11 + src/Entities/Blocks/NumberedListItem.php | 11 + src/Entities/Blocks/Paragraph.php | 11 + src/Entities/Blocks/TextBlock.php | 26 ++- src/Entities/Blocks/ToDo.php | 11 + src/Entities/Blocks/Toggle.php | 11 + tests/EndpointBlocksTest.php | 213 +++++++++++------- .../blocks/response_specific_block_200.json | 8 + 13 files changed, 285 insertions(+), 90 deletions(-) create mode 100644 tests/stubs/endpoints/blocks/response_specific_block_200.json diff --git a/src/Endpoints/Block.php b/src/Endpoints/Block.php index 6c68eb5..395f207 100644 --- a/src/Endpoints/Block.php +++ b/src/Endpoints/Block.php @@ -6,6 +6,7 @@ use FiveamCode\LaravelNotionApi\Exceptions\NotionException; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection; +use FiveamCode\LaravelNotionApi\Entities\Blocks\Block as BaseBlockEntity; /** * Class Block @@ -33,7 +34,7 @@ public function __construct(Notion $notion, string $blockId) /** * Retrieve block children - * url: https://api.notion.com/{version}/blocks/{block_id}/children + * url: https://api.notion.com/{version}/blocks/{block_id}/children [get] * notion-api-docs: https://developers.notion.com/reference/get-block-children * * @return BlockCollection @@ -50,11 +51,37 @@ public function children(): BlockCollection } /** - * @return array + * Append one Block or an array of Blocks + * url: https://api.notion.com/{version}/blocks/{block_id}/children [patch] + * notion-api-docs: https://developers.notion.com/reference/patch-block-children + * + * @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block * @throws HandlingException */ - public function create(): array + public function append(array|BaseBlockEntity $appendices): BaseBlockEntity { - throw new HandlingException('Not implemented'); + if (!is_array($appendices)) { + $appendices = [$appendices]; + } + $children = []; + + foreach ($appendices as $block) { + array_push($children, [ + "object" => "block", + "type" => $block->getType(), + $block->getType() => $block->getRawContent() + ]); + } + + $body = [ + "children" => $children + ]; + + $response = $this->patch( + $this->url(Endpoint::BLOCKS . '/' . $this->blockId . '/children' . ""), + $body + ); + + return new BaseBlockEntity($response->json()); } } diff --git a/src/Entities/Blocks/Block.php b/src/Entities/Blocks/Block.php index 7bf6369..c8a97f7 100644 --- a/src/Entities/Blocks/Block.php +++ b/src/Entities/Blocks/Block.php @@ -161,6 +161,10 @@ public function asText() : string return $this->text; } + public function setContent($content){ + $this->content = $content; + } + /** * @param $rawContent * @return Block @@ -173,6 +177,7 @@ public static function fromResponse($rawContent): Block return $block; } + /** * Maps the type of a block to the corresponding package class by converting the type name. * diff --git a/src/Entities/Blocks/BulletedListItem.php b/src/Entities/Blocks/BulletedListItem.php index c407b4d..68c0c70 100644 --- a/src/Entities/Blocks/BulletedListItem.php +++ b/src/Entities/Blocks/BulletedListItem.php @@ -13,4 +13,15 @@ */ class BulletedListItem extends TextBlock { + public static function create(array|string $textContent): BulletedListItem + { + $bulletedListItem = new BulletedListItem(); + TextBlock::createTextBlock($bulletedListItem, $textContent); + return $bulletedListItem; + } + + function __construct(array $responseData = null){ + $this->type = "bulleted_list_item"; + parent::__construct($responseData); + } } diff --git a/src/Entities/Blocks/HeadingOne.php b/src/Entities/Blocks/HeadingOne.php index 8ddf073..a3f93f4 100644 --- a/src/Entities/Blocks/HeadingOne.php +++ b/src/Entities/Blocks/HeadingOne.php @@ -13,4 +13,15 @@ */ class HeadingOne extends TextBlock { + public static function create(array|string $textContent): HeadingOne + { + $headingOne = new HeadingOne(); + TextBlock::createTextBlock($headingOne, $textContent); + return $headingOne; + } + + function __construct(array $responseData = null){ + $this->type = "heading_1"; + parent::__construct($responseData); + } } diff --git a/src/Entities/Blocks/HeadingThree.php b/src/Entities/Blocks/HeadingThree.php index 4c26205..230f418 100644 --- a/src/Entities/Blocks/HeadingThree.php +++ b/src/Entities/Blocks/HeadingThree.php @@ -13,4 +13,15 @@ */ class HeadingThree extends TextBlock { + public static function create(array|string $textContent): HeadingThree + { + $headingThree = new HeadingThree(); + HeadingThree::createTextBlock($headingThree, $textContent); + return $headingThree; + } + + function __construct(array $responseData = null){ + $this->type = "heading_3"; + parent::__construct($responseData); + } } diff --git a/src/Entities/Blocks/HeadingTwo.php b/src/Entities/Blocks/HeadingTwo.php index 7238651..0bf435f 100644 --- a/src/Entities/Blocks/HeadingTwo.php +++ b/src/Entities/Blocks/HeadingTwo.php @@ -13,4 +13,15 @@ */ class HeadingTwo extends TextBlock { + public static function create(array|string $textContent): HeadingTwo + { + $headingTwo = new HeadingTwo(); + HeadingTwo::createTextBlock($headingTwo, $textContent); + return $headingTwo; + } + + function __construct(array $responseData = null){ + $this->type = "heading_2"; + parent::__construct($responseData); + } } diff --git a/src/Entities/Blocks/NumberedListItem.php b/src/Entities/Blocks/NumberedListItem.php index 8c8baf2..a1b0bb5 100644 --- a/src/Entities/Blocks/NumberedListItem.php +++ b/src/Entities/Blocks/NumberedListItem.php @@ -13,4 +13,15 @@ */ class NumberedListItem extends TextBlock { + public static function create(array|string $textContent): NumberedListItem + { + $numberedListItem = new NumberedListItem(); + TextBlock::createTextBlock($numberedListItem, $textContent); + return $numberedListItem; + } + + function __construct(array $responseData = null){ + $this->type = "numbered_list_item"; + parent::__construct($responseData); + } } diff --git a/src/Entities/Blocks/Paragraph.php b/src/Entities/Blocks/Paragraph.php index 8768eef..2ed3471 100644 --- a/src/Entities/Blocks/Paragraph.php +++ b/src/Entities/Blocks/Paragraph.php @@ -14,4 +14,15 @@ */ class Paragraph extends TextBlock { + public static function create(array|string $textContent): Paragraph + { + $paragraph = new Paragraph(); + TextBlock::createTextBlock($paragraph, $textContent); + return $paragraph; + } + + function __construct(array $responseData = null){ + $this->type = "paragraph"; + parent::__construct($responseData); + } } diff --git a/src/Entities/Blocks/TextBlock.php b/src/Entities/Blocks/TextBlock.php index 443fdd0..67eeeea 100644 --- a/src/Entities/Blocks/TextBlock.php +++ b/src/Entities/Blocks/TextBlock.php @@ -3,6 +3,7 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; use DateTime; +use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; @@ -12,8 +13,31 @@ * Class TextBlock * @package FiveamCode\LaravelNotionApi\Entities\Blocks */ -class TextBlock extends Block +class TextBlock extends Block implements Modifiable { + protected static function createTextBlock(TextBlock $textBlock, array|string $textContent): TextBlock + { + if (is_string($textContent)) { + $textContent = [$textContent]; + } + + $text = []; + foreach ($textContent as $textItem) { + array_push($text, [ + "type" => "text", + "text" => [ + "content" => $textItem + ] + ]); + } + + $textBlock->rawContent = [ + "text" => $text + ]; + + return $textBlock; + } + /** * */ diff --git a/src/Entities/Blocks/ToDo.php b/src/Entities/Blocks/ToDo.php index 22b097f..53489af 100644 --- a/src/Entities/Blocks/ToDo.php +++ b/src/Entities/Blocks/ToDo.php @@ -13,4 +13,15 @@ */ class ToDo extends TextBlock { + public static function create(array|string $textContent): ToDo + { + $toDo = new ToDo(); + TextBlock::createTextBlock($toDo, $textContent); + return $toDo; + } + + function __construct(array $responseData = null){ + $this->type = "to_do"; + parent::__construct($responseData); + } } diff --git a/src/Entities/Blocks/Toggle.php b/src/Entities/Blocks/Toggle.php index 7e0a4fb..55e7a75 100644 --- a/src/Entities/Blocks/Toggle.php +++ b/src/Entities/Blocks/Toggle.php @@ -13,4 +13,15 @@ */ class Toggle extends TextBlock { + public static function create(array|string $textContent): Toggle + { + $toggle = new Toggle(); + TextBlock::createTextBlock($toggle, $textContent); + return $toggle; + } + + function __construct(array $responseData = null){ + $this->type = "toggle"; + parent::__construct($responseData); + } } diff --git a/tests/EndpointBlocksTest.php b/tests/EndpointBlocksTest.php index eacd20e..0b7cb18 100644 --- a/tests/EndpointBlocksTest.php +++ b/tests/EndpointBlocksTest.php @@ -79,85 +79,84 @@ public function it_returns_block_collection_with_children() $this->assertEquals('Lacinato kale', $blockChild->getRawContent()['text'][0]['plain_text']); } - /** @test */ - public function it_returns_block_collection_with_children_as_correct_instances() - { - // successful /v1/blocks/BLOCK_DOES_EXIST/children - Http::fake([ - 'https://api.notion.com/v1/blocks/1d719dd1-563b-4387-b74f-20da92b827fb/children*' - => Http::response( - json_decode(file_get_contents('tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json'), true), - 200, - ['Headers'] - ) - ]); - - $blockChildren = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->children(); - $this->assertInstanceOf(BlockCollection::class, $blockChildren); - - # check collection - $blockChildrenCollection = $blockChildren->asCollection(); - $this->assertContainsOnly(Block::class, $blockChildrenCollection); - $this->assertIsIterable($blockChildrenCollection); - $this->assertCount(8, $blockChildrenCollection); - - # check paragraph - $blockChild = $blockChildrenCollection[0]; - $this->assertInstanceOf(Paragraph::class, $blockChild); - $this->assertEquals('paragraph', $blockChild->getType()); - $this->assertFalse($blockChild->hasChildren()); - $this->assertEquals('paragraph_block', $blockChild->getContent()->getPlainText()); - - # check heading_1 - $blockChild = $blockChildrenCollection[1]; - $this->assertInstanceOf(HeadingOne::class, $blockChild); - $this->assertEquals('heading_1', $blockChild->getType()); - $this->assertFalse($blockChild->hasChildren()); - $this->assertEquals('heading_one_block', $blockChild->getContent()->getPlainText()); - - # check heading_2 - $blockChild = $blockChildrenCollection[2]; - $this->assertInstanceOf(HeadingTwo::class, $blockChild); - $this->assertEquals('heading_2', $blockChild->getType()); - $this->assertFalse($blockChild->hasChildren()); - $this->assertEquals('heading_two_block', $blockChild->getContent()->getPlainText()); - - # check heading_3 - $blockChild = $blockChildrenCollection[3]; - $this->assertInstanceOf(HeadingThree::class, $blockChild); - $this->assertEquals('heading_3', $blockChild->getType()); - $this->assertFalse($blockChild->hasChildren()); - $this->assertEquals('heading_three_block', $blockChild->getContent()->getPlainText()); - - # check bulleted_list_item - $blockChild = $blockChildrenCollection[4]; - $this->assertInstanceOf(BulletedListItem::class, $blockChild); - $this->assertEquals('bulleted_list_item', $blockChild->getType()); - $this->assertFalse($blockChild->hasChildren()); - $this->assertEquals('bulleted_list_item_block', $blockChild->getContent()->getPlainText()); - - # check numbered_list_item - $blockChild = $blockChildrenCollection[5]; - $this->assertInstanceOf(NumberedListItem::class, $blockChild); - $this->assertEquals('numbered_list_item', $blockChild->getType()); - $this->assertFalse($blockChild->hasChildren()); - $this->assertEquals('numbered_list_item_block', $blockChild->getContent()->getPlainText()); - - # check to_do - $blockChild = $blockChildrenCollection[6]; - $this->assertInstanceOf(ToDo::class, $blockChild); - $this->assertEquals('to_do', $blockChild->getType()); - $this->assertFalse($blockChild->hasChildren()); - $this->assertEquals('to_do_block', $blockChild->getContent()->getPlainText()); - - # check toggle - $blockChild = $blockChildrenCollection[7]; - $this->assertInstanceOf(Toggle::class, $blockChild); - $this->assertEquals('toggle', $blockChild->getType()); - $this->assertFalse($blockChild->hasChildren()); - $this->assertEquals('toggle_block', $blockChild->getContent()->getPlainText()); - - } + /** @test */ + public function it_returns_block_collection_with_children_as_correct_instances() + { + // successful /v1/blocks/BLOCK_DOES_EXIST/children + Http::fake([ + 'https://api.notion.com/v1/blocks/1d719dd1-563b-4387-b74f-20da92b827fb/children*' + => Http::response( + json_decode(file_get_contents('tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json'), true), + 200, + ['Headers'] + ) + ]); + + $blockChildren = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->children(); + $this->assertInstanceOf(BlockCollection::class, $blockChildren); + + # check collection + $blockChildrenCollection = $blockChildren->asCollection(); + $this->assertContainsOnly(Block::class, $blockChildrenCollection); + $this->assertIsIterable($blockChildrenCollection); + $this->assertCount(8, $blockChildrenCollection); + + # check paragraph + $blockChild = $blockChildrenCollection[0]; + $this->assertInstanceOf(Paragraph::class, $blockChild); + $this->assertEquals('paragraph', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('paragraph_block', $blockChild->getContent()->getPlainText()); + + # check heading_1 + $blockChild = $blockChildrenCollection[1]; + $this->assertInstanceOf(HeadingOne::class, $blockChild); + $this->assertEquals('heading_1', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('heading_one_block', $blockChild->getContent()->getPlainText()); + + # check heading_2 + $blockChild = $blockChildrenCollection[2]; + $this->assertInstanceOf(HeadingTwo::class, $blockChild); + $this->assertEquals('heading_2', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('heading_two_block', $blockChild->getContent()->getPlainText()); + + # check heading_3 + $blockChild = $blockChildrenCollection[3]; + $this->assertInstanceOf(HeadingThree::class, $blockChild); + $this->assertEquals('heading_3', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('heading_three_block', $blockChild->getContent()->getPlainText()); + + # check bulleted_list_item + $blockChild = $blockChildrenCollection[4]; + $this->assertInstanceOf(BulletedListItem::class, $blockChild); + $this->assertEquals('bulleted_list_item', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('bulleted_list_item_block', $blockChild->getContent()->getPlainText()); + + # check numbered_list_item + $blockChild = $blockChildrenCollection[5]; + $this->assertInstanceOf(NumberedListItem::class, $blockChild); + $this->assertEquals('numbered_list_item', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('numbered_list_item_block', $blockChild->getContent()->getPlainText()); + + # check to_do + $blockChild = $blockChildrenCollection[6]; + $this->assertInstanceOf(ToDo::class, $blockChild); + $this->assertEquals('to_do', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('to_do_block', $blockChild->getContent()->getPlainText()); + + # check toggle + $blockChild = $blockChildrenCollection[7]; + $this->assertInstanceOf(Toggle::class, $blockChild); + $this->assertEquals('toggle', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('toggle_block', $blockChild->getContent()->getPlainText()); + } /** @test */ public function it_throws_a_notion_exception_not_found() @@ -179,13 +178,57 @@ public function it_throws_a_notion_exception_not_found() } /** @test */ - public function it_throws_a_handling_exception_not_implemented() + public function it_returns_parent_block_in_which_new_blocks_have_been_successfully_appended() { + //TODO: Change in release 0.7.0 or 0.8.0 + //!IMPORTANT: This will be changed in Notion version 2021-08-16, because a list of the newly created block children will be returned + //!https://developers.notion.com/changelog/notion-version-2021-08-16#append-block-children-returns-a-list-of-blocks - $this->expectException(HandlingException::class); - $this->expectExceptionMessage('Not implemented'); + // successful /v1/blocks/BLOCK_DOES_EXIST/children [patch] + Http::fake([ + 'https://api.notion.com/v1/blocks/1d719dd1-563b-4387-b74f-20da92b827fb/children*' + => Http::response( + json_decode(file_get_contents('tests/stubs/endpoints/blocks/response_specific_block_200.json'), true), + 200, + ['Headers'] + ) + ]); - Notion::block('')->create(); - } + $paragraph = Paragraph::create("New TextBlock"); + $bulletedListItem = BulletedListItem::create("New TextBlock"); + $headingOne = HeadingOne::create("New TextBlock"); + $headingTwo = HeadingTwo::create("New TextBlock"); + $headingThree = HeadingThree::create("New TextBlock"); + $numberedListItem = NumberedListItem::create("New TextBlock"); + $toDo = ToDo::create("New TextBlock"); + $toggle = Toggle::create(["New TextBlock"]); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($paragraph); + $this->assertInstanceOf(Block::class, $parentBlock); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($bulletedListItem); + $this->assertInstanceOf(Block::class, $parentBlock); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($headingOne); + $this->assertInstanceOf(Block::class, $parentBlock); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($headingTwo); + $this->assertInstanceOf(Block::class, $parentBlock); -} \ No newline at end of file + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($headingThree); + $this->assertInstanceOf(Block::class, $parentBlock); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($numberedListItem); + $this->assertInstanceOf(Block::class, $parentBlock); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($toDo); + $this->assertInstanceOf(Block::class, $parentBlock); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($toggle); + $this->assertInstanceOf(Block::class, $parentBlock); + + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append([$paragraph, $bulletedListItem, $headingOne, $headingTwo, $headingThree, $numberedListItem, $toDo, $toggle]); + $this->assertInstanceOf(Block::class, $parentBlock); + } +} diff --git a/tests/stubs/endpoints/blocks/response_specific_block_200.json b/tests/stubs/endpoints/blocks/response_specific_block_200.json new file mode 100644 index 0000000..82a6de2 --- /dev/null +++ b/tests/stubs/endpoints/blocks/response_specific_block_200.json @@ -0,0 +1,8 @@ +{ + "object": "block", + "id": "1d719dd1-563b-4387-b74f-20da92b827fb", + "created_time": "2021-07-17T16:51:00.000Z", + "last_edited_time": "2021-07-17T16:54:00.000Z", + "has_children": false, + "type": "page" +} \ No newline at end of file From 9c7d72d4d6916ec2caa6931ca96e45d2cb82b1d4 Mon Sep 17 00:00:00 2001 From: JohGuentner <3506359+johguentner@users.noreply.github.com> Date: Sat, 11 Sep 2021 21:08:06 +0200 Subject: [PATCH 02/10] polish method name in Block + add Embed-Block - rename "fillContent" of Block to "fillRawContent", since it is filling the rawContent (no direct breaking change) - added EmbedBlock (retreive url + caption) --- src/Entities/Blocks/Block.php | 5 +-- src/Entities/Blocks/ChildPage.php | 5 +++ src/Entities/Blocks/Embed.php | 51 +++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/Entities/Blocks/Embed.php diff --git a/src/Entities/Blocks/Block.php b/src/Entities/Blocks/Block.php index c8a97f7..cc40ad0 100644 --- a/src/Entities/Blocks/Block.php +++ b/src/Entities/Blocks/Block.php @@ -69,7 +69,7 @@ protected function fillFromRaw(): void { $this->fillId(); $this->fillType(); - $this->fillContent(); + $this->fillRawContent(); $this->fillHasChildren(); $this->fillCreatedTime(); $this->fillLastEditedTime(); @@ -88,7 +88,7 @@ private function fillType(): void /** * */ - private function fillContent(): void + private function fillRawContent(): void { if (Arr::exists($this->responseData, $this->getType())) { $this->rawContent = $this->responseData[$this->getType()]; @@ -193,6 +193,7 @@ private static function mapTypeToClass(string $type): string case 'child_page': case 'paragraph': case 'to_do': + case 'embed': case 'toggle': $class = str_replace('_', '', ucwords($type, '_')); return "FiveamCode\\LaravelNotionApi\\Entities\\Blocks\\" . $class; diff --git a/src/Entities/Blocks/ChildPage.php b/src/Entities/Blocks/ChildPage.php index f1577ee..c7ef831 100644 --- a/src/Entities/Blocks/ChildPage.php +++ b/src/Entities/Blocks/ChildPage.php @@ -13,6 +13,11 @@ */ class ChildPage extends Block { + function __construct(array $responseData = null){ + $this->type = "child_page"; + parent::__construct($responseData); + } + /** * */ diff --git a/src/Entities/Blocks/Embed.php b/src/Entities/Blocks/Embed.php new file mode 100644 index 0000000..f8d46e1 --- /dev/null +++ b/src/Entities/Blocks/Embed.php @@ -0,0 +1,51 @@ +type = "embed"; + parent::__construct($responseData); + } + + /** + * + */ + protected function fillFromRaw(): void + { + parent::fillFromRaw(); + $this->fillContent(); + } + + /** + * + */ + protected function fillContent(): void + { + $this->url = $this->rawContent['url']; + $this->caption = new RichText($this->rawContent['caption']); + $this->content = $this->url; + } + + public function getUrl(){ + return $this->url; + } + + public function getCaption(){ + return $this->caption; + } +} From 86e37f9c0efc9c9db4d78f37f522350f3766c7b4 Mon Sep 17 00:00:00 2001 From: JohGuentner <3506359+johguentner@users.noreply.github.com> Date: Sat, 11 Sep 2021 21:30:41 +0200 Subject: [PATCH 03/10] add embed-creation and add tests for embed-block --- src/Entities/Blocks/Embed.php | 28 +++++++++++++++-- tests/EndpointBlocksTest.php | 17 ++++++++-- ...esponse_specific_supported_blocks_200.json | 31 +++++++++++++++++++ 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/src/Entities/Blocks/Embed.php b/src/Entities/Blocks/Embed.php index f8d46e1..78fa34e 100644 --- a/src/Entities/Blocks/Embed.php +++ b/src/Entities/Blocks/Embed.php @@ -17,7 +17,27 @@ class Embed extends Block private RichText $caption; private string $url = ""; - function __construct(array $responseData = null){ + public static function create(string $url, string $caption): Embed + { + $embed = new Embed(); + + $embed->rawContent = [ + 'url' => $url, + 'caption' => [ + [ + 'type' => 'text', + 'text' => [ + 'content' => $caption + ] + ] + ] + ]; + + return $embed; + } + + function __construct(array $responseData = null) + { $this->type = "embed"; parent::__construct($responseData); } @@ -41,11 +61,13 @@ protected function fillContent(): void $this->content = $this->url; } - public function getUrl(){ + public function getUrl() + { return $this->url; } - public function getCaption(){ + public function getCaption() + { return $this->caption; } } diff --git a/tests/EndpointBlocksTest.php b/tests/EndpointBlocksTest.php index 0b7cb18..93503cd 100644 --- a/tests/EndpointBlocksTest.php +++ b/tests/EndpointBlocksTest.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Http; use FiveamCode\LaravelNotionApi\Entities\Blocks\Block; use FiveamCode\LaravelNotionApi\Entities\Blocks\BulletedListItem; +use FiveamCode\LaravelNotionApi\Entities\Blocks\Embed; use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingOne; use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingThree; use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingTwo; @@ -99,7 +100,7 @@ public function it_returns_block_collection_with_children_as_correct_instances() $blockChildrenCollection = $blockChildren->asCollection(); $this->assertContainsOnly(Block::class, $blockChildrenCollection); $this->assertIsIterable($blockChildrenCollection); - $this->assertCount(8, $blockChildrenCollection); + $this->assertCount(9, $blockChildrenCollection); # check paragraph $blockChild = $blockChildrenCollection[0]; @@ -156,6 +157,14 @@ public function it_returns_block_collection_with_children_as_correct_instances() $this->assertEquals('toggle', $blockChild->getType()); $this->assertFalse($blockChild->hasChildren()); $this->assertEquals('toggle_block', $blockChild->getContent()->getPlainText()); + + # check embed + $blockChild = $blockChildrenCollection[8]; + $this->assertInstanceOf(Embed::class, $blockChild); + $this->assertEquals('embed', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('Testcaption', $blockChild->getCaption()->getPlainText()); + $this->assertEquals('https://notion.so', $blockChild->getUrl()); } /** @test */ @@ -202,6 +211,7 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful $numberedListItem = NumberedListItem::create("New TextBlock"); $toDo = ToDo::create("New TextBlock"); $toggle = Toggle::create(["New TextBlock"]); + $embed = Embed::create("https://5amco.de", "Testcaption"); $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($paragraph); $this->assertInstanceOf(Block::class, $parentBlock); @@ -227,8 +237,11 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($toggle); $this->assertInstanceOf(Block::class, $parentBlock); + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($embed); + $this->assertInstanceOf(Block::class, $parentBlock); + - $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append([$paragraph, $bulletedListItem, $headingOne, $headingTwo, $headingThree, $numberedListItem, $toDo, $toggle]); + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append([$paragraph, $bulletedListItem, $headingOne, $headingTwo, $headingThree, $numberedListItem, $toDo, $toggle, $embed]); $this->assertInstanceOf(Block::class, $parentBlock); } } diff --git a/tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json b/tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json index 54096f0..74f6a65 100644 --- a/tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json +++ b/tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json @@ -233,6 +233,37 @@ } ] } + }, + { + "object": "block", + "id": "1750f17f-d2bd-105a-bedc-c6b5808b98be", + "created_time": "2021-09-11T18:52:00.000Z", + "last_edited_time": "2021-09-11T19:01:00.000Z", + "has_children": false, + "archived": false, + "type": "embed", + "embed": { + "caption": [ + { + "type": "text", + "text": { + "content": "Testcaption", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "Testcaption", + "href": null + } + ], + "url": "https://notion.so" + } } ], "next_cursor": null, From dc294f7561f4c54febb0ac2db018c69b1614d317 Mon Sep 17 00:00:00 2001 From: JohGuentner <3506359+johguentner@users.noreply.github.com> Date: Sun, 12 Sep 2021 00:05:05 +0200 Subject: [PATCH 04/10] fill content of embed-block within create - this ensures the currect values within the class attributes --- src/Entities/Blocks/Embed.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Entities/Blocks/Embed.php b/src/Entities/Blocks/Embed.php index 78fa34e..8edaa8c 100644 --- a/src/Entities/Blocks/Embed.php +++ b/src/Entities/Blocks/Embed.php @@ -33,6 +33,8 @@ public static function create(string $url, string $caption): Embed ] ]; + $embed->fillContent(); + return $embed; } From 941dec8b5aca345130488bb6f75e09562c91df9a Mon Sep 17 00:00:00 2001 From: JohGuentner <3506359+johguentner@users.noreply.github.com> Date: Sun, 12 Sep 2021 00:06:58 +0200 Subject: [PATCH 05/10] fill content of textblocks during creation - this ensures the correct values within the textblock classes attributes --- src/Entities/Blocks/TextBlock.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Entities/Blocks/TextBlock.php b/src/Entities/Blocks/TextBlock.php index 67eeeea..c4fc1ce 100644 --- a/src/Entities/Blocks/TextBlock.php +++ b/src/Entities/Blocks/TextBlock.php @@ -35,6 +35,8 @@ protected static function createTextBlock(TextBlock $textBlock, array|string $te "text" => $text ]; + $textBlock->fillContent(); + return $textBlock; } From 76a4298b71f6611170b5845000bf68f66344af40 Mon Sep 17 00:00:00 2001 From: JohGuentner <3506359+johguentner@users.noreply.github.com> Date: Sun, 12 Sep 2021 01:08:15 +0200 Subject: [PATCH 06/10] add new blocks (file, image, video, pdf) + polish - set up BaseFileBlock::class for file-related blocks (file, image, file, pdf) - implement Modifiable within embed and BaseFileBlock - mark caption as optional paramter in embed and BaseFileBlock with empty string as default - set up tests for all new blocks (creation and retreival) --- src/Entities/Blocks/BaseFileBlock.php | 79 ++++++++++ src/Entities/Blocks/Block.php | 11 +- src/Entities/Blocks/Embed.php | 5 +- src/Entities/Blocks/File.php | 30 ++++ src/Entities/Blocks/Image.php | 30 ++++ src/Entities/Blocks/Pdf.php | 30 ++++ src/Entities/Blocks/Video.php | 30 ++++ tests/EndpointBlocksTest.php | 55 ++++++- ...esponse_specific_supported_blocks_200.json | 136 ++++++++++++++++++ 9 files changed, 399 insertions(+), 7 deletions(-) create mode 100644 src/Entities/Blocks/BaseFileBlock.php create mode 100644 src/Entities/Blocks/File.php create mode 100644 src/Entities/Blocks/Image.php create mode 100644 src/Entities/Blocks/Pdf.php create mode 100644 src/Entities/Blocks/Video.php diff --git a/src/Entities/Blocks/BaseFileBlock.php b/src/Entities/Blocks/BaseFileBlock.php new file mode 100644 index 0000000..6f4f679 --- /dev/null +++ b/src/Entities/Blocks/BaseFileBlock.php @@ -0,0 +1,79 @@ +rawContent = [ + 'type' => 'external', + 'caption' => [ + [ + 'type' => 'text', + 'text' => [ + 'content' => $caption + ] + ] + ], + 'external' => [ + 'url' => $url, + ] + ]; + + $fileBlock->fillContent(); + + return $fileBlock; + } + + private string $hostingType = ""; + private string $url = ""; + private RichText $caption; + + + /** + * + */ + protected function fillFromRaw(): void + { + parent::fillFromRaw(); + $this->fillContent(); + } + + /** + * + */ + protected function fillContent(): void + { + $this->hostingType = $this->rawContent['type']; + $this->url = $this->rawContent[$this->hostingType]['url']; + $this->caption = new RichText($this->rawContent['caption']); + $this->content = $this->url; + } + + public function getUrl() + { + return $this->url; + } + + public function getHostingType() + { + return $this->hostingType; + } + + public function getCaption() + { + return $this->caption; + } +} diff --git a/src/Entities/Blocks/Block.php b/src/Entities/Blocks/Block.php index cc40ad0..4ec1be5 100644 --- a/src/Entities/Blocks/Block.php +++ b/src/Entities/Blocks/Block.php @@ -156,12 +156,13 @@ public function getContent() /** * @return string */ - public function asText() : string + public function asText(): string { return $this->text; } - public function setContent($content){ + public function setContent($content) + { $this->content = $content; } @@ -193,8 +194,12 @@ private static function mapTypeToClass(string $type): string case 'child_page': case 'paragraph': case 'to_do': - case 'embed': case 'toggle': + case 'embed': + case 'image': + case 'video': + case 'file': + case 'pdf': $class = str_replace('_', '', ucwords($type, '_')); return "FiveamCode\\LaravelNotionApi\\Entities\\Blocks\\" . $class; case 'heading_1': diff --git a/src/Entities/Blocks/Embed.php b/src/Entities/Blocks/Embed.php index 8edaa8c..8b0b859 100644 --- a/src/Entities/Blocks/Embed.php +++ b/src/Entities/Blocks/Embed.php @@ -3,6 +3,7 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; use DateTime; +use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; @@ -12,12 +13,12 @@ * Class Paragraph * @package FiveamCode\LaravelNotionApi\Entities\Blocks */ -class Embed extends Block +class Embed extends Block implements Modifiable { private RichText $caption; private string $url = ""; - public static function create(string $url, string $caption): Embed + public static function create(string $url, string $caption = ""): Embed { $embed = new Embed(); diff --git a/src/Entities/Blocks/File.php b/src/Entities/Blocks/File.php new file mode 100644 index 0000000..238d19b --- /dev/null +++ b/src/Entities/Blocks/File.php @@ -0,0 +1,30 @@ +type = "file"; + parent::__construct($responseData); + } + +} diff --git a/src/Entities/Blocks/Image.php b/src/Entities/Blocks/Image.php new file mode 100644 index 0000000..84ff24b --- /dev/null +++ b/src/Entities/Blocks/Image.php @@ -0,0 +1,30 @@ +type = "image"; + parent::__construct($responseData); + } + +} diff --git a/src/Entities/Blocks/Pdf.php b/src/Entities/Blocks/Pdf.php new file mode 100644 index 0000000..2846e01 --- /dev/null +++ b/src/Entities/Blocks/Pdf.php @@ -0,0 +1,30 @@ +type = "pdf"; + parent::__construct($responseData); + } + +} diff --git a/src/Entities/Blocks/Video.php b/src/Entities/Blocks/Video.php new file mode 100644 index 0000000..4fdbb73 --- /dev/null +++ b/src/Entities/Blocks/Video.php @@ -0,0 +1,30 @@ +type = "video"; + parent::__construct($responseData); + } + +} diff --git a/tests/EndpointBlocksTest.php b/tests/EndpointBlocksTest.php index 93503cd..24e0497 100644 --- a/tests/EndpointBlocksTest.php +++ b/tests/EndpointBlocksTest.php @@ -7,13 +7,17 @@ use FiveamCode\LaravelNotionApi\Entities\Blocks\Block; use FiveamCode\LaravelNotionApi\Entities\Blocks\BulletedListItem; use FiveamCode\LaravelNotionApi\Entities\Blocks\Embed; +use FiveamCode\LaravelNotionApi\Entities\Blocks\File; use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingOne; use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingThree; use FiveamCode\LaravelNotionApi\Entities\Blocks\HeadingTwo; +use FiveamCode\LaravelNotionApi\Entities\Blocks\Image; use FiveamCode\LaravelNotionApi\Entities\Blocks\NumberedListItem; use FiveamCode\LaravelNotionApi\Entities\Blocks\Paragraph; +use FiveamCode\LaravelNotionApi\Entities\Blocks\Pdf; use FiveamCode\LaravelNotionApi\Entities\Blocks\ToDo; use FiveamCode\LaravelNotionApi\Entities\Blocks\Toggle; +use FiveamCode\LaravelNotionApi\Entities\Blocks\Video; use FiveamCode\LaravelNotionApi\Exceptions\NotionException; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection; @@ -100,7 +104,7 @@ public function it_returns_block_collection_with_children_as_correct_instances() $blockChildrenCollection = $blockChildren->asCollection(); $this->assertContainsOnly(Block::class, $blockChildrenCollection); $this->assertIsIterable($blockChildrenCollection); - $this->assertCount(9, $blockChildrenCollection); + $this->assertCount(13, $blockChildrenCollection); # check paragraph $blockChild = $blockChildrenCollection[0]; @@ -165,6 +169,42 @@ public function it_returns_block_collection_with_children_as_correct_instances() $this->assertFalse($blockChild->hasChildren()); $this->assertEquals('Testcaption', $blockChild->getCaption()->getPlainText()); $this->assertEquals('https://notion.so', $blockChild->getUrl()); + + # check image + $blockChild = $blockChildrenCollection[9]; + $this->assertInstanceOf(Image::class, $blockChild); + $this->assertEquals('image', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('test', $blockChild->getCaption()->getPlainText()); + $this->assertEquals('external', $blockChild->getHostingType()); + $this->assertEquals('https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb', $blockChild->getUrl()); + + # check file + $blockChild = $blockChildrenCollection[10]; + $this->assertInstanceOf(File::class, $blockChild); + $this->assertEquals('file', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('TestCaption', $blockChild->getCaption()->getPlainText()); + $this->assertEquals('external', $blockChild->getHostingType()); + $this->assertEquals('https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb', $blockChild->getUrl()); + + # check video + $blockChild = $blockChildrenCollection[11]; + $this->assertInstanceOf(Video::class, $blockChild); + $this->assertEquals('video', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('TestCaption', $blockChild->getCaption()->getPlainText()); + $this->assertEquals('external', $blockChild->getHostingType()); + $this->assertEquals('https://www.w3schools.com/html/mov_bbb.mp4', $blockChild->getUrl()); + + # check pdf + $blockChild = $blockChildrenCollection[12]; + $this->assertInstanceOf(Pdf::class, $blockChild); + $this->assertEquals('pdf', $blockChild->getType()); + $this->assertFalse($blockChild->hasChildren()); + $this->assertEquals('TestCaption', $blockChild->getCaption()->getPlainText()); + $this->assertEquals('external', $blockChild->getHostingType()); + $this->assertEquals('https://notion.so/testpdf.pdf', $blockChild->getUrl()); } /** @test */ @@ -212,6 +252,9 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful $toDo = ToDo::create("New TextBlock"); $toggle = Toggle::create(["New TextBlock"]); $embed = Embed::create("https://5amco.de", "Testcaption"); + $image = Image::create("https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb", "Testcaption"); + $video = Image::create("https://www.w3schools.com/html/mov_bbb.mp4", "TestCaption"); + $pdf = Image::create("https://notion.so/testpdf.pdf", "TestCaption"); $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($paragraph); $this->assertInstanceOf(Block::class, $parentBlock); @@ -240,8 +283,16 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($embed); $this->assertInstanceOf(Block::class, $parentBlock); + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($image); + $this->assertInstanceOf(Block::class, $parentBlock); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($video); + $this->assertInstanceOf(Block::class, $parentBlock); + + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($pdf); + $this->assertInstanceOf(Block::class, $parentBlock); - $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append([$paragraph, $bulletedListItem, $headingOne, $headingTwo, $headingThree, $numberedListItem, $toDo, $toggle, $embed]); + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append([$paragraph, $bulletedListItem, $headingOne, $headingTwo, $headingThree, $numberedListItem, $toDo, $toggle, $embed, $image, $video, $pdf]); $this->assertInstanceOf(Block::class, $parentBlock); } } diff --git a/tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json b/tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json index 74f6a65..2c743f1 100644 --- a/tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json +++ b/tests/stubs/endpoints/blocks/response_specific_supported_blocks_200.json @@ -264,6 +264,142 @@ ], "url": "https://notion.so" } + }, + { + "object": "block", + "id": "1a14a61f-0d09-45c2-b97b-07b209474ecf", + "created_time": "2021-09-11T22:18:00.000Z", + "last_edited_time": "2021-09-11T22:21:00.000Z", + "has_children": false, + "archived": false, + "type": "image", + "image": { + "caption": [ + { + "type": "text", + "text": { + "content": "test", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "test", + "href": null + } + ], + "type": "external", + "external": { + "url": "https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb" + } + } + }, + { + "object": "block", + "id": "5e506978-6e1f-10c3-8374-63eaf27eaecc", + "created_time": "2021-09-11T22:38:00.000Z", + "last_edited_time": "2021-09-11T22:38:00.000Z", + "has_children": false, + "archived": false, + "type": "file", + "file": { + "caption": [ + { + "type": "text", + "text": { + "content": "TestCaption", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "TestCaption", + "href": null + } + ], + "type": "external", + "external": { + "url": "https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb" + } + } + }, + { + "object": "block", + "id": "3762ce35-e825-19e0-b024-4f5e172cdfe2", + "created_time": "2021-09-11T23:00:00.000Z", + "last_edited_time": "2021-09-11T23:00:00.000Z", + "has_children": false, + "archived": false, + "type": "video", + "video": { + "caption": [ + { + "type": "text", + "text": { + "content": "TestCaption", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "TestCaption", + "href": null + } + ], + "type": "external", + "external": { + "url": "https://www.w3schools.com/html/mov_bbb.mp4" + } + } + }, + { + "object": "block", + "id": "51a8e0ef-570a-4e14-bc03-16db98ad45db", + "created_time": "2021-09-11T22:58:00.000Z", + "last_edited_time": "2021-09-11T22:58:00.000Z", + "has_children": false, + "archived": false, + "type": "pdf", + "pdf": { + "caption": [ + { + "type": "text", + "text": { + "content": "TestCaption", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "TestCaption", + "href": null + } + ], + "type": "external", + "external": { + "url": "https://notion.so/testpdf.pdf" + } + } } ], "next_cursor": null, From 8a8745faf5896689694e7af50b294945694e58ad Mon Sep 17 00:00:00 2001 From: Diana Scharf Date: Mon, 13 Sep 2021 22:00:18 +0200 Subject: [PATCH 07/10] Fixed tests --- tests/EndpointBlocksTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/EndpointBlocksTest.php b/tests/EndpointBlocksTest.php index 24e0497..fa19211 100644 --- a/tests/EndpointBlocksTest.php +++ b/tests/EndpointBlocksTest.php @@ -253,8 +253,9 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful $toggle = Toggle::create(["New TextBlock"]); $embed = Embed::create("https://5amco.de", "Testcaption"); $image = Image::create("https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb", "Testcaption"); - $video = Image::create("https://www.w3schools.com/html/mov_bbb.mp4", "TestCaption"); - $pdf = Image::create("https://notion.so/testpdf.pdf", "TestCaption"); + $file = File::create("https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb", "Testcaption"); + $video = Video::create("https://www.w3schools.com/html/mov_bbb.mp4", "TestCaption"); + $pdf = Pdf::create("https://notion.so/testpdf.pdf", "TestCaption"); $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($paragraph); $this->assertInstanceOf(Block::class, $parentBlock); @@ -286,6 +287,9 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($image); $this->assertInstanceOf(Block::class, $parentBlock); + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($file); + $this->assertInstanceOf(Block::class, $parentBlock); + $parentBlock = Notion::block('1d719dd1-563b-4387-b74f-20da92b827fb')->append($video); $this->assertInstanceOf(Block::class, $parentBlock); From 5b880c769de6dbac5552048ef1a292c90c4d24c6 Mon Sep 17 00:00:00 2001 From: Diana Scharf Date: Mon, 13 Sep 2021 22:14:50 +0200 Subject: [PATCH 08/10] Formatting commit --- src/Entities/Blocks/BaseFileBlock.php | 4 ++-- src/Entities/Blocks/Block.php | 2 +- src/Entities/Blocks/BulletedListItem.php | 5 +++-- src/Entities/Blocks/ChildPage.php | 9 +++++---- src/Entities/Blocks/Embed.php | 4 ++-- src/Entities/Blocks/HeadingOne.php | 5 +++-- src/Entities/Blocks/HeadingThree.php | 5 +++-- src/Entities/Blocks/HeadingTwo.php | 5 +++-- src/Entities/Blocks/NumberedListItem.php | 5 +++-- src/Entities/Blocks/Paragraph.php | 5 +++-- src/Entities/Blocks/TextBlock.php | 6 +++--- src/Entities/Blocks/ToDo.php | 5 +++-- src/Entities/Blocks/Toggle.php | 5 +++-- src/Entities/Collections/BlockCollection.php | 8 ++++---- src/Entities/Entity.php | 12 +++++++----- src/Entities/Page.php | 2 +- src/Entities/Properties/Checkbox.php | 3 ++- src/Entities/Properties/Date.php | 4 ++-- src/Entities/Properties/Files.php | 2 +- src/Entities/Properties/Formula.php | 6 +++--- src/Entities/Properties/MultiSelect.php | 2 +- src/Entities/Properties/People.php | 4 ++-- src/Entities/Properties/Relation.php | 4 ++-- src/Entities/PropertyItems/RichDate.php | 1 - src/Entities/PropertyItems/RichText.php | 2 +- src/Entities/PropertyItems/SelectItem.php | 7 ++++--- src/LaravelNotionApiServiceProvider.php | 4 ++-- src/Query/Filter.php | 4 ++-- 28 files changed, 71 insertions(+), 59 deletions(-) diff --git a/src/Entities/Blocks/BaseFileBlock.php b/src/Entities/Blocks/BaseFileBlock.php index 6f4f679..597b098 100644 --- a/src/Entities/Blocks/BaseFileBlock.php +++ b/src/Entities/Blocks/BaseFileBlock.php @@ -43,7 +43,7 @@ protected static function createFileBlock(BaseFileBlock $fileBlock, string $url, /** - * + * */ protected function fillFromRaw(): void { @@ -52,7 +52,7 @@ protected function fillFromRaw(): void } /** - * + * */ protected function fillContent(): void { diff --git a/src/Entities/Blocks/Block.php b/src/Entities/Blocks/Block.php index 4ec1be5..176bf65 100644 --- a/src/Entities/Blocks/Block.php +++ b/src/Entities/Blocks/Block.php @@ -146,7 +146,7 @@ public function getLastEditedTime(): DateTime } /** - * + * */ public function getContent() { diff --git a/src/Entities/Blocks/BulletedListItem.php b/src/Entities/Blocks/BulletedListItem.php index 68c0c70..3867c4b 100644 --- a/src/Entities/Blocks/BulletedListItem.php +++ b/src/Entities/Blocks/BulletedListItem.php @@ -15,12 +15,13 @@ class BulletedListItem extends TextBlock { public static function create(array|string $textContent): BulletedListItem { - $bulletedListItem = new BulletedListItem(); + $bulletedListItem = new BulletedListItem(); TextBlock::createTextBlock($bulletedListItem, $textContent); return $bulletedListItem; } - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "bulleted_list_item"; parent::__construct($responseData); } diff --git a/src/Entities/Blocks/ChildPage.php b/src/Entities/Blocks/ChildPage.php index c7ef831..6b8f88c 100644 --- a/src/Entities/Blocks/ChildPage.php +++ b/src/Entities/Blocks/ChildPage.php @@ -13,13 +13,14 @@ */ class ChildPage extends Block { - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "child_page"; parent::__construct($responseData); } /** - * + * */ protected function fillFromRaw(): void { @@ -28,9 +29,9 @@ protected function fillFromRaw(): void } /** - * + * */ - protected function fillContent() : void + protected function fillContent(): void { $this->content = $this->rawContent['title']; $this->text = $this->getContent(); diff --git a/src/Entities/Blocks/Embed.php b/src/Entities/Blocks/Embed.php index 8b0b859..9dae26a 100644 --- a/src/Entities/Blocks/Embed.php +++ b/src/Entities/Blocks/Embed.php @@ -46,7 +46,7 @@ function __construct(array $responseData = null) } /** - * + * */ protected function fillFromRaw(): void { @@ -55,7 +55,7 @@ protected function fillFromRaw(): void } /** - * + * */ protected function fillContent(): void { diff --git a/src/Entities/Blocks/HeadingOne.php b/src/Entities/Blocks/HeadingOne.php index a3f93f4..908828a 100644 --- a/src/Entities/Blocks/HeadingOne.php +++ b/src/Entities/Blocks/HeadingOne.php @@ -15,12 +15,13 @@ class HeadingOne extends TextBlock { public static function create(array|string $textContent): HeadingOne { - $headingOne = new HeadingOne(); + $headingOne = new HeadingOne(); TextBlock::createTextBlock($headingOne, $textContent); return $headingOne; } - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "heading_1"; parent::__construct($responseData); } diff --git a/src/Entities/Blocks/HeadingThree.php b/src/Entities/Blocks/HeadingThree.php index 230f418..f260eb8 100644 --- a/src/Entities/Blocks/HeadingThree.php +++ b/src/Entities/Blocks/HeadingThree.php @@ -15,12 +15,13 @@ class HeadingThree extends TextBlock { public static function create(array|string $textContent): HeadingThree { - $headingThree = new HeadingThree(); + $headingThree = new HeadingThree(); HeadingThree::createTextBlock($headingThree, $textContent); return $headingThree; } - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "heading_3"; parent::__construct($responseData); } diff --git a/src/Entities/Blocks/HeadingTwo.php b/src/Entities/Blocks/HeadingTwo.php index 0bf435f..94774d3 100644 --- a/src/Entities/Blocks/HeadingTwo.php +++ b/src/Entities/Blocks/HeadingTwo.php @@ -15,12 +15,13 @@ class HeadingTwo extends TextBlock { public static function create(array|string $textContent): HeadingTwo { - $headingTwo = new HeadingTwo(); + $headingTwo = new HeadingTwo(); HeadingTwo::createTextBlock($headingTwo, $textContent); return $headingTwo; } - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "heading_2"; parent::__construct($responseData); } diff --git a/src/Entities/Blocks/NumberedListItem.php b/src/Entities/Blocks/NumberedListItem.php index a1b0bb5..5b85419 100644 --- a/src/Entities/Blocks/NumberedListItem.php +++ b/src/Entities/Blocks/NumberedListItem.php @@ -15,12 +15,13 @@ class NumberedListItem extends TextBlock { public static function create(array|string $textContent): NumberedListItem { - $numberedListItem = new NumberedListItem(); + $numberedListItem = new NumberedListItem(); TextBlock::createTextBlock($numberedListItem, $textContent); return $numberedListItem; } - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "numbered_list_item"; parent::__construct($responseData); } diff --git a/src/Entities/Blocks/Paragraph.php b/src/Entities/Blocks/Paragraph.php index 2ed3471..f4103de 100644 --- a/src/Entities/Blocks/Paragraph.php +++ b/src/Entities/Blocks/Paragraph.php @@ -16,12 +16,13 @@ class Paragraph extends TextBlock { public static function create(array|string $textContent): Paragraph { - $paragraph = new Paragraph(); + $paragraph = new Paragraph(); TextBlock::createTextBlock($paragraph, $textContent); return $paragraph; } - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "paragraph"; parent::__construct($responseData); } diff --git a/src/Entities/Blocks/TextBlock.php b/src/Entities/Blocks/TextBlock.php index c4fc1ce..3d1fd5b 100644 --- a/src/Entities/Blocks/TextBlock.php +++ b/src/Entities/Blocks/TextBlock.php @@ -30,7 +30,7 @@ protected static function createTextBlock(TextBlock $textBlock, array|string $te ] ]); } - + $textBlock->rawContent = [ "text" => $text ]; @@ -41,7 +41,7 @@ protected static function createTextBlock(TextBlock $textBlock, array|string $te } /** - * + * */ protected function fillFromRaw(): void { @@ -50,7 +50,7 @@ protected function fillFromRaw(): void } /** - * + * */ protected function fillContent(): void { diff --git a/src/Entities/Blocks/ToDo.php b/src/Entities/Blocks/ToDo.php index 53489af..3b74fff 100644 --- a/src/Entities/Blocks/ToDo.php +++ b/src/Entities/Blocks/ToDo.php @@ -15,12 +15,13 @@ class ToDo extends TextBlock { public static function create(array|string $textContent): ToDo { - $toDo = new ToDo(); + $toDo = new ToDo(); TextBlock::createTextBlock($toDo, $textContent); return $toDo; } - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "to_do"; parent::__construct($responseData); } diff --git a/src/Entities/Blocks/Toggle.php b/src/Entities/Blocks/Toggle.php index 55e7a75..df6d177 100644 --- a/src/Entities/Blocks/Toggle.php +++ b/src/Entities/Blocks/Toggle.php @@ -15,12 +15,13 @@ class Toggle extends TextBlock { public static function create(array|string $textContent): Toggle { - $toggle = new Toggle(); + $toggle = new Toggle(); TextBlock::createTextBlock($toggle, $textContent); return $toggle; } - function __construct(array $responseData = null){ + function __construct(array $responseData = null) + { $this->type = "toggle"; parent::__construct($responseData); } diff --git a/src/Entities/Collections/BlockCollection.php b/src/Entities/Collections/BlockCollection.php index 599c2a2..b27a4cf 100644 --- a/src/Entities/Collections/BlockCollection.php +++ b/src/Entities/Collections/BlockCollection.php @@ -16,9 +16,9 @@ class BlockCollection extends EntityCollection /** * will include unsupported blocks within your collection - * unsupported blocks are currently not supported by the Notion API + * unsupported blocks are currently not supported by the Notion API * they will be ignored (not included) in your collection by default - * + * * @return BlockCollection */ public function withUnsupported(): BlockCollection @@ -40,7 +40,7 @@ protected function collectChildren(): void /** * returns according blocks as collection - * + * * @return Collection */ public function asCollection(): Collection @@ -58,7 +58,7 @@ public function asCollection(): Collection /** * returns according blocks as collection and will only represent the textual content of the blocks * (this is useful if you only want to work with the blocks content and not with the whole block object) - * + * * @return Collection */ public function asTextCollection(): Collection diff --git a/src/Entities/Entity.php b/src/Entities/Entity.php index dfcd773..9f14a69 100644 --- a/src/Entities/Entity.php +++ b/src/Entities/Entity.php @@ -33,7 +33,7 @@ class Entity implements JsonSerializable */ public function __construct(array $responseData = null) { - if($responseData != null) $this->setResponseData($responseData); + if ($responseData != null) $this->setResponseData($responseData); } /** @@ -50,7 +50,7 @@ protected function setResponseData(array $responseData): void // Currently, the API returns not-found objects with status code 200 - // so we have to check here on the given status code in the paylaod, // if the object was not found. - if( + if ( $responseData['object'] === 'error' && Arr::exists($responseData, 'status') && $responseData['status'] === 404 ) { @@ -99,9 +99,10 @@ public function getId(): string } /** - * + * */ - public function setId($id): void{ + public function setId($id): void + { $this->id = $id; } @@ -124,7 +125,8 @@ public function jsonSerialize(): array /** * @return array */ - public function toArray(): array { + public function toArray(): array + { return get_object_vars($this); } } diff --git a/src/Entities/Page.php b/src/Entities/Page.php index 9626e0e..5fe183d 100644 --- a/src/Entities/Page.php +++ b/src/Entities/Page.php @@ -158,7 +158,7 @@ private function fillTitle(): void } /** - * + * */ private function fillPageUrl(): void { diff --git a/src/Entities/Properties/Checkbox.php b/src/Entities/Properties/Checkbox.php index 7d2db79..7198fb2 100644 --- a/src/Entities/Properties/Checkbox.php +++ b/src/Entities/Properties/Checkbox.php @@ -56,7 +56,8 @@ public function isChecked(): bool /** * @return string */ - public function asText(): string{ + public function asText(): string + { return ($this->getContent()) ? "true" : "false"; } } diff --git a/src/Entities/Properties/Date.php b/src/Entities/Properties/Date.php index bf00773..4b55f9a 100644 --- a/src/Entities/Properties/Date.php +++ b/src/Entities/Properties/Date.php @@ -32,7 +32,7 @@ public static function value(?DateTime $start, ?DateTime $end = null): Date $dateProperty->rawContent = [ "date" => [ "start" => $start->format("c"), - "end" => $end->format("c") + "end" => $end->format("c") ] ]; } else { @@ -64,7 +64,7 @@ protected function fillDate(): void $richDate->setStart(new DateTime($startAsIsoString)); } - + if (isset($this->rawContent["end"])) { $endAsIsoString = $this->rawContent["end"]; $richDate->setEnd(new DateTime($endAsIsoString)); diff --git a/src/Entities/Properties/Files.php b/src/Entities/Properties/Files.php index 8aa66db..d3344b6 100644 --- a/src/Entities/Properties/Files.php +++ b/src/Entities/Properties/Files.php @@ -26,7 +26,7 @@ protected function fillFromRaw(): void protected function fillFiles(): void { $this->content = new Collection(); - foreach($this->rawContent as $file){ + foreach ($this->rawContent as $file) { $this->content->add($file); } } diff --git a/src/Entities/Properties/Formula.php b/src/Entities/Properties/Formula.php index d710662..e8ab41d 100644 --- a/src/Entities/Properties/Formula.php +++ b/src/Entities/Properties/Formula.php @@ -22,12 +22,12 @@ protected function fillFromRaw(): void $this->formulaType = $this->rawContent['type']; - if ($this->formulaType == 'string' || $this->formulaType == 'number'|| $this->formulaType == 'boolean') { + if ($this->formulaType == 'string' || $this->formulaType == 'number' || $this->formulaType == 'boolean') { $this->content = $this->rawContent[$this->formulaType]; } else if ($this->formulaType == 'date') { $this->content = new RichDate(); - if(isset($this->rawContent[$this->formulaType]['start'])) $this->content->setStart(new DateTime($this->rawContent[$this->formulaType]['start'])); - if(isset($this->rawContent[$this->formulaType]['end'])) $this->content->setEnd(new DateTime($this->rawContent[$this->formulaType]['end'])); + if (isset($this->rawContent[$this->formulaType]['start'])) $this->content->setStart(new DateTime($this->rawContent[$this->formulaType]['start'])); + if (isset($this->rawContent[$this->formulaType]['end'])) $this->content->setEnd(new DateTime($this->rawContent[$this->formulaType]['end'])); } } diff --git a/src/Entities/Properties/MultiSelect.php b/src/Entities/Properties/MultiSelect.php index d8339ad..01b9afe 100644 --- a/src/Entities/Properties/MultiSelect.php +++ b/src/Entities/Properties/MultiSelect.php @@ -23,7 +23,7 @@ public static function value(array $names): MultiSelect $multiSelectRawContent = []; $selectItemCollection = new Collection(); - foreach($names as $name){ + foreach ($names as $name) { $selectItem = new SelectItem(); $selectItem->setName($name); $selectItemCollection->add($selectItem); diff --git a/src/Entities/Properties/People.php b/src/Entities/Properties/People.php index b4722b3..6b4470b 100644 --- a/src/Entities/Properties/People.php +++ b/src/Entities/Properties/People.php @@ -23,8 +23,8 @@ public static function value(array $userIds): People $peopleProperty->content = new Collection(); $peopleProperty->rawContent = ['people' => []]; - foreach($userIds as $userId){ - array_push($peopleProperty->rawContent['people'], ['object' => 'user', 'id' => $userId]); + foreach ($userIds as $userId) { + array_push($peopleProperty->rawContent['people'], ['object' => 'user', 'id' => $userId]); $peopleProperty->content->add(new User(['object' => 'user', 'id' => $userId])); } diff --git a/src/Entities/Properties/Relation.php b/src/Entities/Properties/Relation.php index b0a2bdf..1028724 100644 --- a/src/Entities/Properties/Relation.php +++ b/src/Entities/Properties/Relation.php @@ -21,7 +21,7 @@ public static function value(array $relationIds): Relation $relationProperty->content = new Collection(); $relationProperty->rawContent = ['relation' => []]; - foreach($relationIds as $relationId){ + foreach ($relationIds as $relationId) { array_push($relationProperty->rawContent['relation'], ['id' => $relationId]); $relationProperty->content->add($relationId); } @@ -45,7 +45,7 @@ protected function fillFromRaw(): void protected function fillRelation(): void { $this->content = new Collection(); - foreach($this->rawContent as $relationId){ + foreach ($this->rawContent as $relationId) { $this->content->add($relationId); } } diff --git a/src/Entities/PropertyItems/RichDate.php b/src/Entities/PropertyItems/RichDate.php index 4439b3d..e737df9 100644 --- a/src/Entities/PropertyItems/RichDate.php +++ b/src/Entities/PropertyItems/RichDate.php @@ -93,7 +93,6 @@ public function setStart($start): void /** - */ public function setEnd($end): void { diff --git a/src/Entities/PropertyItems/RichText.php b/src/Entities/PropertyItems/RichText.php index a0baed6..47983f4 100644 --- a/src/Entities/PropertyItems/RichText.php +++ b/src/Entities/PropertyItems/RichText.php @@ -16,7 +16,7 @@ class RichText extends Entity */ protected string $plainText = ''; - + /** * @param array $responseData */ diff --git a/src/Entities/PropertyItems/SelectItem.php b/src/Entities/PropertyItems/SelectItem.php index 0ba785d..bd3f892 100644 --- a/src/Entities/PropertyItems/SelectItem.php +++ b/src/Entities/PropertyItems/SelectItem.php @@ -47,7 +47,8 @@ protected function fillFromRaw(): void /** * */ - protected function fillName():void{ + protected function fillName(): void + { if (Arr::exists($this->responseData, 'name')) { $this->name = $this->responseData['name']; } @@ -56,7 +57,8 @@ protected function fillName():void{ /** * */ - protected function fillColor():void{ + protected function fillColor(): void + { if (Arr::exists($this->responseData, 'color')) { $this->color = $this->responseData['color']; } @@ -80,7 +82,6 @@ public function getName(): string } - /** * @param $color */ diff --git a/src/LaravelNotionApiServiceProvider.php b/src/LaravelNotionApiServiceProvider.php index 1d3c524..81acf5e 100644 --- a/src/LaravelNotionApiServiceProvider.php +++ b/src/LaravelNotionApiServiceProvider.php @@ -17,7 +17,7 @@ public function boot() { if ($this->app->runningInConsole()) { $this->publishes([ - __DIR__.'/../config/config.php' => config_path('laravel-notion-api.php'), + __DIR__ . '/../config/config.php' => config_path('laravel-notion-api.php'), ], 'config'); } } @@ -28,7 +28,7 @@ public function boot() public function register() { // Automatically apply the package configuration - $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-notion-api'); + $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'laravel-notion-api'); $this->app->singleton(Notion::class, function () { diff --git a/src/Query/Filter.php b/src/Query/Filter.php index efe4d63..0790daa 100644 --- a/src/Query/Filter.php +++ b/src/Query/Filter.php @@ -35,8 +35,8 @@ class Filter extends QueryHelper public function __construct( string $property, string $filterType = null, - array $filterConditions = null, - array $filterDefinition = null + array $filterConditions = null, + array $filterDefinition = null ) { parent::__construct(); From 27404c95da76fb50136bdae28ce395f69b2af3c4 Mon Sep 17 00:00:00 2001 From: Diana Scharf Date: Mon, 13 Sep 2021 22:27:25 +0200 Subject: [PATCH 09/10] Optimize imports --- src/Endpoints/Block.php | 8 ++++---- src/Endpoints/Database.php | 4 ++-- src/Endpoints/Databases.php | 4 ++-- src/Endpoints/Endpoint.php | 6 +++--- src/Endpoints/Pages.php | 4 +--- src/Endpoints/Search.php | 4 ++-- src/Endpoints/Users.php | 4 ++-- src/Entities/Blocks/BaseFileBlock.php | 4 ---- src/Entities/Blocks/Block.php | 2 +- src/Entities/Blocks/BulletedListItem.php | 5 ----- src/Entities/Blocks/ChildPage.php | 5 ----- src/Entities/Blocks/Embed.php | 4 ---- src/Entities/Blocks/File.php | 6 ------ src/Entities/Blocks/HeadingOne.php | 5 ----- src/Entities/Blocks/HeadingThree.php | 5 ----- src/Entities/Blocks/HeadingTwo.php | 5 ----- src/Entities/Blocks/Image.php | 6 ------ src/Entities/Blocks/NumberedListItem.php | 5 ----- src/Entities/Blocks/Paragraph.php | 6 ------ src/Entities/Blocks/Pdf.php | 6 ------ src/Entities/Blocks/TextBlock.php | 4 ---- src/Entities/Blocks/ToDo.php | 5 ----- src/Entities/Blocks/Toggle.php | 5 ----- src/Entities/Blocks/Video.php | 6 ------ src/Entities/Collections/BlockCollection.php | 2 +- src/Entities/Collections/DatabaseCollection.php | 2 +- src/Entities/Collections/EntityCollection.php | 10 +++++----- src/Entities/Collections/PageCollection.php | 2 +- src/Entities/Collections/UserCollection.php | 2 +- src/Entities/Contracts/Modifiable.php | 2 -- src/Entities/Database.php | 2 +- src/Entities/Entity.php | 4 ++-- src/Entities/Page.php | 4 ++-- src/Entities/Properties/CreatedTime.php | 1 - src/Entities/Properties/Date.php | 2 +- src/Entities/Properties/LastEditedTime.php | 1 - src/Entities/Properties/MultiSelect.php | 4 ++-- src/Entities/Properties/Property.php | 3 +-- src/Entities/Properties/Rollup.php | 1 - src/Entities/Properties/Select.php | 2 +- src/Entities/Properties/Text.php | 2 +- src/Entities/Properties/Title.php | 2 +- src/Entities/PropertyItems/RichDate.php | 2 +- src/Entities/PropertyItems/RichText.php | 2 +- src/Entities/PropertyItems/SelectItem.php | 2 +- src/Entities/User.php | 2 +- src/Notion.php | 14 +++++++------- src/Query/Filter.php | 2 +- src/Query/Sorting.php | 2 +- 49 files changed, 51 insertions(+), 141 deletions(-) diff --git a/src/Endpoints/Block.php b/src/Endpoints/Block.php index 395f207..063685c 100644 --- a/src/Endpoints/Block.php +++ b/src/Endpoints/Block.php @@ -2,11 +2,11 @@ namespace FiveamCode\LaravelNotionApi\Endpoints; -use FiveamCode\LaravelNotionApi\Notion; -use FiveamCode\LaravelNotionApi\Exceptions\NotionException; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; -use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection; use FiveamCode\LaravelNotionApi\Entities\Blocks\Block as BaseBlockEntity; +use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection; +use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use FiveamCode\LaravelNotionApi\Exceptions\NotionException; +use FiveamCode\LaravelNotionApi\Notion; /** * Class Block diff --git a/src/Endpoints/Database.php b/src/Endpoints/Database.php index 7032473..7f5a1f8 100644 --- a/src/Endpoints/Database.php +++ b/src/Endpoints/Database.php @@ -2,11 +2,11 @@ namespace FiveamCode\LaravelNotionApi\Endpoints; -use Illuminate\Support\Collection; +use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection; use FiveamCode\LaravelNotionApi\Notion; use FiveamCode\LaravelNotionApi\Query\Filter; use FiveamCode\LaravelNotionApi\Query\Sorting; -use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection; +use Illuminate\Support\Collection; /** * Class Database diff --git a/src/Endpoints/Databases.php b/src/Endpoints/Databases.php index c75cbb7..b18445e 100644 --- a/src/Endpoints/Databases.php +++ b/src/Endpoints/Databases.php @@ -2,10 +2,10 @@ namespace FiveamCode\LaravelNotionApi\Endpoints; +use FiveamCode\LaravelNotionApi\Entities\Collections\DatabaseCollection; use FiveamCode\LaravelNotionApi\Entities\Database; -use FiveamCode\LaravelNotionApi\Exceptions\NotionException; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; -use FiveamCode\LaravelNotionApi\Entities\Collections\DatabaseCollection; +use FiveamCode\LaravelNotionApi\Exceptions\NotionException; /** diff --git a/src/Endpoints/Endpoint.php b/src/Endpoints/Endpoint.php index e39ef59..eea2ec9 100644 --- a/src/Endpoints/Endpoint.php +++ b/src/Endpoints/Endpoint.php @@ -2,11 +2,11 @@ namespace FiveamCode\LaravelNotionApi\Endpoints; -use Illuminate\Http\Client\Response; +use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use FiveamCode\LaravelNotionApi\Exceptions\NotionException; use FiveamCode\LaravelNotionApi\Notion; use FiveamCode\LaravelNotionApi\Query\StartCursor; -use FiveamCode\LaravelNotionApi\Exceptions\NotionException; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Http\Client\Response; /** * Class Endpoint diff --git a/src/Endpoints/Pages.php b/src/Endpoints/Pages.php index c9b8132..01a9d96 100644 --- a/src/Endpoints/Pages.php +++ b/src/Endpoints/Pages.php @@ -3,11 +3,9 @@ namespace FiveamCode\LaravelNotionApi\Endpoints; use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection; -use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection; use FiveamCode\LaravelNotionApi\Entities\Page; -use FiveamCode\LaravelNotionApi\Exceptions\NotionException; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; -use FiveamCode\LaravelNotionApi\Notion; +use FiveamCode\LaravelNotionApi\Exceptions\NotionException; /** * Class Pages diff --git a/src/Endpoints/Search.php b/src/Endpoints/Search.php index 157da47..762e413 100644 --- a/src/Endpoints/Search.php +++ b/src/Endpoints/Search.php @@ -2,10 +2,10 @@ namespace FiveamCode\LaravelNotionApi\Endpoints; -use Illuminate\Support\Collection; +use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection; use FiveamCode\LaravelNotionApi\Notion; use FiveamCode\LaravelNotionApi\Query\Sorting; -use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection; +use Illuminate\Support\Collection; /** * Class Search diff --git a/src/Endpoints/Users.php b/src/Endpoints/Users.php index 20871d0..35f94f0 100644 --- a/src/Endpoints/Users.php +++ b/src/Endpoints/Users.php @@ -2,10 +2,10 @@ namespace FiveamCode\LaravelNotionApi\Endpoints; +use FiveamCode\LaravelNotionApi\Entities\Collections\UserCollection; use FiveamCode\LaravelNotionApi\Entities\User; -use FiveamCode\LaravelNotionApi\Exceptions\NotionException; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; -use FiveamCode\LaravelNotionApi\Entities\Collections\UserCollection; +use FiveamCode\LaravelNotionApi\Exceptions\NotionException; /** * Class Users diff --git a/src/Entities/Blocks/BaseFileBlock.php b/src/Entities/Blocks/BaseFileBlock.php index 597b098..ce27c18 100644 --- a/src/Entities/Blocks/BaseFileBlock.php +++ b/src/Entities/Blocks/BaseFileBlock.php @@ -2,12 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** * Class TextBlock diff --git a/src/Entities/Blocks/Block.php b/src/Entities/Blocks/Block.php index 176bf65..5575c08 100644 --- a/src/Entities/Blocks/Block.php +++ b/src/Entities/Blocks/Block.php @@ -3,9 +3,9 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; use DateTime; -use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Arr; /** * Class Block diff --git a/src/Entities/Blocks/BulletedListItem.php b/src/Entities/Blocks/BulletedListItem.php index 3867c4b..857f076 100644 --- a/src/Entities/Blocks/BulletedListItem.php +++ b/src/Entities/Blocks/BulletedListItem.php @@ -2,11 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class BulletedListItem * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/ChildPage.php b/src/Entities/Blocks/ChildPage.php index 6b8f88c..d0495a5 100644 --- a/src/Entities/Blocks/ChildPage.php +++ b/src/Entities/Blocks/ChildPage.php @@ -2,11 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class ChildPage * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/Embed.php b/src/Entities/Blocks/Embed.php index 9dae26a..9393513 100644 --- a/src/Entities/Blocks/Embed.php +++ b/src/Entities/Blocks/Embed.php @@ -2,12 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** * Class Paragraph diff --git a/src/Entities/Blocks/File.php b/src/Entities/Blocks/File.php index 238d19b..d793314 100644 --- a/src/Entities/Blocks/File.php +++ b/src/Entities/Blocks/File.php @@ -2,12 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class Paragraph * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/HeadingOne.php b/src/Entities/Blocks/HeadingOne.php index 908828a..7b7f415 100644 --- a/src/Entities/Blocks/HeadingOne.php +++ b/src/Entities/Blocks/HeadingOne.php @@ -2,11 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class HeadingOne * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/HeadingThree.php b/src/Entities/Blocks/HeadingThree.php index f260eb8..c55fe0b 100644 --- a/src/Entities/Blocks/HeadingThree.php +++ b/src/Entities/Blocks/HeadingThree.php @@ -2,11 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class HeadingThree * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/HeadingTwo.php b/src/Entities/Blocks/HeadingTwo.php index 94774d3..077b08c 100644 --- a/src/Entities/Blocks/HeadingTwo.php +++ b/src/Entities/Blocks/HeadingTwo.php @@ -2,11 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class HeadingTwo * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/Image.php b/src/Entities/Blocks/Image.php index 84ff24b..0e1a993 100644 --- a/src/Entities/Blocks/Image.php +++ b/src/Entities/Blocks/Image.php @@ -2,12 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class Paragraph * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/NumberedListItem.php b/src/Entities/Blocks/NumberedListItem.php index 5b85419..0a49d22 100644 --- a/src/Entities/Blocks/NumberedListItem.php +++ b/src/Entities/Blocks/NumberedListItem.php @@ -2,11 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class NumberedListItem * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/Paragraph.php b/src/Entities/Blocks/Paragraph.php index f4103de..c955830 100644 --- a/src/Entities/Blocks/Paragraph.php +++ b/src/Entities/Blocks/Paragraph.php @@ -2,12 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class Paragraph * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/Pdf.php b/src/Entities/Blocks/Pdf.php index 2846e01..027ab0d 100644 --- a/src/Entities/Blocks/Pdf.php +++ b/src/Entities/Blocks/Pdf.php @@ -2,12 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class Paragraph * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/TextBlock.php b/src/Entities/Blocks/TextBlock.php index 3d1fd5b..6184bed 100644 --- a/src/Entities/Blocks/TextBlock.php +++ b/src/Entities/Blocks/TextBlock.php @@ -2,12 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** * Class TextBlock diff --git a/src/Entities/Blocks/ToDo.php b/src/Entities/Blocks/ToDo.php index 3b74fff..80a1848 100644 --- a/src/Entities/Blocks/ToDo.php +++ b/src/Entities/Blocks/ToDo.php @@ -2,11 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class ToDo * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/Toggle.php b/src/Entities/Blocks/Toggle.php index df6d177..e56f6d8 100644 --- a/src/Entities/Blocks/Toggle.php +++ b/src/Entities/Blocks/Toggle.php @@ -2,11 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class Toggle * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Blocks/Video.php b/src/Entities/Blocks/Video.php index 4fdbb73..bc60685 100644 --- a/src/Entities/Blocks/Video.php +++ b/src/Entities/Blocks/Video.php @@ -2,12 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Blocks; -use DateTime; -use Illuminate\Support\Arr; -use FiveamCode\LaravelNotionApi\Entities\Entity; -use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; - /** * Class Paragraph * @package FiveamCode\LaravelNotionApi\Entities\Blocks diff --git a/src/Entities/Collections/BlockCollection.php b/src/Entities/Collections/BlockCollection.php index b27a4cf..0f1c224 100644 --- a/src/Entities/Collections/BlockCollection.php +++ b/src/Entities/Collections/BlockCollection.php @@ -2,8 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Collections; -use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Entities\Blocks\Block; +use Illuminate\Support\Collection; /** diff --git a/src/Entities/Collections/DatabaseCollection.php b/src/Entities/Collections/DatabaseCollection.php index a105990..f1942ab 100644 --- a/src/Entities/Collections/DatabaseCollection.php +++ b/src/Entities/Collections/DatabaseCollection.php @@ -2,8 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Collections; -use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Entities\Database; +use Illuminate\Support\Collection; /** * Class DatabaseCollection diff --git a/src/Entities/Collections/EntityCollection.php b/src/Entities/Collections/EntityCollection.php index 1fe2a04..38a8513 100644 --- a/src/Entities/Collections/EntityCollection.php +++ b/src/Entities/Collections/EntityCollection.php @@ -3,13 +3,13 @@ namespace FiveamCode\LaravelNotionApi\Entities\Collections; -use Illuminate\Support\Arr; -use Illuminate\Support\Collection; -use FiveamCode\LaravelNotionApi\Entities\Page; -use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Entities\Database; -use FiveamCode\LaravelNotionApi\Exceptions\NotionException; +use FiveamCode\LaravelNotionApi\Entities\Entity; +use FiveamCode\LaravelNotionApi\Entities\Page; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use FiveamCode\LaravelNotionApi\Exceptions\NotionException; +use Illuminate\Support\Arr; +use Illuminate\Support\Collection; /** diff --git a/src/Entities/Collections/PageCollection.php b/src/Entities/Collections/PageCollection.php index f24c211..e9279ec 100644 --- a/src/Entities/Collections/PageCollection.php +++ b/src/Entities/Collections/PageCollection.php @@ -2,8 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Collections; -use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Entities\Page; +use Illuminate\Support\Collection; /** diff --git a/src/Entities/Collections/UserCollection.php b/src/Entities/Collections/UserCollection.php index dccb25b..ecb26b1 100644 --- a/src/Entities/Collections/UserCollection.php +++ b/src/Entities/Collections/UserCollection.php @@ -2,8 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Collections; -use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Entities\User; +use Illuminate\Support\Collection; /** diff --git a/src/Entities/Contracts/Modifiable.php b/src/Entities/Contracts/Modifiable.php index 8db97c3..e1f6505 100644 --- a/src/Entities/Contracts/Modifiable.php +++ b/src/Entities/Contracts/Modifiable.php @@ -2,8 +2,6 @@ namespace FiveamCode\LaravelNotionApi\Entities\Contracts; -use FiveamCode\LaravelNotionApi\Entities\Properties\Property; - interface Modifiable { } \ No newline at end of file diff --git a/src/Entities/Database.php b/src/Entities/Database.php index 6626152..443f2a8 100644 --- a/src/Entities/Database.php +++ b/src/Entities/Database.php @@ -3,8 +3,8 @@ namespace FiveamCode\LaravelNotionApi\Entities; use DateTime; -use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Arr; /** diff --git a/src/Entities/Entity.php b/src/Entities/Entity.php index 9f14a69..863a1c5 100644 --- a/src/Entities/Entity.php +++ b/src/Entities/Entity.php @@ -3,10 +3,10 @@ namespace FiveamCode\LaravelNotionApi\Entities; use Carbon\Carbon; -use JsonSerializable; -use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Exceptions\NotionException; +use Illuminate\Support\Arr; +use JsonSerializable; /** * Class Entity diff --git a/src/Entities/Page.php b/src/Entities/Page.php index 5fe183d..1a9f2d9 100644 --- a/src/Entities/Page.php +++ b/src/Entities/Page.php @@ -10,8 +10,6 @@ use FiveamCode\LaravelNotionApi\Entities\Properties\Number; use FiveamCode\LaravelNotionApi\Entities\Properties\People; use FiveamCode\LaravelNotionApi\Entities\Properties\PhoneNumber; -use Illuminate\Support\Arr; -use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Entities\Properties\Property; use FiveamCode\LaravelNotionApi\Entities\Properties\Relation; use FiveamCode\LaravelNotionApi\Entities\Properties\Select; @@ -19,6 +17,8 @@ use FiveamCode\LaravelNotionApi\Entities\Properties\Title; use FiveamCode\LaravelNotionApi\Entities\Properties\Url; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Arr; +use Illuminate\Support\Collection; /** * Class Page diff --git a/src/Entities/Properties/CreatedTime.php b/src/Entities/Properties/CreatedTime.php index a07a96a..e08105f 100644 --- a/src/Entities/Properties/CreatedTime.php +++ b/src/Entities/Properties/CreatedTime.php @@ -4,7 +4,6 @@ use DateTime; use Exception; -use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichDate; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** diff --git a/src/Entities/Properties/Date.php b/src/Entities/Properties/Date.php index 4b55f9a..7e119f7 100644 --- a/src/Entities/Properties/Date.php +++ b/src/Entities/Properties/Date.php @@ -3,9 +3,9 @@ namespace FiveamCode\LaravelNotionApi\Entities\Properties; use DateTime; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichDate; +use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** * Class Date diff --git a/src/Entities/Properties/LastEditedTime.php b/src/Entities/Properties/LastEditedTime.php index e64aa5a..ddbb444 100644 --- a/src/Entities/Properties/LastEditedTime.php +++ b/src/Entities/Properties/LastEditedTime.php @@ -4,7 +4,6 @@ use DateTime; use Exception; -use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichDate; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** diff --git a/src/Entities/Properties/MultiSelect.php b/src/Entities/Properties/MultiSelect.php index 01b9afe..ff983e9 100644 --- a/src/Entities/Properties/MultiSelect.php +++ b/src/Entities/Properties/MultiSelect.php @@ -3,9 +3,9 @@ namespace FiveamCode\LaravelNotionApi\Entities\Properties; use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; -use Illuminate\Support\Collection; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\SelectItem; +use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Collection; /** * Class MultiSelect diff --git a/src/Entities/Properties/Property.php b/src/Entities/Properties/Property.php index e2b9555..2c5cdea 100644 --- a/src/Entities/Properties/Property.php +++ b/src/Entities/Properties/Property.php @@ -2,10 +2,9 @@ namespace FiveamCode\LaravelNotionApi\Entities\Properties; -use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; -use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Arr; /** * Class Property diff --git a/src/Entities/Properties/Rollup.php b/src/Entities/Properties/Rollup.php index 9c0fa89..52931ca 100644 --- a/src/Entities/Properties/Rollup.php +++ b/src/Entities/Properties/Rollup.php @@ -6,7 +6,6 @@ use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichDate; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use Illuminate\Support\Collection; -use Illuminate\Support\Str; /** * Class Rollup diff --git a/src/Entities/Properties/Select.php b/src/Entities/Properties/Select.php index 33a47bb..012c764 100644 --- a/src/Entities/Properties/Select.php +++ b/src/Entities/Properties/Select.php @@ -3,8 +3,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Properties; use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\SelectItem; +use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** * Class Select diff --git a/src/Entities/Properties/Text.php b/src/Entities/Properties/Text.php index 310fd19..efcb5c1 100644 --- a/src/Entities/Properties/Text.php +++ b/src/Entities/Properties/Text.php @@ -3,8 +3,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Properties; use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; +use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** * Class Text diff --git a/src/Entities/Properties/Title.php b/src/Entities/Properties/Title.php index c9c9195..f390c60 100644 --- a/src/Entities/Properties/Title.php +++ b/src/Entities/Properties/Title.php @@ -3,8 +3,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\Properties; use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable; -use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; +use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; /** * Class Title diff --git a/src/Entities/PropertyItems/RichDate.php b/src/Entities/PropertyItems/RichDate.php index e737df9..31e0224 100644 --- a/src/Entities/PropertyItems/RichDate.php +++ b/src/Entities/PropertyItems/RichDate.php @@ -3,8 +3,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\PropertyItems; use DateTime; -use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Entities\Entity; +use Illuminate\Support\Arr; /** * Class RichDate diff --git a/src/Entities/PropertyItems/RichText.php b/src/Entities/PropertyItems/RichText.php index 47983f4..9e09d76 100644 --- a/src/Entities/PropertyItems/RichText.php +++ b/src/Entities/PropertyItems/RichText.php @@ -2,8 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities\PropertyItems; -use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Entities\Entity; +use Illuminate\Support\Arr; /** * Class RichText diff --git a/src/Entities/PropertyItems/SelectItem.php b/src/Entities/PropertyItems/SelectItem.php index bd3f892..046b407 100644 --- a/src/Entities/PropertyItems/SelectItem.php +++ b/src/Entities/PropertyItems/SelectItem.php @@ -2,9 +2,9 @@ namespace FiveamCode\LaravelNotionApi\Entities\PropertyItems; -use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Entities\Entity; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Arr; /** * Class SelectItem diff --git a/src/Entities/User.php b/src/Entities/User.php index 211b5bd..2141812 100644 --- a/src/Entities/User.php +++ b/src/Entities/User.php @@ -2,8 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Entities; -use Illuminate\Support\Arr; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Arr; /** * Class User diff --git a/src/Notion.php b/src/Notion.php index 7639ce6..80954c0 100644 --- a/src/Notion.php +++ b/src/Notion.php @@ -2,17 +2,17 @@ namespace FiveamCode\LaravelNotionApi; -use Illuminate\Support\Collection; -use Illuminate\Support\Facades\Http; -use Illuminate\Http\Client\PendingRequest; -use FiveamCode\LaravelNotionApi\Endpoints\Pages; use FiveamCode\LaravelNotionApi\Endpoints\Block; -use FiveamCode\LaravelNotionApi\Endpoints\Search; -use FiveamCode\LaravelNotionApi\Endpoints\Users; -use FiveamCode\LaravelNotionApi\Endpoints\Endpoint; use FiveamCode\LaravelNotionApi\Endpoints\Database; use FiveamCode\LaravelNotionApi\Endpoints\Databases; +use FiveamCode\LaravelNotionApi\Endpoints\Endpoint; +use FiveamCode\LaravelNotionApi\Endpoints\Pages; +use FiveamCode\LaravelNotionApi\Endpoints\Search; +use FiveamCode\LaravelNotionApi\Endpoints\Users; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Http\Client\PendingRequest; +use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Http; /** diff --git a/src/Query/Filter.php b/src/Query/Filter.php index 0790daa..3a46861 100644 --- a/src/Query/Filter.php +++ b/src/Query/Filter.php @@ -2,8 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Query; -use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Collection; /** * Class Filter diff --git a/src/Query/Sorting.php b/src/Query/Sorting.php index 731972f..2a762bb 100644 --- a/src/Query/Sorting.php +++ b/src/Query/Sorting.php @@ -2,8 +2,8 @@ namespace FiveamCode\LaravelNotionApi\Query; -use Illuminate\Support\Collection; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; +use Illuminate\Support\Collection; /** * Class Sorting From e622b4122c577a65084a7800bfcc57818d6d02a7 Mon Sep 17 00:00:00 2001 From: JohGuentner <3506359+johguentner@users.noreply.github.com> Date: Sun, 19 Sep 2021 14:39:33 +0200 Subject: [PATCH 10/10] polish implementations - rename "BaseBlockEntity" to "BlockEntity" in BlockEndpoint for clearity - mark createFileBlock method in BaseFileBlock as final - replace array_push with array[] = [...] for better performance --- src/Endpoints/Block.php | 10 +++++----- src/Entities/Blocks/BaseFileBlock.php | 2 +- src/Entities/Blocks/TextBlock.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Endpoints/Block.php b/src/Endpoints/Block.php index 395f207..05968e9 100644 --- a/src/Endpoints/Block.php +++ b/src/Endpoints/Block.php @@ -6,7 +6,7 @@ use FiveamCode\LaravelNotionApi\Exceptions\NotionException; use FiveamCode\LaravelNotionApi\Exceptions\HandlingException; use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection; -use FiveamCode\LaravelNotionApi\Entities\Blocks\Block as BaseBlockEntity; +use FiveamCode\LaravelNotionApi\Entities\Blocks\Block as BlockEntity; /** * Class Block @@ -58,7 +58,7 @@ public function children(): BlockCollection * @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block * @throws HandlingException */ - public function append(array|BaseBlockEntity $appendices): BaseBlockEntity + public function append(array|BlockEntity $appendices): BlockEntity { if (!is_array($appendices)) { $appendices = [$appendices]; @@ -66,11 +66,11 @@ public function append(array|BaseBlockEntity $appendices): BaseBlockEntity $children = []; foreach ($appendices as $block) { - array_push($children, [ + $children[] = [ "object" => "block", "type" => $block->getType(), $block->getType() => $block->getRawContent() - ]); + ]; } $body = [ @@ -82,6 +82,6 @@ public function append(array|BaseBlockEntity $appendices): BaseBlockEntity $body ); - return new BaseBlockEntity($response->json()); + return new BlockEntity($response->json()); } } diff --git a/src/Entities/Blocks/BaseFileBlock.php b/src/Entities/Blocks/BaseFileBlock.php index 6f4f679..acc9458 100644 --- a/src/Entities/Blocks/BaseFileBlock.php +++ b/src/Entities/Blocks/BaseFileBlock.php @@ -15,7 +15,7 @@ */ class BaseFileBlock extends Block implements Modifiable { - protected static function createFileBlock(BaseFileBlock $fileBlock, string $url, string $caption = ""): BaseFileBlock + protected static final function createFileBlock(BaseFileBlock $fileBlock, string $url, string $caption = ""): BaseFileBlock { $fileBlock->rawContent = [ 'type' => 'external', diff --git a/src/Entities/Blocks/TextBlock.php b/src/Entities/Blocks/TextBlock.php index 67eeeea..22ecaaf 100644 --- a/src/Entities/Blocks/TextBlock.php +++ b/src/Entities/Blocks/TextBlock.php @@ -23,12 +23,12 @@ protected static function createTextBlock(TextBlock $textBlock, array|string $te $text = []; foreach ($textContent as $textItem) { - array_push($text, [ + $text[] = [ "type" => "text", "text" => [ "content" => $textItem ] - ]); + ]; } $textBlock->rawContent = [