Skip to content

Commit 7e6515a

Browse files
authored
Merge pull request #115 from Kit/add-update-tag-method
Add `update_tag_name` method
2 parents bf2b64e + 7150507 commit 7e6515a

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/ConvertKit_API_Traits.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,23 @@ public function create_tags(array $tags, string $callback_url = '')
585585
);
586586
}
587587

588+
/**
589+
* Updates the name of a tag.
590+
*
591+
* @param integer $tag_id Tag ID.
592+
* @param string $name New name.
593+
*
594+
* @since 2.2.1
595+
*
596+
* @see https://developers.kit.com/api-reference/tags/update-tag-name
597+
*
598+
* @return false|mixed
599+
*/
600+
public function update_tag_name(int $tag_id, string $name)
601+
{
602+
return $this->put(sprintf('tags/%s', $tag_id), ['name' => $name]);
603+
}
604+
588605
/**
589606
* Tags a subscriber with the given existing Tag.
590607
*

tests/ConvertKitAPITest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,59 @@ public function testCreateTagsThatExist()
17221722
$this->assertEquals($result->tags[0]->name, $_ENV['CONVERTKIT_API_TAG_NAME_2']);
17231723
}
17241724

1725+
/**
1726+
* Test that update_tag_name() returns the expected data.
1727+
*
1728+
* @since 2.2.1
1729+
*
1730+
* @return void
1731+
*/
1732+
public function testUpdateTagName()
1733+
{
1734+
$result = $this->api->update_tag_name(
1735+
tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'],
1736+
name: $_ENV['CONVERTKIT_API_TAG_NAME'],
1737+
);
1738+
1739+
// Assert existing tag is returned.
1740+
$this->assertEquals($result->tag->id, (int) $_ENV['CONVERTKIT_API_TAG_ID']);
1741+
$this->assertEquals($result->tag->name, $_ENV['CONVERTKIT_API_TAG_NAME']);
1742+
}
1743+
1744+
/**
1745+
* Test that update_tag_name() throws a ClientException when an invalid
1746+
* tag ID is specified.
1747+
*
1748+
* @since 2.2.1
1749+
*
1750+
* @return void
1751+
*/
1752+
public function testUpdateTagNameWithInvalidTagID()
1753+
{
1754+
$this->expectException(ClientException::class);
1755+
$result = $this->api->update_tag_name(
1756+
tag_id: 12345,
1757+
name: $_ENV['CONVERTKIT_API_TAG_NAME'],
1758+
);
1759+
}
1760+
1761+
/**
1762+
* Test that update_tag_name() throws a ClientException when a blank
1763+
* name is specified.
1764+
*
1765+
* @since 2.2.1
1766+
*
1767+
* @return void
1768+
*/
1769+
public function testUpdateTagNameWithBlankName()
1770+
{
1771+
$this->expectException(ClientException::class);
1772+
$result = $this->api->update_tag_name(
1773+
tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'],
1774+
name: ''
1775+
);
1776+
}
1777+
17251778
/**
17261779
* Test that tag_subscriber_by_email() returns the expected data.
17271780
*

0 commit comments

Comments
 (0)