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 9c6aaac

Browse files
committed
code analysis, docs and reformatting
1 parent e44df66 commit 9c6aaac

Some content is hidden

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

49 files changed

+1108
-301
lines changed

‎README.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,22 @@ $notion->pages()->find($yourPageId);
5353
```
5454

5555
#### Query Database
56+
5657
```php
5758
// Queries a specific database and returns a collection of pages (= database entries)
5859
$sortings = new Collection();
5960
$filters = new Collection();
6061

6162
$sortings
62-
->add(Sorting::propertySort("Ordered", "ascending"));
63+
->add(Sorting::propertySort('Ordered', 'ascending'));
6364
$sortings
64-
->add(Sorting::timestampSort("created_time", "ascending"));
65+
->add(Sorting::timestampSort('created_time', 'ascending'));
6566

6667
$filters
67-
->add(Filter::textFilter("title", ["contains" => "new"]));
68+
->add(Filter::textFilter('title', ['contains' => 'new']));
6869
// or
6970
$filters
70-
->add(Filter::rawFilter("Tags", ["multi_select" => ["contains" => "great"]]));
71+
->add(Filter::rawFilter('Tags', ['multi_select' => ['contains' => 'great']]));
7172

7273
$notion
7374
->database($yourDatabaseId)

‎src/Endpoints/Block.php‎

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

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5-
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
65
use FiveamCode\LaravelNotionApi\Notion;
76
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
7+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
88
use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection;
99

10+
/**
11+
* Class Block
12+
* @package FiveamCode\LaravelNotionApi\Endpoints
13+
*/
1014
class Block extends Endpoint
1115
{
16+
/**
17+
* @var string
18+
*/
1219
private string $blockId;
1320

21+
/**
22+
* Block constructor.
23+
* @param Notion $notion
24+
* @param string $blockId
25+
* @throws HandlingException
26+
* @throws \FiveamCode\LaravelNotionApi\Exceptions\LaravelNotionAPIException
27+
*/
1428
public function __construct(Notion $notion, string $blockId)
1529
{
1630
parent::__construct($notion);
@@ -23,18 +37,24 @@ public function __construct(Notion $notion, string $blockId)
2337
* notion-api-docs: https://developers.notion.com/reference/get-block-children
2438
*
2539
* @return BlockCollection
40+
* @throws HandlingException
41+
* @throws NotionException
2642
*/
2743
public function children(): BlockCollection
2844
{
2945
$response = $this->get(
30-
$this->url(Endpoint::BLOCKS . "/" . $this->blockId . "/children" . "?{$this->buildPaginationQuery()}")
46+
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . '/children' . "?{$this->buildPaginationQuery()}")
3147
);
3248

3349
return new BlockCollection($response->json());
3450
}
3551

52+
/**
53+
* @return array
54+
* @throws HandlingException
55+
*/
3656
public function create(): array
3757
{
38-
throw new HandlingException("Not implemented");
58+
throw new HandlingException('Not implemented');
3959
}
4060
}

‎src/Endpoints/Database.php‎

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

33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

5-
use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection;
65
use Illuminate\Support\Collection;
76
use FiveamCode\LaravelNotionApi\Notion;
87
use FiveamCode\LaravelNotionApi\Query\Filter;
98
use FiveamCode\LaravelNotionApi\Query\Sorting;
9+
use FiveamCode\LaravelNotionApi\Entities\Collections\PageCollection;
1010

