Skip to content
Merged
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
17 changes: 17 additions & 0 deletions src/ConvertKit_API_Traits.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,23 @@ public function create_tags(array $tags, string $callback_url = '')
);
}

/**
* Updates the name of a tag.
*
* @param integer $tag_id Tag ID.
* @param string $name New name.
*
* @since 2.2.1
*
* @see https://developers.kit.com/api-reference/tags/update-tag-name
*
* @return false|mixed
*/
public function update_tag_name(int $tag_id, string $name)
{
return $this->put(sprintf('tags/%s', $tag_id), ['name' => $name]);
}

/**
* Tags a subscriber with the given existing Tag.
*
Expand Down
53 changes: 53 additions & 0 deletions tests/ConvertKitAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,59 @@ public function testCreateTagsThatExist()
$this->assertEquals($result->tags[0]->name, $_ENV['CONVERTKIT_API_TAG_NAME_2']);
}

/**
* Test that update_tag_name() returns the expected data.
*
* @since 2.2.1
*
* @return void
*/
public function testUpdateTagName()
{
$result = $this->api->update_tag_name(
tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'],
name: $_ENV['CONVERTKIT_API_TAG_NAME'],
);

// Assert existing tag is returned.
$this->assertEquals($result->tag->id, (int) $_ENV['CONVERTKIT_API_TAG_ID']);
$this->assertEquals($result->tag->name, $_ENV['CONVERTKIT_API_TAG_NAME']);
}

/**
* Test that update_tag_name() throws a ClientException when an invalid
* tag ID is specified.
*
* @since 2.2.1
*
* @return void
*/
public function testUpdateTagNameWithInvalidTagID()
{
$this->expectException(ClientException::class);
$result = $this->api->update_tag_name(
tag_id: 12345,
name: $_ENV['CONVERTKIT_API_TAG_NAME'],
);
}

/**
* Test that update_tag_name() throws a ClientException when a blank
* name is specified.
*
* @since 2.2.1
*
* @return void
*/
public function testUpdateTagNameWithBlankName()
{
$this->expectException(ClientException::class);
$result = $this->api->update_tag_name(
tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'],
name: ''
);
}

/**
* Test that tag_subscriber_by_email() returns the expected data.
*
Expand Down