Skip to content
26 changes: 26 additions & 0 deletions src/Endpoints/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,37 @@ public function append(array|BlockEntity $appendices): BlockEntity
"children" => $children
];


$response = $this->patch(
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . '/children' . ""),
$body
);

return new BlockEntity($response->json());
}


/**
* Update one specific Block
* url: https://api.notion.com/{version}/blocks/{block_id} [patch]
* notion-api-docs: https://developers.notion.com/reference/update-a-block
*
* @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block
* @throws HandlingException
*/
public function update(BlockEntity $block): BlockEntity
{
$body = [
"object" => "block",
"type" => $block->getType(),
$block->getType() => $block->getRawContent()
];

$response = $this->patch(
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . ""),
$body
);

return new BlockEntity($response->json());
}
}
4 changes: 2 additions & 2 deletions src/Endpoints/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public function limit(int $limit): Endpoint
*/
public function offset(StartCursor $startCursor): Endpoint
{
// toDo
throw HandlingException::instance('Not implemented yet.', compact($startCursor));
$this->startCursor = $startCursor;
return $this;
}

}
12 changes: 12 additions & 0 deletions src/Entities/Blocks/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public function getType(): string
return $this->type;
}

/**
* @return string
*/
public function setType(string $type): void
{
$this->type = $type;
}

/**
* @return array
*/
Expand Down Expand Up @@ -166,6 +174,10 @@ public function setContent($content)
$this->content = $content;
}

public function setRawContent($rawContent){
$this->rawContent = $rawContent;
}

/**
* @param $rawContent
* @return Block
Expand Down
15 changes: 15 additions & 0 deletions src/Entities/Blocks/TextBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ protected static function createTextBlock(TextBlock $textBlock, array|string $te
return $textBlock;
}

public function setContent($content): TextBlock
{
$this->getContent()->setPlainText($content);

$text[] = [
"type" => "text",
"text" => [
"content" => $content
]
];

$this->rawContent['text'] = $text;
return $this;
}

/**
*
*/
Expand Down
5 changes: 3 additions & 2 deletions src/Entities/Properties/LastEditedTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTime;
use Exception;
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
use Throwable;

/**
* Class LastEditedTime
Expand All @@ -20,10 +21,10 @@ protected function fillFromRaw(): void
parent::fillFromRaw();

try {
if ($this->rawContent !== null) {
if (is_string($this->rawContent) && $this->rawContent !== null) {
$this->content = new DateTime($this->rawContent);
}
} catch (Exception $e) {
} catch (Throwable $e) {
throw HandlingException::instance('The content of last_edited_time is not a valid ISO 8601 date time string.');
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/LaravelNotionApi.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Query/Filters/Operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Operators
# ToDo: Make this a enum with PHP 8.1
const EQUALS = 'equals';
const DOES_NOT_EQUAL = 'does_not_equal';
const CONTAINS = 'contain';
const CONTAINS = 'contains';
const DOES_NOT_CONTAIN = 'does_not_contain';
const STARTS_WITH = 'starts_with';
const ENDS_WITH = 'ends_with';
Expand Down
4 changes: 4 additions & 0 deletions src/Query/StartCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public function __construct(string $cursor)
{
$this->cursor = $cursor;
}

public function __toString() {
return $this->cursor;
}
}