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
46 changes: 32 additions & 14 deletions src/ConvertKit_API_Traits.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,39 @@ public function get_growth_stats(\DateTime|null $starting = null, \DateTime|null
/**
* List forms.
*
* @param string $status Form status (active|archived|trashed|all).
* @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.
* @param integer $per_page Number of results to return.
* @param string $status Form status (active|archived|trashed|all).
* @param array<string> $include Additional fields to include: subscriber_count.
* @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.
* @param integer $per_page Number of results to return.
*
* @see https://developers.kit.com/api-reference/forms/list-forms
*
* @return mixed|array<int,\stdClass>
*/
public function get_forms(
string $status = 'active',
array $include = [],
bool $include_total_count = false,
string $after_cursor = '',
string $before_cursor = '',
int $per_page = 100
) {
// Build parameters.
$options = [
'type' => 'embed',
'status' => $status,
];

if (!empty($include)) {
$options['include'] = implode(',', $include);
}

return $this->get(
'forms',
$this->build_total_count_and_pagination_params(
[
'type' => 'embed',
'status' => $status,
],
$options,
$include_total_count,
$after_cursor,
$before_cursor,
Expand Down Expand Up @@ -1004,10 +1013,11 @@ public function update_snippet(
/**
* List tags.
*
* @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.
* @param integer $per_page Number of results to return.
* @param array<string> $include Additional fields to include: subscriber_count.
* @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.
* @param integer $per_page Number of results to return.
*
* @see https://developers.kit.com/api-reference/tags/list-tags
*
Expand All @@ -1016,15 +1026,23 @@ public function update_snippet(
* @return mixed|array<int,\stdClass>
*/
public function get_tags(
array $include = [],
bool $include_total_count = false,
string $after_cursor = '',
string $before_cursor = '',
int $per_page = 100
) {
// Build parameters.
$options = [];

if (!empty($include)) {
$options['include'] = implode(',', $include);
}

return $this->get(
'tags',
$this->build_total_count_and_pagination_params(
[],
$options,
$include_total_count,
$after_cursor,
$before_cursor,
Expand Down
44 changes: 44 additions & 0 deletions tests/ConvertKitAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,28 @@ public function testGetFormsWithArchivedStatus()
}
}

/**
* Test that get_forms() returns the subscriber count
* when included in the `include` argument.
*
* @since 2.6.0
*
* @return void
*/
public function testGetFormsWithSubscriberCount()
{
$result = $this->api->get_forms(
include: ['subscriber_count']
);

// Assert forms and pagination exist.
$this->assertDataExists($result, 'forms');
$this->assertPaginationExists($result);

// Assert subscriber count is included.
$this->assertArrayHasKey('subscriber_count', get_object_vars($result->forms[0]));
}

/**
* Test that get_forms() returns the expected data
* when the total count is included.
Expand Down Expand Up @@ -2220,6 +2242,28 @@ public function testGetTags()
$this->assertArrayHasKey('created_at', $tag);
}

/**
* Test that get_tags() returns the subscriber count
* when included in the `include` argument.
*
* @since 2.6.0
*
* @return void
*/
public function testGetTagsWithSubscriberCount()
{
$result = $this->api->get_tags(
include: ['subscriber_count']
);

// Assert forms and pagination exist.
$this->assertDataExists($result, 'tags');
$this->assertPaginationExists($result);

// Assert subscriber count is included.
$this->assertArrayHasKey('subscriber_count', get_object_vars($result->tags[0]));
}

/**
* Test that get_tags() returns the expected data
* when the total count is included.
Expand Down
Loading