Skip to content

add block-update functionality + flexible content #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
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