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 15d3c73

Browse files
Merge pull request #35 from 5am-code/dev
Dev for v0.6.0
2 parents 11c11e1 + 235271b commit 15d3c73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1582
-284
lines changed

‎src/Endpoints/Block.php

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5-
use FiveamCode\LaravelNotionApi\Notion;
6-
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
7-
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
5+
use FiveamCode\LaravelNotionApi\Entities\Blocks\Block as BlockEntity;
86
use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection;
7+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
8+
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
9+
use FiveamCode\LaravelNotionApi\Notion;
910

1011
/**
1112
* Class Block
@@ -31,9 +32,29 @@ public function __construct(Notion $notion, string $blockId)
3132
$this->blockId = $blockId;
3233
}
3334

35+
/**
36+
* Retrieve a block
37+
* url: https://api.notion.com/{version}/blocks/{block_id}
38+
* notion-api-docs: https://developers.notion.com/reference/retrieve-a-block
39+
*
40+
* @param string $blockId
41+
* @return BlockEntity
42+
* @throws HandlingException
43+
* @throws NotionException
44+
*/
45+
public function retrieve(): BlockEntity
46+
{
47+
48+
$response = $this->get(
49+
$this->url(Endpoint::BLOCKS . '/' . $this->blockId)
50+
);
51+
52+
return BlockEntity::fromResponse($response->json());
53+
}
54+
3455
/**
3556
* Retrieve block children
36-
* url: https://api.notion.com/{version}/blocks/{block_id}/children
57+
* url: https://api.notion.com/{version}/blocks/{block_id}/children [get]
3758
* notion-api-docs: https://developers.notion.com/reference/get-block-children
3859
*
3960
* @return BlockCollection
@@ -50,11 +71,37 @@ public function children(): BlockCollection
5071
}
5172

5273
/**
53-
* @return array
74+
* Append one Block or an array of Blocks
75+
* url: https://api.notion.com/{version}/blocks/{block_id}/children [patch]
76+
* notion-api-docs: https://developers.notion.com/reference/patch-block-children
77+
*
78+
* @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block
5479
* @throws HandlingException
5580
*/
56-
public function create(): array
81+
public function append(array|BlockEntity$appendices): BlockEntity
5782
{
58-
throw new HandlingException('Not implemented');
83+
if (!is_array($appendices)) {
84+
$appendices = [$appendices];
85+
}
86+
$children = [];
87+
88+
foreach ($appendices as $block) {
89+
$children[] = [
90+
"object" => "block",
91+
"type" => $block->getType(),
92+
$block->getType() => $block->getRawContent()
93+
];
94+
}
95+
96+
$body = [
97+
"children" => $children
98+
];
99+
100+
$response = $this->patch(
101+
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . '/children' . ""),
102+
$body
103+
);
104+
105+
return new BlockEntity($response->json());
59106
}
60107
}

‎src/Endpoints/Database.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5-
use Illuminate\Support\Collection;
5+
use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection;
66
use FiveamCode\LaravelNotionApi\Notion;
7-
use FiveamCode\LaravelNotionApi\Query\Filter;
7+
use FiveamCode\LaravelNotionApi\Query\Filters\Filter;
88
use FiveamCode\LaravelNotionApi\Query\Sorting;
9-
use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection;
9+
use Illuminate\Support\Collection;
1010

