Skip to content

Commit 973b154

Browse files
authored
Merge pull request #39 from 5am-code/dev
Patch for typo, type-check, removing unused file and block-update-functionality
2 parents 15d3c73 + a21fc04 commit 973b154

File tree

8 files changed

+63
-17
lines changed

8 files changed

+63
-17
lines changed

src/Endpoints/Block.php

+26
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/Endpoints/Endpoint.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ public function limit(int $limit): Endpoint
169169
*/
170170
public function offset(StartCursor $startCursor): Endpoint
171171
{
172-
// toDo
173-
throw HandlingException::instance('Not implemented yet.', compact($startCursor));
172+
$this->startCursor = $startCursor;
173+
return $this;
174174
}
175175

176176
}

src/Entities/Blocks/Block.php

+12
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

+15
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
*/

src/Entities/Properties/LastEditedTime.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DateTime;
66
use Exception;
77
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
8+
use Throwable;
89

910
/**
1011
* Class LastEditedTime
@@ -20,10 +21,10 @@ protected function fillFromRaw(): void
2021
parent::fillFromRaw();
2122

2223
try {
23-
if ($this->rawContent !== null) {
24+
if (is_string($this->rawContent) && $this->rawContent !== null) {
2425
$this->content = new DateTime($this->rawContent);
2526
}
26-
} catch (Exception $e) {
27+
} catch (Throwable $e) {
2728
throw HandlingException::instance('The content of last_edited_time is not a valid ISO 8601 date time string.');
2829
}
2930
}

src/LaravelNotionApi.php

-12
This file was deleted.

src/Query/Filters/Operators.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Operators
99
# ToDo: Make this a enum with PHP 8.1
1010
const EQUALS = 'equals';
1111
const DOES_NOT_EQUAL = 'does_not_equal';
12-
const CONTAINS = 'contain';
12+
const CONTAINS = 'contains';
1313
const DOES_NOT_CONTAIN = 'does_not_contain';
1414
const STARTS_WITH = 'starts_with';
1515
const ENDS_WITH = 'ends_with';

src/Query/StartCursor.php

+4
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ public function __construct(string $cursor)
2121
{
2222
$this->cursor = $cursor;
2323
}
24+
25+
public function __toString() {
26+
return $this->cursor;
27+
}
2428
}

0 commit comments

Comments
 (0)