Skip to content

Commit cddec0b

Browse files
committed
feat: add metadata support to EmailEndpoint
Added a `metadata` method to set custom metadata for emails. Updated tests to ensure correct behavior when metadata is provided. Fixed a typo in the headers method's PHPDoc.
1 parent a4e0c7a commit cddec0b

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/Endpoints/EmailEndpoint.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class EmailEndpoint extends Endpoint
1515
private ?string $idempotencyKey = null;
1616

1717
/**
18-
* Set the custom headeres.
18+
* Set the custom headers.
1919
*
2020
* @example ["Key" => "Value"]
2121
*
@@ -169,6 +169,20 @@ public function idempotencyKey(string $key): self
169169
return $this;
170170
}
171171

172+
/**
173+
* Set custom metadata.
174+
*
175+
* @example ["key" => "value"]
176+
*
177+
* @param array<string, string> $metadata The metadata object.
178+
*/
179+
public function metadata(array $metadata): self
180+
{
181+
$this->payload['metadata'] = $metadata;
182+
183+
return $this;
184+
}
185+
172186
/**
173187
* Send the composed email using the current payload.
174188
*

tests/Endpoints/EmailEndpointTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,23 @@
233233
->subject('Test Subject')
234234
->send();
235235
});
236+
237+
test('it handles metadata', function () {
238+
$this->httpClient
239+
->shouldReceive('post')
240+
->once()
241+
->with('/v1/send', [
242+
'from' => 'sender@example.com',
243+
'to' => ['recipient@example.com'],
244+
'subject' => 'Test Subject',
245+
'metadata' => ['foo' => 'bar'],
246+
], [])
247+
->andReturn(['message_id' => '123', 'status' => 'pending']);
248+
249+
$this->endpoint
250+
->from('sender@example.com')
251+
->to('recipient@example.com')
252+
->subject('Test Subject')
253+
->metadata(['foo' => 'bar'])
254+
->send();
255+
});

0 commit comments

Comments
 (0)