-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementation for retreiving page property items
- incl. some tests
- Loading branch information
1 parent
b5b978c
commit 8f98375
Showing
5 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace FiveamCode\LaravelNotionApi\Endpoints; | ||
|
||
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 | ||
{ | ||
$response = $this->get( | ||
$this->url(Endpoint::PAGES . '/' . $this->pageId . '/' . 'properties' . '/' . urlencode($propertyId)) | ||
); | ||
|
||
return Property::fromResponse( | ||
propertyKey: null, | ||
rawContent: $response->json() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Carbon\Carbon; | ||
use FiveamCode\LaravelNotionApi\Entities\Collections\CommentCollection; | ||
use FiveamCode\LaravelNotionApi\Entities\Comment; | ||
use FiveamCode\LaravelNotionApi\Entities\Properties\Property; | ||
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText; | ||
use FiveamCode\LaravelNotionApi\Exceptions\NotionException; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
$httpRecorder = null; | ||
|
||
beforeEach(function () { | ||
$this->httpRecorder = Http::recordAndFakeLater([ | ||
'https://api.notion.com/v1/pages*', | ||
'https://api.notion.com/v1/databases*', | ||
])->storeIn('snapshots/page-property-items'); | ||
}); | ||
|
||
it('should fetch specific property items of a page', function () { | ||
|
||
$this->httpRecorder->nameForNextRequest('database-for-properties'); | ||
$databaseStructure = \Notion::databases()->find('cdd4befe814144f7b1eecb9c123bd4fb'); | ||
|
||
$propertyKeys = $databaseStructure->getProperties()->map(fn ($o) => $o->getTitle()); | ||
|
||
foreach ($propertyKeys as $propertyKey) { | ||
try { | ||
|
||
if ($propertyKey == 'Rollup' || $propertyKey == 'Person' || $propertyKey == 'Name') continue; | ||
$id = $databaseStructure->getProperty($propertyKey)->getId(); | ||
$property = \Notion::page('f1884dca3885460e93f52bf4da7cce8e')->property($id); | ||
|
||
expect($property)->toBeInstanceOf(Property::class); | ||
} catch (\Exception $e) { | ||
// dd($id); | ||
dd($propertyKey, $e->getMessage()); | ||
} | ||
} | ||
}); |