-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathPage.php
74 lines (63 loc) · 2.08 KB
/
Page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace FiveamCode\LaravelNotionApi\Endpoints;
use FiveamCode\LaravelNotionApi\Entities\Collections\EntityCollection;
use FiveamCode\LaravelNotionApi\Entities\Collections\UserCollection;
use FiveamCode\LaravelNotionApi\Entities\Properties\Property;
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
use FiveamCode\LaravelNotionApi\Notion;
/**
* Class Page.
*/
class Page extends Endpoint
{
/**
* @var ?string
*/
private ?string $pageId = null;
public function __construct(Notion $notion, string $pageId)
{
parent::__construct($notion);
$this->pageId = $pageId;
}
/**
* Retrieve a page property item.
*
* @url https://api.notion.com/{version}/pages/{page_id}/properties/{property_id} [get]
*
* @reference https://developers.notion.com/reference/retrieve-a-page-property.
*
* @param string $propertyId
* @return Page
*
* @throws HandlingException
* @throws NotionException
*/
public function property(string $propertyId): Property|EntityCollection
{
$response = $this->get(
$this->url(Endpoint::PAGES.'/'.$this->pageId.'/'.'properties'.'/'.rawurlencode(rawurldecode($propertyId)))
);
$rawContent = $response->json();
if ($rawContent['object'] === 'list') {
if (count($rawContent['results']) === 0) {
return new EntityCollection();
}
$type = $rawContent['type'] ?? $rawContent['results'][0]['type'];
// if($type === 'rollup'){
// dd($rawContent['type']);
// }
// if($)
// dd("HI");
return match ($type) {
'people' => new UserCollection($rawContent),
// 'rollup' => new Collection
default => dd($rawContent) && new EntityCollection($rawContent)
};
}
return Property::fromObjectResponse(
id: $propertyId,
rawContent: $rawContent
);
}
}