diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index 71f2175..927dca2 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -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. * diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index e05a025..54ec07d 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -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. *