Skip to content

Commit 5af94b7

Browse files
committed
added commits
1 parent 5a08f49 commit 5af94b7

File tree

11 files changed

+144
-35
lines changed

11 files changed

+144
-35
lines changed

src/Endpoints/Blocks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function find(string $blockId): Block
2525
$jsonArray = $this->getJson(
2626
$this->url(Endpoint::BLOCKS . "/" . $blockId . "/children")
2727
);
28-
return new Block($this->notion, $jsonArray);
28+
return new Block($jsonArray);
2929
}
3030

3131
public function create(): array{

src/Endpoints/Databases.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function find(string $databaseId): Database
3737
$jsonArray = $this->getJson(
3838
$this->url(Endpoint::DATABASES . "/" . $databaseId)
3939
);
40-
return new Database($this->notion, $jsonArray);
40+
return new Database($jsonArray);
4141
}
4242

4343
public function query(): array

src/Endpoints/Pages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function find(string $pageId): Page
2626
$jsonArray = $this->getJson(
2727
$this->url(Endpoint::PAGES . "/" . $pageId)
2828
);
29-
return new Page($this->notion, $jsonArray);
29+
return new Page($jsonArray);
3030
}
3131

3232
public function create(): array{

src/Endpoints/Users.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function find(string $userId): User
3939
$jsonArray = $this->getJson(
4040
$this->url(Endpoint::USERS . "/" . $userId)
4141
);
42-
return new User($this->notion, $jsonArray);
42+
return new User($jsonArray);
4343
}
4444

4545
public function limit()

src/Entities/Block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ class Block extends Entity
1111
protected function setRaw(array $raw): void
1212
{
1313
parent::setRaw($raw);
14-
if ($raw['object'] != 'block') throw WrapperException::instance("invalid json-array: the given object is not a block");
14+
if ($raw['object'] !== 'block') throw WrapperException::instance("invalid json-array: the given object is not a block");
1515
}
1616
}

src/Entities/Database.php

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,78 @@
22

33
namespace FiveamCode\LaravelNotionApi\Entities;
44

5+
use DateTime;
6+
use Carbon\Carbon;
57
use FiveamCode\LaravelNotionApi\Exceptions\WrapperException;
68
use FiveamCode\LaravelNotionApi\Notion;
9+
use Illuminate\Support\Arr;
10+
711

812
class Database extends Entity
913
{
14+
private string $title = "";
15+
private array $rawTitle = [];
16+
private array $rawProperties = [];
17+
private DateTime $createdTime;
18+
private DateTime $lastEditedTime;
19+
1020
protected function setRaw(array $raw): void
1121
{
1222
parent::setRaw($raw);
13-
if ($raw['object'] != 'database') throw WrapperException::instance("invalid json-array: the given object is not a database");
23+
if ($raw['object'] !== 'database') throw WrapperException::instance("invalid json-array: the given object is not a database");
24+
25+
if (Arr::exists($raw, 'title') && is_array($raw['title'])) {
26+
$this->title = Arr::first($raw['title'], null, ['plain_text' => ''])['plain_text'];
27+
$this->rawTitle = $raw['title'];
28+
}
29+
30+
if (Arr::exists($raw, 'properties')) {
31+
$this->rawProperties = $raw['properties'];
32+
}
33+
34+
if (Arr::exists($raw, 'created_time')) {
35+
$this->createdTime = new Carbon($raw['created_time']);
36+
}
37+
38+
if (Arr::exists($raw, 'last_edited_time')) {
39+
$this->lastEditedTime = new Carbon($raw['last_edited_time']);
40+
}
41+
}
42+
43+
public function getTitle(): string
44+
{
45+
return $this->title;
46+
}
47+
48+
public function getProperties()
49+
{
50+
//TODO: return collection of property-entities (id, type, title)
51+
throw new \Exception("not implemented yet");
52+
}
53+
54+
public function getRawTitle(): array
55+
{
56+
return $this->rawTitle;
57+
}
58+
59+
public function getRawProperties(): array
60+
{
61+
return $this->rawProperties;
62+
}
63+
64+
public function getPropertyNames(): array
65+
{
66+
return array_keys($this->rawProperties);
67+
}
68+
69+
public function getCreatedTime(): DateTime
70+
{
71+
return $this->createdTime;
72+
}
73+
74+
75+
public function getLastEditedTime(): DateTime
76+
{
77+
return $this->lastEditedTime;
1478
}
1579
}

src/Entities/Entity.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ class Entity
1010
{
1111
private string $id;
1212
private array $raw;
13-
private Notion $notion;
1413

15-
public function __construct(Notion $notion = null, array $raw = null)
14+
public function __construct(array $raw = null)
1615
{
17-
$this->notion = $notion;
1816
$this->setRaw($raw);
1917
}
2018

@@ -28,12 +26,12 @@ protected function setRaw(array $raw): void
2826
}
2927

3028

31-
public function getId()
29+
public function getId() : string
3230
{
3331
return $this->id;
3432
}
3533

36-
public function getRaw()
34+
public function getRaw() : array
3735
{
3836
return $this->raw;
3937
}

src/Entities/EntityCollection.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,32 @@
44

55
use FiveamCode\LaravelNotionApi\Exceptions\WrapperException;
66
use FiveamCode\LaravelNotionApi\Notion;
7+
use Illuminate\Support\Arr;
8+
79

810
//TODO:WORK IN PROGRESS
911
class EntityCollection
1012
{
11-
protected string $raw;
13+
protected array $raw;
1214
protected Notion $notion;
1315

14-
public function __construct(Notion $notion = null, string $raw = null)
16+
public function __construct(Notion $notion = null, array $raw = null)
1517
{
1618
$this->notion = $notion;
1719
$this->setRaw($raw);
1820
}
1921

20-
protected function setRaw(string $raw):void{
21-
if (!isset($raw['object'])) throw WrapperException::instance("invalid json-array: no object given");
22-
if (!isset($raw['results'])) throw WrapperException::instance("invalid json-array: no results given");
22+
protected function setRaw(array $raw): void
23+
{
24+
if (!Arr::exists($raw, 'object')) throw WrapperException::instance("invalid json-array: no object given");
25+
if (!Arr::exists($raw, 'results')) throw WrapperException::instance("invalid json-array: no results given");
2326
if ($raw['object'] != 'list') throw WrapperException::instance("invalid json-array: the given object is not a list");
2427

2528
$this->raw = $raw;
26-
2729
}
2830

29-
public function getRaw(){
31+
public function getRaw(): array
32+
{
3033
return $this->raw;
3134
}
3235
}

src/Entities/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class Page extends Entity
1010
protected function setRaw(array $raw): void
1111
{
1212
parent::setRaw($raw);
13-
if ($raw['object'] != 'page') throw WrapperException::instance("invalid json-array: the given object is not a page");
13+
if ($raw['object'] !== 'page') throw WrapperException::instance("invalid json-array: the given object is not a page");
1414
}
1515
}

src/Entities/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class User extends Entity
1010
protected function setRaw(array $raw): void
1111
{
1212
parent::setRaw($raw);
13-
if ($raw['object'] != 'user') throw WrapperException::instance("invalid json-array: the given object is not a user");
13+
if ($raw['object'] !== 'user') throw WrapperException::instance("invalid json-array: the given object is not a user");
1414
}
1515
}

0 commit comments

Comments
 (0)