1111
/**
1212
* Class Database
@@ -68,7 +68,6 @@ public function query(): PageCollection
6868
if ($this->pageSize !== null)
6969
$postData['page_size'] = $this->pageSize;
7070

71-
7271
$response = $this
7372
->post(
7473
$this->url(Endpoint::DATABASES . "/{$this->databaseId}/query"),

‎src/Endpoints/Databases.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5+
use FiveamCode\LaravelNotionApi\Entities\Collections\DatabaseCollection;
56
use FiveamCode\LaravelNotionApi\Entities\Database;
6-
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
77
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
8-
use FiveamCode\LaravelNotionApi\Entities\Collections\DatabaseCollection;
8+
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
99

1010

1111
/**
@@ -26,6 +26,7 @@ class Databases extends Endpoint implements EndpointInterface
2626
* @return DatabaseCollection
2727
* @throws HandlingException
2828
* @throws NotionException
29+
* @deprecated
2930
*/
3031
public function all(): DatabaseCollection
3132
{
@@ -36,7 +37,7 @@ public function all(): DatabaseCollection
3637
/**
3738
* Retrieve a database
3839
* url: https://api.notion.com/{version}/databases/{database_id}
39-
* notion-api-docs: https://developers.notion.com/reference/get-database
40+
* notion-api-docs: https://developers.notion.com/reference/retrieve-a-database
4041
*
4142
* @param string $databaseId
4243
* @return Database

‎src/Endpoints/Endpoint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5-
use Illuminate\Http\Client\Response;
5+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
6+
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
67
use FiveamCode\LaravelNotionApi\Notion;
78
use FiveamCode\LaravelNotionApi\Query\StartCursor;
8-
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
9-
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
9+
use Illuminate\Http\Client\Response;
1010

1111
/**
1212
* Class Endpoint

‎src/Endpoints/Pages.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5+
use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection;
56
use FiveamCode\LaravelNotionApi\Entities\Page;
6-
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
77
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
8+
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
89

910
/**
1011
* Class Pages

‎src/Endpoints/Search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5-
use Illuminate\Support\Collection;
5+
use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection;
66
use FiveamCode\LaravelNotionApi\Notion;
77
use FiveamCode\LaravelNotionApi\Query\Sorting;
8-
use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection;
8+
use Illuminate\Support\Collection;
99

1010
/**
1111
* Class Search

‎src/Endpoints/Users.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5+
use FiveamCode\LaravelNotionApi\Entities\Collections\UserCollection;
56
use FiveamCode\LaravelNotionApi\Entities\User;
6-
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
77
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
8-
use FiveamCode\LaravelNotionApi\Entities\Collections\UserCollection;
8+
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
99

1010
/**
1111
* Class Users

‎src/Entities/Blocks/BaseFileBlock.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace FiveamCode\LaravelNotionApi\Entities\Blocks;
4+
5+
use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable;
6+
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText;
7+
8+
/**
9+
* Class TextBlock
10+
* @package FiveamCode\LaravelNotionApi\Entities\Blocks
11+
*/
12+
class BaseFileBlock extends Block implements Modifiable
13+
{
14+
protected static final function createFileBlock(BaseFileBlock $fileBlock, string $url, string $caption = ""): BaseFileBlock
15+
{
16+
$fileBlock->rawContent = [
17+
'type' => 'external',
18+
'caption' => [
19+
[
20+
'type' => 'text',
21+
'text' => [
22+
'content' => $caption
23+
]
24+
]
25+
],
26+
'external' => [
27+
'url' => $url,
28+
]
29+
];
30+
31+
$fileBlock->fillContent();
32+
33+
return $fileBlock;
34+
}
35+
36+
private string $hostingType = "";
37+
private string $url = "";
38+
private RichText $caption;
39+
40+
41+
/**
42+
*
43+
*/
44+
protected function fillFromRaw(): void
45+
{
46+
parent::fillFromRaw();
47+
$this->fillContent();
48+
}
49+
50+
/**
51+
*
52+
*/
53+
protected function fillContent(): void
54+
{
55+
$this->hostingType = $this->rawContent['type'];
56+
$this->url = $this->rawContent[$this->hostingType]['url'];
57+
$this->caption = new RichText($this->rawContent['caption']);
58+
$this->content = $this->url;
59+
}
60+
61+
public function getUrl()
62+
{
63+
return $this->url;
64+
}
65+
66+
public function getHostingType()
67+
{
68+
return $this->hostingType;
69+
}
70+
71+
public function getCaption()
72+
{
73+
return $this->caption;
74+
}
75+
}

‎src/Entities/Blocks/Block.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace FiveamCode\LaravelNotionApi\Entities\Blocks;
44

55
use DateTime;
6-
use Illuminate\Support\Arr;
76
use FiveamCode\LaravelNotionApi\Entities\Entity;
87
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
8+
use Illuminate\Support\Arr;
99

1010
/**
1111
* Class Block
@@ -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()];
@@ -146,7 +146,7 @@ public function getLastEditedTime(): DateTime
146146
}
147147

148148
/**
149-
*
149+
*
150150
*/
151151
public function getContent()
152152
{
@@ -156,11 +156,16 @@ public function getContent()
156156
/**
157157
* @return string
158158
*/
159-
public function asText(): string
159+
public function asText(): string
160160
{
161161
return $this->text;
162162
}
163163

164+
public function setContent($content)
165+
{
166+
$this->content = $content;
167+
}
168+
164169
/**
165170
* @param $rawContent
166171
* @return Block
@@ -173,6 +178,7 @@ public static function fromResponse($rawContent): Block
173178
return $block;
174179
}
175180

181+
176182
/**
177183
* Maps the type of a block to the corresponding package class by converting the type name.
178184
*
@@ -189,6 +195,11 @@ private static function mapTypeToClass(string $type): string
189195
case 'paragraph':
190196
case 'to_do':
191197
case 'toggle':
198+
case 'embed':
199+
case 'image':
200+
case 'video':
201+
case 'file':
202+
case 'pdf':
192203
$class = str_replace('_', '', ucwords($type, '_'));
193204
return "FiveamCode\\LaravelNotionApi\\Entities\\Blocks\\" . $class;
194205
case 'heading_1':

‎src/Entities/Blocks/BulletedListItem.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
namespace FiveamCode\LaravelNotionApi\Entities\Blocks;
44

5-
use DateTime;
6-
use Illuminate\Support\Arr;
7-
use FiveamCode\LaravelNotionApi\Entities\Entity;
8-
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
9-
105
/**
116
* Class BulletedListItem
127
* @package FiveamCode\LaravelNotionApi\Entities\Blocks
138
*/
149
class BulletedListItem extends TextBlock
1510
{
11+
public static function create(array|string $textContent): BulletedListItem
12+
{
13+
$bulletedListItem = new BulletedListItem();
14+
TextBlock::createTextBlock($bulletedListItem, $textContent);
15+
return $bulletedListItem;
16+
}
17+
18+
function __construct(array $responseData = null)
19+
{
20+
$this->type = "bulleted_list_item";
21+
parent::__construct($responseData);
22+
}
1623
}

0 commit comments

Comments
(0)

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