Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a21fc04

Browse files
Merge pull request #47 from 5am-code/feature/block-update
add block-update functionality + flexible content
2 parents ac6fc2f + f978f58 commit a21fc04

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

‎src/Endpoints/Block.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,37 @@ public function append(array|BlockEntity $appendices): BlockEntity
9797
"children" => $children
9898
];
9999

100+
100101
$response = $this->patch(
101102
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . '/children' . ""),
102103
$body
103104
);
104105

105106
return new BlockEntity($response->json());
106107
}
108+
109+
110+
/**
111+
* Update one specific Block
112+
* url: https://api.notion.com/{version}/blocks/{block_id} [patch]
113+
* notion-api-docs: https://developers.notion.com/reference/update-a-block
114+
*
115+
* @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block
116+
* @throws HandlingException
117+
*/
118+
public function update(BlockEntity $block): BlockEntity
119+
{
120+
$body = [
121+
"object" => "block",
122+
"type" => $block->getType(),
123+
$block->getType() => $block->getRawContent()
124+
];
125+
126+
$response = $this->patch(
127+
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . ""),
128+
$body
129+
);
130+
131+
return new BlockEntity($response->json());
132+
}
107133
}

‎src/Entities/Blocks/Block.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ public function getType(): string
113113
return $this->type;
114114
}
115115

116+
/**
117+
* @return string
118+
*/
119+
public function setType(string $type): void
120+
{
121+
$this->type = $type;
122+
}
123+
116124
/**
117125
* @return array
118126
*/
@@ -166,6 +174,10 @@ public function setContent($content)
166174
$this->content = $content;
167175
}
168176

177+
public function setRawContent($rawContent){
178+
$this->rawContent = $rawContent;
179+
}
180+
169181
/**
170182
* @param $rawContent
171183
* @return Block

‎src/Entities/Blocks/TextBlock.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ protected static function createTextBlock(TextBlock $textBlock, array|string $te
3636
return $textBlock;
3737
}
3838

39+
public function setContent($content): TextBlock
40+
{
41+
$this->getContent()->setPlainText($content);
42+
43+
$text[] = [
44+
"type" => "text",
45+
"text" => [
46+
"content" => $content
47+
]
48+
];
49+
50+
$this->rawContent['text'] = $text;
51+
return $this;
52+
}
53+
3954
/**
4055
*
4156
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /