Skip to content

Commit 9c7d72d

Browse files
committed
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)
1 parent e1de3e8 commit 9c7d72d

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

src/Entities/Blocks/Block.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function fillFromRaw(): void
6969
{
7070
$this->fillId();
7171
$this->fillType();
72-
$this->fillContent();
72+
$this->fillRawContent();
7373
$this->fillHasChildren();
7474
$this->fillCreatedTime();
7575
$this->fillLastEditedTime();
@@ -88,7 +88,7 @@ private function fillType(): void
8888
/**
8989
*
9090
*/
91-
private function fillContent(): void
91+
private function fillRawContent(): void
9292
{
9393
if (Arr::exists($this->responseData, $this->getType())) {
9494
$this->rawContent = $this->responseData[$this->getType()];
@@ -193,6 +193,7 @@ private static function mapTypeToClass(string $type): string
193193
case 'child_page':
194194
case 'paragraph':
195195
case 'to_do':
196+
case 'embed':
196197
case 'toggle':
197198
$class = str_replace('_', '', ucwords($type, '_'));
198199
return "FiveamCode\\LaravelNotionApi\\Entities\\Blocks\\" . $class;

src/Entities/Blocks/ChildPage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
class ChildPage extends Block
1515
{
16+
function __construct(array $responseData = null){
17+
$this->type = "child_page";
18+
parent::__construct($responseData);
19+
}
20+
1621
/**
1722
*
1823
*/

src/Entities/Blocks/Embed.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace FiveamCode\LaravelNotionApi\Entities\Blocks;
4+
5+
use DateTime;
6+
use Illuminate\Support\Arr;
7+
use FiveamCode\LaravelNotionApi\Entities\Entity;
8+
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText;
9+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
10+
11+
/**
12+
* Class Paragraph
13+
* @package FiveamCode\LaravelNotionApi\Entities\Blocks
14+
*/
15+
class Embed extends Block
16+
{
17+
private RichText $caption;
18+
private string $url = "";
19+
20+
function __construct(array $responseData = null){
21+
$this->type = "embed";
22+
parent::__construct($responseData);
23+
}
24+
25+
/**
26+
*
27+
*/
28+
protected function fillFromRaw(): void
29+
{
30+
parent::fillFromRaw();
31+
$this->fillContent();
32+
}
33+
34+
/**
35+
*
36+
*/
37+
protected function fillContent(): void
38+
{
39+
$this->url = $this->rawContent['url'];
40+
$this->caption = new RichText($this->rawContent['caption']);
41+
$this->content = $this->url;
42+
}
43+
44+
public function getUrl(){
45+
return $this->url;
46+
}
47+
48+
public function getCaption(){
49+
return $this->caption;
50+
}
51+
}

0 commit comments

Comments
 (0)