Skip to content
Draft
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
10 changes: 10 additions & 0 deletions src/ConvertKit_API_Traits.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = '',
Expand All @@ -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');
}
Expand Down Expand Up @@ -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.
Expand All @@ -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 = '',
Expand All @@ -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');
}
Expand Down
84 changes: 84 additions & 0 deletions tests/ConvertKitAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading