Skip to content

Apply fixes from StyleCI #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

return [
/**
* The default Notion API version to use.
*/
'version' => 'v1',
/**
* The default Notion API version to use.
*/
'version' => 'v1',

/**
* Your Notion API token.
*/
'notion-api-token' => env('NOTION_API_TOKEN', '')
];
/**
* Your Notion API token.
*/
'notion-api-token' => env('NOTION_API_TOKEN', ''),
];
54 changes: 28 additions & 26 deletions src/Endpoints/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use FiveamCode\LaravelNotionApi\Notion;

/**
* Class Block
* @package FiveamCode\LaravelNotionApi\Endpoints
* Class Block.
*/
class Block extends Endpoint
{
Expand All @@ -21,8 +20,10 @@ class Block extends Endpoint

/**
* Block constructor.
* @param Notion $notion
* @param string $blockId
*
* @param Notion $notion
* @param string $blockId
*
* @throws HandlingException
* @throws \FiveamCode\LaravelNotionApi\Exceptions\LaravelNotionAPIException
*/
Expand All @@ -35,18 +36,18 @@ public function __construct(Notion $notion, string $blockId)
/**
* Retrieve a block
* url: https://api.notion.com/{version}/blocks/{block_id}
* notion-api-docs: https://developers.notion.com/reference/retrieve-a-block
* notion-api-docs: https://developers.notion.com/reference/retrieve-a-block.
*
* @param string $blockId
* @param string $blockId
* @return BlockEntity
*
* @throws HandlingException
* @throws NotionException
*/
public function retrieve(): BlockEntity
{

$response = $this->get(
$this->url(Endpoint::BLOCKS . '/' . $this->blockId)
$this->url(Endpoint::BLOCKS.'/'.$this->blockId)
);

return BlockEntity::fromResponse($response->json());
Expand All @@ -55,16 +56,17 @@ public function retrieve(): BlockEntity
/**
* Retrieve block children
* url: https://api.notion.com/{version}/blocks/{block_id}/children [get]
* notion-api-docs: https://developers.notion.com/reference/get-block-children
* notion-api-docs: https://developers.notion.com/reference/get-block-children.
*
* @return BlockCollection
*
* @throws HandlingException
* @throws NotionException
*/
public function children(): BlockCollection
{
$response = $this->get(
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . '/children' . "?{$this->buildPaginationQuery()}")
$this->url(Endpoint::BLOCKS.'/'.$this->blockId.'/children'."?{$this->buildPaginationQuery()}")
);

return new BlockCollection($response->json());
Expand All @@ -73,62 +75,62 @@ public function children(): BlockCollection
/**
* Append one Block or an array of Blocks
* url: https://api.notion.com/{version}/blocks/{block_id}/children [patch]
* notion-api-docs: https://developers.notion.com/reference/patch-block-children
* notion-api-docs: https://developers.notion.com/reference/patch-block-children.
*
* @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block
*
* @throws HandlingException
*/
public function append($appendices): BlockEntity
{
if(!is_array($appendices) && !$appendices instanceof BlockEntity) {
if (! is_array($appendices) && ! $appendices instanceof BlockEntity) {
throw new HandlingException('$appendices must be an array or instance of BlockEntity');
}

if (!is_array($appendices)) {
if (! is_array($appendices)) {
$appendices = [$appendices];
}
$children = [];

foreach ($appendices as $block) {
$children[] = [
"object" => "block",
"type" => $block->getType(),
$block->getType() => $block->getRawContent()
'object' => 'block',
'type' => $block->getType(),
$block->getType() => $block->getRawContent(),
];
}

$body = [
"children" => $children
'children' => $children,
];


$response = $this->patch(
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . '/children' . ""),
$this->url(Endpoint::BLOCKS.'/'.$this->blockId.'/children'.''),
$body
);

return new BlockEntity($response->json());
}


/**
* Update one specific Block
* Update one specific Block
* url: https://api.notion.com/{version}/blocks/{block_id} [patch]
* notion-api-docs: https://developers.notion.com/reference/update-a-block
* notion-api-docs: https://developers.notion.com/reference/update-a-block.
*
* @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block
*
* @throws HandlingException
*/
public function update(BlockEntity $block): BlockEntity
{
$body = [
"object" => "block",
"type" => $block->getType(),
$block->getType() => $block->getRawContent()
'object' => 'block',
'type' => $block->getType(),
$block->getType() => $block->getRawContent(),
];

$response = $this->patch(
$this->url(Endpoint::BLOCKS . '/' . $this->blockId . ""),
$this->url(Endpoint::BLOCKS.'/'.$this->blockId.''),
$body
);

Expand Down
33 changes: 20 additions & 13 deletions src/Endpoints/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use Illuminate\Support\Collection;

/**
* Class Database
* @package FiveamCode\LaravelNotionApi\Endpoints
* Class Database.
*/
class Database extends Endpoint
{
Expand All @@ -29,11 +28,12 @@ class Database extends Endpoint
*/
private Collection $sorts;


/**
* Database constructor.
* @param string $databaseId
* @param Notion $notion
*
* @param string $databaseId
* @param Notion $notion
*
* @throws \FiveamCode\LaravelNotionApi\Exceptions\HandlingException
* @throws \FiveamCode\LaravelNotionApi\Exceptions\LaravelNotionAPIException
*/
Expand All @@ -49,28 +49,33 @@ public function __construct(string $databaseId, Notion $notion)

/**
* @return PageCollection
*
* @throws \FiveamCode\LaravelNotionApi\Exceptions\HandlingException
* @throws \FiveamCode\LaravelNotionApi\Exceptions\NotionException
*/
public function query(): PageCollection
{
$postData = [];

if ($this->sorts->isNotEmpty())
if ($this->sorts->isNotEmpty()) {
$postData['sorts'] = Sorting::sortQuery($this->sorts);
}

if ($this->filter->isNotEmpty())
$postData['filter']['or'] = Filter::filterQuery($this->filter); // TODO Compound filters!
if ($this->filter->isNotEmpty()) {
$postData['filter']['or'] = Filter::filterQuery($this->filter);
} // TODO Compound filters!

if ($this->startCursor !== null)
if ($this->startCursor !== null) {
$postData['start_cursor'] = $this->startCursor;
}

if ($this->pageSize !== null)
if ($this->pageSize !== null) {
$postData['page_size'] = $this->pageSize;
}

$response = $this
->post(
$this->url(Endpoint::DATABASES . "/{$this->databaseId}/query"),
$this->url(Endpoint::DATABASES."/{$this->databaseId}/query"),
$postData
)
->json();
Expand All @@ -79,22 +84,24 @@ public function query(): PageCollection
}

/**
* @param Collection $filter
* @param Collection $filter
* @return $this
*/
public function filterBy(Collection $filter): Database
{
$this->filter = $filter;

return $this;
}

/**
* @param Collection $sorts
* @param Collection $sorts
* @return $this
*/
public function sortBy(Collection $sorts): Database
{
$this->sorts = $sorts;

return $this;
}
}
19 changes: 10 additions & 9 deletions src/Endpoints/Databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,48 @@
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;


/**
* Class Databases
* Class Databases.
*
* This endpoint is not recommended by Notion anymore.
* Use the search() endpoint instead.
*
* @package FiveamCode\LaravelNotionApi\Endpoints
*/
class Databases extends Endpoint implements EndpointInterface
{
/**
* List databases
* url: https://api.notion.com/{version}/databases
* notion-api-docs: https://developers.notion.com/reference/get-databases
* notion-api-docs: https://developers.notion.com/reference/get-databases.
*
* @return DatabaseCollection
*
* @throws HandlingException
* @throws NotionException
*
* @deprecated
*/
public function all(): DatabaseCollection
{
$resultData = $this->getJson($this->url(Endpoint::DATABASES) . "?{$this->buildPaginationQuery()}");
$resultData = $this->getJson($this->url(Endpoint::DATABASES)."?{$this->buildPaginationQuery()}");

return new DatabaseCollection($resultData);
}

/**
* Retrieve a database
* url: https://api.notion.com/{version}/databases/{database_id}
* notion-api-docs: https://developers.notion.com/reference/retrieve-a-database
* notion-api-docs: https://developers.notion.com/reference/retrieve-a-database.
*
* @param string $databaseId
* @param string $databaseId
* @return Database
*
* @throws HandlingException
* @throws NotionException
*/
public function find(string $databaseId): Database
{
$result = $this
->getJson($this->url(Endpoint::DATABASES . "/{$databaseId}"));
->getJson($this->url(Endpoint::DATABASES."/{$databaseId}"));

return new Database($result);
}
Expand Down
Loading