Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: resend/resend-php
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.12.0
Choose a base ref
...
head repository: resend/resend-php
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.13.0
Choose a head ref
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Aug 15, 2024

  1. feat: Add support for email schedule (#57)

    jayanratna authored Aug 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c74926e View commit details
Showing with 76 additions and 1 deletion.
  1. +28 −0 src/Service/Email.php
  2. +10 −0 src/ValueObjects/ResourceUri.php
  3. +13 −1 src/ValueObjects/Transporter/Payload.php
  4. +25 −0 tests/Service/Email.php
28 changes: 28 additions & 0 deletions src/Service/Email.php
Original file line number Diff line number Diff line change
@@ -43,4 +43,32 @@ public function send(array $parameters): \Resend\Email
{
return $this->create($parameters);
}

/**
* Update a scheduled email with the given ID.
*
* @see https://resend.com/docs/api-reference/emails/update-email
*/
public function update(string $id, array $parameters): \Resend\Email
{
$payload = Payload::update('emails', $id, $parameters);

$result = $this->transporter->request($payload);

return $this->createResource('emails', $result);
}

/**
* Cancel a scheduled email with the given ID.
*
* @see https://resend.com/docs/api-reference/emails/cancel-email
*/
public function cancel(string $id): \Resend\Email
{
$payload = Payload::cancel('emails', $id);

$result = $this->transporter->request($payload);

return $this->createResource('emails', $result);
}
}
10 changes: 10 additions & 0 deletions src/ValueObjects/ResourceUri.php
Original file line number Diff line number Diff line change
@@ -57,12 +57,22 @@ public static function delete(string $resource, string $id): self

/**
* Create a new Resource URI value object that verifies the given resource.
*
* @deprecated Use withAction instead
*/
public static function verify(string $resource, string $id): self
{
return new self("{$resource}/{$id}/verify");
}

/**
* Create a new Resource URI value object with the given action.
*/
public static function withAction(string $resource, string $id, string $action): self
{
return new self("{$resource}/{$id}/{$action}");
}

/**
* Returns the string representation of the object.
*/
14 changes: 13 additions & 1 deletion src/ValueObjects/Transporter/Payload.php
Original file line number Diff line number Diff line change
@@ -90,7 +90,19 @@ public static function verify(string $resource, string $id): self
{
$contentType = ContentType::JSON;
$method = Method::POST;
$uri = ResourceUri::verify($resource, $id);
$uri = ResourceUri::withAction($resource, $id, 'verify');

return new self($contentType, $method, $uri);
}

/**
* Create a new Transporter Payload instance.
*/
public static function cancel(string $resource, string $id): self
{
$contentType = ContentType::JSON;
$method = Method::POST;
$uri = ResourceUri::withAction($resource, $id, 'cancel');

return new self($contentType, $method, $uri);
}
25 changes: 25 additions & 0 deletions tests/Service/Email.php
Original file line number Diff line number Diff line change
@@ -10,3 +10,28 @@
expect($result)->toBeInstanceOf(Email::class)
->id->toBe('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
});

it('can update a scheduled email', function () {
$client = mockClient('PATCH', 'emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794', [
'scheduled_at' => '2024-08-05T11:52:01.858Z',
], ['object' => 'email', 'id' => '49a3999c-0ce1-4ea6-ab68-afcd6dc2e794']);

$result = $client->emails->update('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794', [
'scheduled_at' => '2024-08-05T11:52:01.858Z',
]);

expect($result)->toBeInstanceOf(Email::class)
->id->toBe('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
});

it('can cancel a scheduled email', function () {
$client = mockClient('POST', 'emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794/cancel', [], [
'object' => 'email',
'id' => '49a3999c-0ce1-4ea6-ab68-afcd6dc2e794',
]);

$result = $client->emails->cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');

expect($result)->toBeInstanceOf(Email::class)
->id->toBe('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
});