diff --git a/src/Document/Components/ArticleThumbnail.php b/src/Document/Components/ArticleThumbnail.php new file mode 100644 index 0000000..7bf6c7f --- /dev/null +++ b/src/Document/Components/ArticleThumbnail.php @@ -0,0 +1,137 @@ +caption = $caption; + return $this; + } + + /** + * Set the accessibility caption for VoiceOver. + * + * @param string $caption The accessibility caption. + * + * @return $this + */ + public function setAccessibilityCaption(string $caption): self + { + $this->accessibilityCaption = $caption; + return $this; + } + + /** + * Set whether the image contains explicit content. + * + * @param bool $explicit Whether the content is explicit. + * + * @return $this + */ + public function setExplicitContent(bool $explicit): self + { + $this->explicitContent = $explicit; + return $this; + } + + /** + * {@inheritdoc} + * + * @return array + */ + public function jsonSerialize(): array + { + $data = $this->getBaseProperties(); + $data['URL'] = $this->url; + + if ($this->caption !== null) { + $data['caption'] = $this->caption; + } + + if ($this->accessibilityCaption !== null) { + $data['accessibilityCaption'] = $this->accessibilityCaption; + } + + if ($this->explicitContent !== null) { + $data['explicitContent'] = $this->explicitContent; + } + + return $data; + } +} diff --git a/src/Document/Components/ArticleTitle.php b/src/Document/Components/ArticleTitle.php new file mode 100644 index 0000000..cd859d3 --- /dev/null +++ b/src/Document/Components/ArticleTitle.php @@ -0,0 +1,25 @@ +explicitContent = $explicit; + return $this; + } + /** * {@inheritdoc} * @@ -112,6 +130,10 @@ public function jsonSerialize(): array $data['accessibilityCaption'] = $this->accessibilityCaption; } + if ($this->explicitContent !== null) { + $data['explicitContent'] = $this->explicitContent; + } + return $data; } } diff --git a/src/Document/Components/TextComponent.php b/src/Document/Components/TextComponent.php index 6437119..a535fb1 100644 --- a/src/Document/Components/TextComponent.php +++ b/src/Document/Components/TextComponent.php @@ -20,6 +20,9 @@ abstract class TextComponent extends Component /** @var string|null The text format (none, html, markdown). */ protected ?string $format = null; + /** @var array>|null Additions (links) applied to text ranges. */ + protected ?array $additions = null; + /** * @param string $text The raw text content. */ @@ -61,6 +64,22 @@ public function setFormat(string $format): static return $this; } + /** + * Set additions (link ranges) for the text component. + * + * Additions allow you to apply links to specific ranges of text. + * Note: Additions are not supported when format is 'html' or 'markdown'. + * + * @param array> $additions Array of addition objects with rangeStart, rangeLength, and link. + * @return static + * @see https://developer.apple.com/documentation/applenewsformat/addition + */ + public function setAdditions(array $additions): static + { + $this->additions = $additions; + return $this; + } + /** * @return array */ @@ -81,6 +100,10 @@ public function jsonSerialize(): array $data['format'] = $this->format; } + if ($this->additions !== null) { + $data['additions'] = $this->additions; + } + return $data; } } diff --git a/src/Request/MultipartBuilder.php b/src/Request/MultipartBuilder.php index 660fbbb..392ad4b 100644 --- a/src/Request/MultipartBuilder.php +++ b/src/Request/MultipartBuilder.php @@ -210,6 +210,7 @@ private function guessImageContentType(string $filename): string 'jpg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', + 'webp' => 'image/webp', default => 'application/octet-stream', }; } diff --git a/tests/Document/Components/TextComponentAdditionsTest.php b/tests/Document/Components/TextComponentAdditionsTest.php new file mode 100644 index 0000000..f499885 --- /dev/null +++ b/tests/Document/Components/TextComponentAdditionsTest.php @@ -0,0 +1,41 @@ + 'link', + 'rangeStart' => 19, + 'rangeLength' => 4, + 'URL' => 'https://example.com', + ], + ]; + + $body->setAdditions($additions); + + $data = $body->jsonSerialize(); + + $this->assertArrayHasKey('additions', $data); + $this->assertEquals($additions, $data['additions']); + } + + public function testAdditionsNotIncludedWhenNull(): void + { + $body = new Body('Simple text without links'); + + $data = $body->jsonSerialize(); + + $this->assertArrayNotHasKey('additions', $data); + } +}