11+
/**
12+
* Class Database
13+
* @package FiveamCode\LaravelNotionApi\Endpoints
14+
*/
1115
class Database extends Endpoint
1216
{
17+
/**
18+
* @var string
19+
*/
1320
private string $databaseId;
1421

22+
/**
23+
* @var Collection
24+
*/
1525
private Collection $filter;
26+
27+
/**
28+
* @var Collection
29+
*/
1630
private Collection $sorts;
1731

1832

33+
/**
34+
* Database constructor.
35+
* @param string $databaseId
36+
* @param Notion $notion
37+
* @throws \FiveamCode\LaravelNotionApi\Exceptions\HandlingException
38+
* @throws \FiveamCode\LaravelNotionApi\Exceptions\LaravelNotionAPIException
39+
*/
1940
public function __construct(string $databaseId, Notion $notion)
2041
{
2142
$this->databaseId = $databaseId;
@@ -26,21 +47,26 @@ public function __construct(string $databaseId, Notion $notion)
2647
parent::__construct($notion);
2748
}
2849

50+
/**
51+
* @return PageCollection
52+
* @throws \FiveamCode\LaravelNotionApi\Exceptions\HandlingException
53+
* @throws \FiveamCode\LaravelNotionApi\Exceptions\NotionException
54+
*/
2955
public function query(): PageCollection
3056
{
3157
$postData = [];
3258

3359
if ($this->sorts->isNotEmpty())
34-
$postData["sorts"] = Sorting::sortQuery($this->sorts);
60+
$postData['sorts'] = Sorting::sortQuery($this->sorts);
3561

3662
if ($this->filter->isNotEmpty())
37-
$postData["filter"]["or"] = Filter::filterQuery($this->filter); // TODO Compound filters!
63+
$postData['filter']['or'] = Filter::filterQuery($this->filter); // TODO Compound filters!
3864

3965
if ($this->startCursor !== null)
40-
$postData["start_cursor"] = $this->startCursor;
66+
$postData['start_cursor'] = $this->startCursor;
4167

4268
if ($this->pageSize !== null)
43-
$postData["page_size"] = $this->pageSize;
69+
$postData['page_size'] = $this->pageSize;
4470

4571

4672
$response = $this
@@ -53,13 +79,21 @@ public function query(): PageCollection
5379
return new PageCollection($response);
5480
}
5581

56-
public function filterBy(Collection $filter)
82+
/**
83+
* @param Collection $filter
84+
* @return $this
85+
*/
86+
public function filterBy(Collection $filter): Database
5787
{
5888
$this->filter = $filter;
5989
return $this;
6090
}
6191

62-
public function sortBy(Collection $sorts)
92+
/**
93+
* @param Collection $sorts
94+
* @return $this
95+
*/
96+
public function sortBy(Collection $sorts): Database
6397
{
6498
$this->sorts = $sorts;
6599
return $this;

‎src/Endpoints/Databases.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace FiveamCode\LaravelNotionApi\Endpoints;
44

55
use FiveamCode\LaravelNotionApi\Entities\Database;
6+
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
67
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
78
use FiveamCode\LaravelNotionApi\Entities\Collections\DatabaseCollection;
89

@@ -23,6 +24,8 @@ class Databases extends Endpoint implements EndpointInterface
2324
* notion-api-docs: https://developers.notion.com/reference/get-databases
2425
*
2526
* @return DatabaseCollection
27+
* @throws HandlingException
28+
* @throws NotionException
2629
*/
2730
public function all(): DatabaseCollection
2831
{
@@ -38,6 +41,7 @@ public function all(): DatabaseCollection
3841
* @param string $databaseId
3942
* @return Database
4043
* @throws HandlingException
44+
* @throws NotionException
4145
*/
4246
public function find(string $databaseId): Database
4347
{

‎src/Endpoints/Endpoint.php‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,54 @@
44

55
use Illuminate\Http\Client\Response;
66
use FiveamCode\LaravelNotionApi\Notion;
7-
use GuzzleHttp\Promise\PromiseInterface;
87
use FiveamCode\LaravelNotionApi\Query\StartCursor;
98
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
109
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
11-
use FiveamCode\LaravelNotionApi\Exceptions\LaravelNotionAPIException;
1210

11+
/**
12+
* Class Endpoint
13+
* @package FiveamCode\LaravelNotionApi\Endpoints
14+
*/
1315
class Endpoint
1416
{
15-
const BASE_URL = 'https://api.notion.com/';
16-
const DATABASES = 'databases';
17-
const BLOCKS = 'blocks';
18-
const PAGES = 'pages';
19-
const USERS = 'users';
20-
const SEARCH = 'search';
17+
publicconst BASE_URL = 'https://api.notion.com/';
18+
publicconst DATABASES = 'databases';
19+
publicconst BLOCKS = 'blocks';
20+
publicconst PAGES = 'pages';
21+
publicconst USERS = 'users';
22+
publicconst SEARCH = 'search';
2123

24+
/**
25+
* @var Notion
26+
*/
2227
public Notion $notion;
2328

29+
/**
30+
* @var StartCursor|null
31+
*/
2432
protected ?StartCursor $startCursor = null;
33+
34+
/**
35+
* @var int
36+
*/
2537
protected int $pageSize = 100;
2638

39+
/**
40+
* @var Response|null
41+
*/
2742
protected ?Response $response = null;
2843

2944
/**
3045
* Endpoint constructor.
3146
* @param Notion $notion
3247
* @throws HandlingException
33-
* @throws LaravelNotionAPIException
3448
*/
3549
public function __construct(Notion $notion)
3650
{
3751
$this->notion = $notion;
3852

3953
if ($this->notion->getConnection() === null) {
40-
throw HandlingException::instance("Connection could not be established, please check your token.");
54+
throw HandlingException::instance('Connection could not be established, please check your token.');
4155
}
4256
}
4357

@@ -69,10 +83,11 @@ protected function getJson(string $url): array
6983

7084
/**
7185
* @param string $url
72-
* @throws HandlingException
86+
* @return Response
7387
* @throws NotionException
88+
* @throws HandlingException
7489
*/
75-
protected function get(string $url)
90+
protected function get(string $url): Response
7691
{
7792
$response = $this->notion->getConnection()->get($url);
7893

@@ -86,9 +101,11 @@ protected function get(string $url)
86101
/**
87102
* @param string $url
88103
* @param array $body
89-
* @return PromiseInterface|Response
104+
* @return Response
105+
* @throws HandlingException
106+
* @throws NotionException
90107
*/
91-
protected function post(string $url, array $body)
108+
protected function post(string $url, array $body): Response
92109
{
93110
$response = $this->notion->getConnection()->post($url, $body);
94111

@@ -105,7 +122,7 @@ protected function post(string $url, array $body)
105122
*/
106123
protected function buildPaginationQuery(): string
107124
{
108-
$paginationQuery = "";
125+
$paginationQuery = '';
109126

110127
if ($this->pageSize !== null)
111128
$paginationQuery = "page_size={$this->pageSize}&";
@@ -131,12 +148,11 @@ public function limit(int $limit): Endpoint
131148
* @param StartCursor $startCursor
132149
* @return Endpoint
133150
* @throws HandlingException
134-
* @throws LaravelNotionAPIException
135151
*/
136152
public function offset(StartCursor $startCursor): Endpoint
137153
{
138154
// toDo
139-
throw HandlingException::instance("Not implemented yet.");
155+
throw HandlingException::instance('Not implemented yet.', compact($startCursor));
140156
}
141157

142158
}

‎src/Endpoints/EndpointInterface.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
use FiveamCode\LaravelNotionApi\Entities\Entity;
66

7+
/**
8+
* Interface EndpointInterface
9+
* @package FiveamCode\LaravelNotionApi\Endpoints
10+
*/
711
interface EndpointInterface
812
{
13+
/**
14+
* @param string $id
15+
* @return Entity
16+
*/
917
public function find(string $id): Entity;
1018
}

‎src/Endpoints/Pages.php‎

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

55
use FiveamCode\LaravelNotionApi\Entities\Page;
6-
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
76
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
7+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
88

9+
/**
10+
* Class Pages
11+
* @package FiveamCode\LaravelNotionApi\Endpoints
12+
*/
913
class Pages extends Endpoint implements EndpointInterface
1014
{
1115

@@ -15,27 +19,37 @@ class Pages extends Endpoint implements EndpointInterface
1519
* notion-api-docs: https://developers.notion.com/reference/get-page
1620
*
1721
* @param string $pageId
18-
* @return array
22+
* @return Page
23+
* @throws HandlingException
24+
* @throws NotionException
1925
*/
2026
public function find(string $pageId): Page
2127
{
2228
$response = $this->get(
23-
$this->url(Endpoint::PAGES . "/" . $pageId)
29+
$this->url(Endpoint::PAGES . '/' . $pageId)
2430
);
2531

2632
return new Page($response->json());
2733
}
2834

35+
/**
36+
* @return array
37+
* @throws HandlingException
38+
*/
2939
public function create(): array
3040
{
3141
//toDo
32-
throw new HandlingException("Not implemented");
42+
throw new HandlingException('Not implemented');
3343
}
3444

3545

46+
/**
47+
* @return array
48+
* @throws HandlingException
49+
*/
3650
public function updateProperties(): array
3751
{
3852
//toDo
39-
throw new HandlingException("Not implemented");
53+
throw new HandlingException('Not implemented');
4054
}
4155
}

0 commit comments

Comments
(0)

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