-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for custom emoji (#48)
* feat: add support for custom emoji * style: improve code readability in BlockTest - Split long URL string into multiple lines for better readability in custom emoji test - Maintains same functionality while adhering to coding standards
- Loading branch information
Showing
4 changed files
with
154 additions
and
0 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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brd6\NotionSdkPhp\Resource\File; | ||
|
||
use Brd6\NotionSdkPhp\Resource\Property\CustomEmojiProperty; | ||
|
||
class CustomEmoji extends AbstractFile | ||
{ | ||
public const FILE_TYPE = 'custom_emoji'; | ||
|
||
protected ?CustomEmojiProperty $customEmoji = null; | ||
|
||
public static function getFileType(): string | ||
{ | ||
return self::FILE_TYPE; | ||
} | ||
|
||
protected function initialize(): void | ||
{ | ||
$data = (array) $this->getRawData()[$this->getType()]; | ||
$this->customEmoji = CustomEmojiProperty::fromRawData($data); | ||
} | ||
|
||
public function getCustomEmoji(): ?CustomEmojiProperty | ||
{ | ||
return $this->customEmoji; | ||
} | ||
|
||
public function setCustomEmoji(CustomEmojiProperty $customEmoji): self | ||
{ | ||
$this->customEmoji = $customEmoji; | ||
|
||
return $this; | ||
} | ||
} |
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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brd6\NotionSdkPhp\Resource\Property; | ||
|
||
class CustomEmojiProperty extends AbstractProperty | ||
{ | ||
protected string $id = ''; | ||
protected string $name = ''; | ||
protected string $url = ''; | ||
|
||
public static function fromRawData(array $rawData): self | ||
{ | ||
$property = new self(); | ||
|
||
$property->id = (string) $rawData['id']; | ||
$property->name = (string) $rawData['name']; | ||
$property->url = (string) $rawData['url']; | ||
|
||
return $property; | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(string $id): self | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function setUrl(string $url): self | ||
{ | ||
$this->url = $url; | ||
|
||
return $this; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Fixtures/client_blocks_retrieve_block_custom_emoji_200.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"object": "block", | ||
"id": "test-block-id", | ||
"created_time": "2022-03-01T18:42:00.000Z", | ||
"last_edited_time": "2022-03-01T18:54:00.000Z", | ||
"created_by": { | ||
"object": "user", | ||
"id": "1091c8fb-8b5a-4cc2-afe9-fdf0367e16d6" | ||
}, | ||
"last_edited_by": { | ||
"object": "user", | ||
"id": "1091c8fb-8b5a-4cc2-afe9-fdf0367e16d6" | ||
}, | ||
"has_children": false, | ||
"archived": false, | ||
"type": "callout", | ||
"callout": { | ||
"rich_text": [], | ||
"icon": { | ||
"type": "custom_emoji", | ||
"custom_emoji": { | ||
"id": "45ce454c-d427-4f53-9489-e5d0f3d1db6b", | ||
"name": "bufo", | ||
"url": "https://s3-us-west-2.amazonaws.com/public.notion-static.com/865e85fc-7442-44d3-b323-9b03a2111720/3c6796979c50f4aa.png" | ||
} | ||
}, | ||
"color": "default" | ||
} | ||
} |
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