Skip to content

Commit db001c0

Browse files
authored
Merge pull request #141 from Kit/add-type-states-to-filter-subscribers
Add `type` and `states` to `filter_subscribers()`
2 parents b8fa60a + 3c70c38 commit db001c0

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/ConvertKit_API_Traits.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,7 @@ public function create_subscribers(array $subscribers, string $callback_url = ''
15141514
* - 'count_less_than' (int|null).
15151515
* - 'after' (\DateTime|null).
15161516
* - 'before' (\DateTime|null).
1517+
* - 'states' (array<string>).
15171518
* - 'any' (array<int|string, mixed>|null).
15181519
* @param boolean $include_total_count To include the total count of records in the response, use true.
15191520
* @param string $after_cursor Return results after the given pagination cursor.
@@ -1538,6 +1539,10 @@ public function filter_subscribers(
15381539
foreach ($all as $condition) {
15391540
$option = [];
15401541

1542+
if (array_key_exists('type', $condition) && !empty($condition['type'])) {
1543+
$option['type'] = $condition['type'];
1544+
}
1545+
15411546
if (array_key_exists('count_greater_than', $condition) && $condition['count_greater_than'] !== null) {
15421547
$option['count_greater_than'] = $condition['count_greater_than'];
15431548
}
@@ -1554,6 +1559,10 @@ public function filter_subscribers(
15541559
$option['before'] = $condition['before']->format('Y-m-d');
15551560
}
15561561

1562+
if (array_key_exists('states', $condition) && !empty($condition['states'])) {
1563+
$option['states'] = (array) $condition['states'];
1564+
}
1565+
15571566
if (array_key_exists('any', $condition) && !empty($condition['any'])) {
15581567
$option['any'] = (array) $condition['any'];
15591568
}

tests/ConvertKitAPITest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4438,6 +4438,9 @@ public function testFilterSubscribers()
44384438
'count_less_than' => 100,
44394439
'after' => new \DateTime('2024-01-01'),
44404440
'before' => new \DateTime('2027-01-01'),
4441+
'states' => [
4442+
'active',
4443+
],
44414444
]
44424445
]
44434446
);
@@ -4465,6 +4468,9 @@ public function testFilterSubscribersWithMultipleConditions()
44654468
'count_less_than' => 100,
44664469
'after' => new \DateTime('2024-01-01'),
44674470
'before' => new \DateTime('2027-01-01'),
4471+
'states' => [
4472+
'active',
4473+
],
44684474
],
44694475
[
44704476
'type' => 'clicks',
@@ -4483,7 +4489,7 @@ public function testFilterSubscribersWithMultipleConditions()
44834489

44844490
/**
44854491
* Test that filter_subscribers() returns the expected data
4486-
* when multiple any conditions are specified.
4492+
* when no parameters are specified.
44874493
*
44884494
* @since 2.4.0
44894495
*
@@ -4498,6 +4504,29 @@ public function testFilterSubscribersWithNoParameters()
44984504
$this->assertPaginationExists($result);
44994505
}
45004506

4507+
/**
4508+
* Test that filter_subscribers() throws a ServerException
4509+
* when invalid parameters are specified.
4510+
*
4511+
* @since 2.4.0
4512+
*
4513+
* @return void
4514+
*/
4515+
public function testFilterSubscribersWithInvalidParameters()
4516+
{
4517+
$this->expectException(ServerException::class);
4518+
$result = $this->api->filter_subscribers(
4519+
[
4520+
[
4521+
'foo' => 'bar',
4522+
],
4523+
[
4524+
'type' => 'not-a-real-type',
4525+
]
4526+
]
4527+
);
4528+
}
4529+
45014530
/**
45024531
* Test that filter_subscribers() returns the expected data
45034532
* when the total count is included.

0 commit comments

Comments
 (0)