diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index f758017..28e03a6 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -1753,6 +1753,7 @@ public function get_subscriber_tags( * @param \DateTime|null $sent_after Get broadcasts sent after the given date. * @param \DateTime|null $sent_before Get broadcasts sent before the given date. * @param boolean $slim When true, omits expensive optional fields from the response. + * @param string|null $status Get broadcasts with the given status (draft, scheduled, sending, completed, aborted). * @param boolean $include_total_count To include the total count of records in the response, use true. * @param string $after_cursor Return results after the given pagination cursor. * @param string $before_cursor Return results before the given pagination cursor. @@ -1766,6 +1767,7 @@ public function get_broadcasts( \DateTime|null $sent_after = null, \DateTime|null $sent_before = null, bool $slim = false, + string|null $status = null, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', @@ -1774,6 +1776,9 @@ public function get_broadcasts( // Build parameters. $options = ['slim' => $slim]; + if (!is_null($status)) { + $options['status'] = $status; + } if (!is_null($sent_after)) { $options['sent_after'] = $sent_after->format('Y-m-d'); } @@ -1935,6 +1940,7 @@ public function get_broadcast_link_clicks( * * @param \DateTime|null $sent_after Get broadcasts sent after the given date. * @param \DateTime|null $sent_before Get broadcasts sent before the given date. + * @param string|null $status Get broadcasts with the given status (draft, scheduled, sending, completed, aborted). * @param boolean $include_total_count To include the total count of records in the response, use true. * @param string $after_cursor Return results after the given pagination cursor. * @param string $before_cursor Return results before the given pagination cursor. @@ -1949,6 +1955,7 @@ public function get_broadcast_link_clicks( public function get_broadcasts_stats( \DateTime|null $sent_after = null, \DateTime|null $sent_before = null, + string|null $status = null, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', @@ -1957,6 +1964,9 @@ public function get_broadcasts_stats( // Build parameters. $options = []; + if (!is_null($status)) { + $options['status'] = $status; + } if (!is_null($sent_after)) { $options['sent_after'] = $sent_after->format('Y-m-d'); } diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index cb07ce6..e349b18 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -5343,6 +5343,46 @@ public function testGetBroadcastsSlim() $this->assertArrayNotHasKey('subscriber_filter', $broadcast); } + /** + * Test that get_broadcasts() returns the expected data + * when the completed status is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsWithCompletedStatus() + { + $result = $this->api->get_broadcasts( + status: 'completed' + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + } + + /** + * Test that get_broadcasts() returns the expected data + * when the aborted status is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsWithAbortedStatus() + { + $result = $this->api->get_broadcasts( + status: 'aborted' + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + $this->assertPaginationExists($result); + + // Assert no broadcasts were returned. + $this->assertCount(0, $result->broadcasts); + } + /** * Test that get_broadcasts() returns the expected data * when pagination parameters and per_page limits are specified. @@ -5740,6 +5780,50 @@ public function testGetBroadcastsStatsWithSentBefore() $this->assertCount(12, $result->broadcasts); } + /** + * Test that get_broadcasts_stats() returns the expected data + * when the completed status is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsStatsWithCompletedStatus() + { + $result = $this->api->get_broadcasts_stats( + status: 'completed' + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + $this->assertPaginationExists($result); + + // Assert the expected number of broadcasts were returned. + $this->assertCount(12, $result->broadcasts); + } + + /** + * Test that get_broadcasts_stats() returns the expected data + * when the aborted status is specified. + * + * @since 2.5 + * + * @return void + */ + public function testGetBroadcastsStatsWithAbortedStatus() + { + $result = $this->api->get_broadcasts_stats( + status: 'aborted' + ); + + // Assert broadcasts and pagination exist. + $this->assertDataExists($result, 'broadcasts'); + $this->assertPaginationExists($result); + + // Assert the expected number of broadcasts were returned. + $this->assertCount(0, $result->broadcasts); + } + /** * Test that get_broadcasts_stats() returns the expected data * when the total count is included.