Skip to content
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
16 changes: 16 additions & 0 deletions src/Broadcasts/ClickedLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Resend\Broadcasts;

use Resend\Resource;

/**
* @property string $id An opaque cursor for this row, used only for pagination. It does not identify any entity in Resend.
* @property string $url The URL that was clicked.
* @property int $clicks Total number of clicks on this URL.
* @property int $unique_clicks Number of unique clicks on this URL.
*/
class ClickedLink extends Resource
{
//
}
14 changes: 14 additions & 0 deletions src/Service/Broadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

namespace Resend\Service;

use Resend\Contracts\Transporter;
use Resend\Service\Broadcasts\ClickedLink;
use Resend\ValueObjects\Transporter\Payload;

class Broadcast extends Service
{
public ClickedLink $clickedLinks;
Comment thread
dielduarte marked this conversation as resolved.

/**
* Create a new broadcast service instance with the given transport.
*/
public function __construct(Transporter $transporter)
{
$this->clickedLinks = new ClickedLink($transporter);

parent::__construct($transporter);
}

/**
* Retrieve a single broadcast.
*
Expand Down
26 changes: 26 additions & 0 deletions src/Service/Broadcasts/ClickedLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Resend\Service\Broadcasts;

use Resend\Service\Service;
use Resend\ValueObjects\Transporter\Payload;

class ClickedLink extends Service
{
/**
* Retrieve a broadcast's clicked links.
*
* @param array{'limit'?: int, 'before'?: string, 'after'?: string} $options
* @return \Resend\Collection<\Resend\Broadcasts\ClickedLink>
*
* @see https://resend.com/docs/api-reference/broadcasts/list-broadcast-clicked-links
*/
public function list(string $broadcastId, array $options = []): \Resend\Collection
{
$payload = Payload::list("broadcasts/$broadcastId/clicked-links", $options);

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

return $this->createResource('broadcast-clicked-links', $result);
}
}
2 changes: 2 additions & 0 deletions src/Service/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Resend\Automation;
use Resend\Automations\Run as AutomationRun;
use Resend\Broadcast;
use Resend\Broadcasts\ClickedLink as BroadcastClickedLink;
use Resend\Collection;
use Resend\Contact;
use Resend\ContactProperty;
Expand Down Expand Up @@ -39,6 +40,7 @@ abstract class Service
'automation-runs' => AutomationRun::class,
'automations' => Automation::class,
'broadcasts' => Broadcast::class,
'broadcast-clicked-links' => BroadcastClickedLink::class,
'contact-imports' => ContactImport::class,
'contact-properties' => ContactProperty::class,
'contact-topics' => ContactTopic::class,
Expand Down
23 changes: 23 additions & 0 deletions tests/Fixtures/Broadcasts/ClickedLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

function broadcastClickedLinks(): array
{
return [
'object' => 'list',
'has_more' => false,
'data' => [
[
'id' => 'b2Zmc2V0OjA',
'url' => 'https://resend.com/pricing',
'clicks' => 42,
'unique_clicks' => 30,
],
[
'id' => 'b2Zmc2V0OjE',
'url' => 'https://resend.com/docs',
'clicks' => 17,
'unique_clicks' => 15,
],
],
];
}
25 changes: 25 additions & 0 deletions tests/Service/Broadcasts/ClickedLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Resend\Broadcasts\ClickedLink;
use Resend\Collection;

it('can get a list of a broadcast\'s clicked links', function () {
$client = mockClient('GET', 'broadcasts/559ac32e-9ef5-46fb-82a1-b76b840c0f7b/clicked-links', [], [], broadcastClickedLinks());

$result = $client->broadcasts->clickedLinks->list('559ac32e-9ef5-46fb-82a1-b76b840c0f7b');

expect($result)->toBeInstanceOf(Collection::class)
->data->toBeArray();

expect($result->data[0])->toBeInstanceOf(ClickedLink::class)
->url->toBe('https://resend.com/pricing');
});

it('can get a list of a broadcast\'s clicked links with pagination options', function () {
$client = mockClient('GET', 'broadcasts/559ac32e-9ef5-46fb-82a1-b76b840c0f7b/clicked-links?limit=1', [], [], broadcastClickedLinks());

$result = $client->broadcasts->clickedLinks->list('559ac32e-9ef5-46fb-82a1-b76b840c0f7b', ['limit' => 1]);

expect($result)->toBeInstanceOf(Collection::class)
->data->toBeArray();
});