Skip to content

Commit f4b62c2

Browse files
committed
Add bounces per campaign and subscriber methods
1 parent c1d0e4e commit f4b62c2

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

src/Endpoint/BouncesClient.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,42 @@ public function list(?int $afterId = null, ?int $limit = 25, ?string $status = n
5555
return new BounceCollection($response);
5656
}
5757

58+
/**
59+
* Get a list of bounce counts by campaign.
60+
*
61+
* GET /api/v2/bounces/by/campaign
62+
*
63+
* @return array<int, array{
64+
* message_id: int,
65+
* subject: string,
66+
* total_bounces: int
67+
* }> Raw API response
68+
* @throws ApiException If an API error occurs
69+
*/
70+
public function listByCampaign(): array
71+
{
72+
return $this->client->get('bounces/by/campaign');
73+
}
74+
75+
/**
76+
* Get a list of bounce counts by subscriber.
77+
*
78+
* GET /api/v2/bounces/by/subscriber
79+
*
80+
* @return array<int, array{
81+
* subscriber_id: int,
82+
* email: string,
83+
* confirmed: bool,
84+
* blacklisted: bool,
85+
* total_bounces: int
86+
* }> Raw API response
87+
* @throws ApiException If an API error occurs
88+
*/
89+
public function listBySubscriber(): array
90+
{
91+
return $this->client->get('bounces/by/subscriber');
92+
}
93+
5894
/**
5995
* Create or update a bounce regex rule.
6096
*

tests/Endpoint/BouncesClientMethodTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,50 @@ public function testListReturnsBounceCollection(): void
3939
$this->assertSame(123, $result->items[0]->messageId);
4040
$this->assertSame('user@example.com', $result->items[0]->subscriberEmail);
4141
}
42+
43+
public function testListByCampaignReturnsRawArray(): void
44+
{
45+
$mockClient = $this->createMock(Client::class);
46+
$mockClient->expects($this->once())
47+
->method('get')
48+
->with('bounces/by/campaign')
49+
->willReturn([
50+
[
51+
'message_id' => 1,
52+
'subject' => 'System',
53+
'total_bounces' => 3,
54+
],
55+
]);
56+
57+
$bouncesClient = new BouncesClient($mockClient);
58+
$result = $bouncesClient->listByCampaign();
59+
60+
$this->assertIsArray($result);
61+
$this->assertSame(1, $result[0]['message_id']);
62+
$this->assertSame(3, $result[0]['total_bounces']);
63+
}
64+
65+
public function testListBySubscriberReturnsRawArray(): void
66+
{
67+
$mockClient = $this->createMock(Client::class);
68+
$mockClient->expects($this->once())
69+
->method('get')
70+
->with('bounces/by/subscriber')
71+
->willReturn([
72+
[
73+
'subscriber_id' => 1,
74+
'email' => 'example@email.com',
75+
'confirmed' => true,
76+
'blacklisted' => false,
77+
'total_bounces' => 2,
78+
],
79+
]);
80+
81+
$bouncesClient = new BouncesClient($mockClient);
82+
$result = $bouncesClient->listBySubscriber();
83+
84+
$this->assertIsArray($result);
85+
$this->assertSame(1, $result[0]['subscriber_id']);
86+
$this->assertSame(2, $result[0]['total_bounces']);
87+
}
4288
}

0 commit comments

Comments
 (0)