From 2d31bdc859c33edd3421c182f36c6dbebfa51fb0 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Fri, 10 Mar 2023 16:09:17 +0000 Subject: [PATCH 1/9] Stubbed missing tag functions --- src/ConvertKit_API.php | 87 +++++++++++++++++++++++++++++++++++++ tests/ConvertKitAPITest.php | 19 ++++++++ 2 files changed, 106 insertions(+) diff --git a/src/ConvertKit_API.php b/src/ConvertKit_API.php index 9ea9c4a..b1eade1 100644 --- a/src/ConvertKit_API.php +++ b/src/ConvertKit_API.php @@ -256,11 +256,41 @@ public function add_subscriber_to_sequence(int $sequence_id, string $email) ); } + /** + * Gets all tags. + * + * @since 1.0.0 + * + * @see https://developers.convertkit.com/#list-tags + * + * @return false|mixed + */ + public function get_tags() + { + return $this->get_resources('tags'); + } + + /** + * Creates a tags. + * + * @since 1.0.0 + * + * @see https://developers.convertkit.com/#create-a-tag + * + * @return false|mixed + */ + public function create_tag(string $tag) + { + + } + /** * Adds a tag to a subscriber * * @param integer $tag Tag ID. * @param array $options Array of user data. + * + * @see https://developers.convertkit.com/#tag-a-subscriber * * @throws \InvalidArgumentException If the provided arguments are not of the expected type. * @@ -284,6 +314,63 @@ public function add_tag(int $tag, array $options) ); } + /** + * Removes a tag from a subscriber. + * + * @since 1.0.0 + * + * @see https://developers.convertkit.com/#remove-tag-from-a-subscriber + * + * @return false|mixed + */ + public function remove_tag_from_subscriber(int $subscriber_id) + { + + } + + /** + * Removes a tag from a subscriber by email address. + * + * @since 1.0.0 + * + * @see https://developers.convertkit.com/#remove-tag-from-a-subscriber-by-email + * + * @return false|mixed + */ + public function remove_tag_from_subscriber_by_email(string $email) + { + + } + + /** + * List subscriptions to a tag + * + * @param integer $tag_id Tag ID. + * @param string $sort_order Sort Order (asc|desc). + * @param string $subscriber_state Subscriber State (active,cancelled). + * @param integer $page Page. + * + * @see https://developers.convertkit.com/#list-subscriptions-to-a-tag + * + * @return false|mixed + */ + public function get_tag_subscriptions( + int $tag_id, + string $sort_order = 'asc', + string $subscriber_state = 'active', + int $page = 1 + ) { + return $this->get( + sprintf('tags/%s/subscriptions', $tag_id), + [ + 'api_secret' => $this->api_secret, + 'sort_order' => $sort_order, + 'subscriber_state' => $subscriber_state, + 'page' => $page, + ] + ); + } + /** * Gets a resource index * Possible resources: forms, landing_pages, subscription_forms, tags diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index a8bdeee..c1ee27d 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -378,6 +378,25 @@ public function testAddSubscriberToSequenceWithInvalidEmailAddress() $result = $this->api->add_subscriber_to_sequence($_ENV['CONVERTKIT_API_SEQUENCE_ID'], 'not-an-email-address'); } + /** + * Test that get_tags() returns the expected data. + * + * @since 1.0.0 + * + * @return void + */ + public function testGetTags() + { + $result = $this->api->get_tags(); + $this->assertIsArray($result); + + // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10. + $tag = get_object_vars($result[0]); + $this->assertArrayHasKey('id', $tag); + $this->assertArrayHasKey('name', $tag); + $this->assertArrayHasKey('created_at', $tag); + } + /** * Test that add_tag() returns the expected data. * From d2248c79481d40ad355ecd77ca64ad1bb5016935 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 13 Mar 2023 13:28:13 +0000 Subject: [PATCH 2/9] Added create_tag() and tests --- src/ConvertKit_API.php | 10 +++++++- tests/ConvertKitAPITest.php | 50 ++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/ConvertKit_API.php b/src/ConvertKit_API.php index c562247..b45d682 100644 --- a/src/ConvertKit_API.php +++ b/src/ConvertKit_API.php @@ -317,7 +317,15 @@ public function get_tags() */ public function create_tag(string $tag) { - + return $this->post( + 'tags', + [ + 'api_key' => $this->api_key, + 'tag' => [ + 'name' => $tag, + ], + ] + ); } /** diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index a9ee680..4f263e0 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -481,6 +481,54 @@ public function testGetTags() $this->assertArrayHasKey('created_at', $tag); } + /** + * Test that create_tag() returns the expected data. + * + * @since 1.0.0 + * + * @return void + */ + public function testCreateTag() + { + $tag = 'Tag Test ' . mt_rand(); + $result = $this->api->create_tag($tag); + + // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10. + $tag = get_object_vars($result); + $this->assertArrayHasKey('id', $tag); + $this->assertArrayHasKey('name', $tag); + $this->assertArrayHasKey('created_at', $tag); + $this->assertEquals($tag['name'], $tag); + } + + /** + * Test that create_tag() throws a ClientException when creating + * a blank tag. + * + * @since 1.0.0 + * + * @return void + */ + public function testCreateTagBlank() + { + $this->expectException(GuzzleHttp\Exception\ClientException::class); + $result = $this->api->create_tag(''); + } + + /** + * Test that create_tag() throws a ClientException when creating + * a tag that already exists. + * + * @since 1.0.0 + * + * @return void + */ + public function testCreateTagThatExists() + { + $this->expectException(GuzzleHttp\Exception\ClientException::class); + $result = $this->api->create_tag($_ENV['CONVERTKIT_API_TAG_NAME']); + } + /** * Test that add_tag() returns the expected data. * @@ -874,7 +922,7 @@ public function testGetResourceInaccessibleURL() */ private function generateEmailAddress($domain = 'convertkit.com') { - return 'wordpress-' . date('Y-m-d-H-i-s') . '-php-' . PHP_VERSION_ID . '@' . $domain; + return 'php-sdk-' . date('Y-m-d-H-i-s') . '-php-' . PHP_VERSION_ID . '@' . $domain; } /** From 813b3ccf6665cf85e11199960ea044bfa13be219 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 13 Mar 2023 13:44:54 +0000 Subject: [PATCH 3/9] Added tag_subscriber() and tests --- src/ConvertKit_API.php | 43 +++++++++++++++++++++++ tests/ConvertKitAPITest.php | 68 ++++++++++++++++++++++++++++++++++--- 2 files changed, 106 insertions(+), 5 deletions(-) diff --git a/src/ConvertKit_API.php b/src/ConvertKit_API.php index b45d682..a47dcce 100644 --- a/src/ConvertKit_API.php +++ b/src/ConvertKit_API.php @@ -328,12 +328,52 @@ public function create_tag(string $tag) ); } + /** + * Tags a subscriber to the given tag. + * + * @param integer $tag_id Tag ID. + * @param string $email Email Address. + * @param string $first_name First Name. + * @param array $fields Custom Fields. + * + * @see https://developers.convertkit.com/#tag-a-subscriber + * + * @return false|mixed + */ + public function tag_subscriber( + int $tag_id, + string $email, + string $first_name = '', + array $fields = [] + ) { + // Build parameters. + $options = [ + 'api_secret' => $this->api_secret, + 'email' => $email, + ]; + + if (!empty($first_name)) { + $options['first_name'] = $first_name; + } + if (!empty($fields)) { + $options['fields'] = $fields; + } + + // Send request. + return $this->post( + sprintf('tags/%s/subscribe', $tag_id), + $options + ); + } + /** * Adds a tag to a subscriber * * @param integer $tag Tag ID. * @param array $options Array of user data. * + * @deprecated 1.0.0 Use tag_subscriber($tag_id, $email, $first_name, $fields). + * * @see https://developers.convertkit.com/#tag-a-subscriber * * @throws \InvalidArgumentException If the provided arguments are not of the expected type. @@ -342,6 +382,9 @@ public function create_tag(string $tag) */ public function add_tag(int $tag, array $options) { + // This function is deprecated in 1.0, as we prefer functions with structured arguments. + trigger_error( 'add_tag() is deprecated in 1.0. Use tag_subscribe($tag_id, $email, $first_name, $fields) instead.', E_USER_NOTICE); + if (!is_int($tag)) { throw new \InvalidArgumentException(); } diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index 4f263e0..163a669 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -530,21 +530,79 @@ public function testCreateTagThatExists() } /** - * Test that add_tag() returns the expected data. + * Test that tag_subscriber() returns the expected data. * * @since 1.0.0 * * @return void */ - public function testAddTag() + public function testTagSubscriber() { - $result = $this->api->add_tag((int) $_ENV['CONVERTKIT_API_TAG_ID'], [ - 'email' => $this->generateEmailAddress(), - ]); + $result = $this->api->tag_subscriber( + (int) $_ENV['CONVERTKIT_API_TAG_ID'], + $this->generateEmailAddress() + ); + $this->assertInstanceOf('stdClass', $result); + $this->assertArrayHasKey('subscription', get_object_vars($result)); + } + + /** + * Test that tag_subscriber() returns the expected data + * when a first_name parameter is included. + * + * @since 1.0.0 + * + * @return void + */ + public function testTagSubscriberWithFirstName() + { + $emailAddress = $this->generateEmailAddress(); + $firstName = 'First Name'; + $result = $this->api->tag_subscriber( + (int) $_ENV['CONVERTKIT_API_TAG_ID'], + $emailAddress, + $firstName + ); + $this->assertInstanceOf('stdClass', $result); $this->assertArrayHasKey('subscription', get_object_vars($result)); + + // Fetch subscriber from API to confirm the first name was saved. + $subscriber = $this->api->get_subscriber($result->subscription->subscriber->id); + $this->assertEquals($subscriber->subscriber->email_address, $emailAddress); + $this->assertEquals($subscriber->subscriber->first_name, $firstName); } + /** + * Test that tag_subscriber() returns the expected data + * when custom field data is included. + * + * @since 1.0.0 + * + * @return void + */ + public function testTagSubscriberWithCustomFields() + { + $result = $this->api->tag_subscriber( + (int) $_ENV['CONVERTKIT_API_TAG_ID'], + $this->generateEmailAddress(), + 'First Name', + [ + 'last_name' => 'Last Name', + ] + ); + + // Check subscription object returned. + $this->assertInstanceOf('stdClass', $result); + $this->assertArrayHasKey('subscription', get_object_vars($result)); + + // Fetch subscriber from API to confirm the custom fields were saved. + $subscriber = $this->api->get_subscriber($result->subscription->subscriber->id); + $this->assertEquals($subscriber->subscriber->fields->last_name, 'Last Name'); + } + + /// + /** * Test that get_resources() for Forms returns the expected data. * From 88270176db4efb9d3d7b1117ab3e1a4549dbb83e Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 13 Mar 2023 13:59:14 +0000 Subject: [PATCH 4/9] Added remove_tag_from_subscriber() and tests --- src/ConvertKit_API.php | 33 +++++++++++++++---- tests/ConvertKitAPITest.php | 64 +++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 7 deletions(-) diff --git a/src/ConvertKit_API.php b/src/ConvertKit_API.php index a47dcce..15ccb06 100644 --- a/src/ConvertKit_API.php +++ b/src/ConvertKit_API.php @@ -307,10 +307,12 @@ public function get_tags() } /** - * Creates a tags. + * Creates a tag. * * @since 1.0.0 * + * @param string $tag Tag Name. + * * @see https://developers.convertkit.com/#create-a-tag * * @return false|mixed @@ -329,7 +331,7 @@ public function create_tag(string $tag) } /** - * Tags a subscriber to the given tag. + * Tags a subscriber with the given existing Tag. * * @param integer $tag_id Tag ID. * @param string $email Email Address. @@ -367,7 +369,7 @@ public function tag_subscriber( } /** - * Adds a tag to a subscriber + * Adds a tag to a subscriber. * * @param integer $tag Tag ID. * @param array $options Array of user data. @@ -406,13 +408,21 @@ public function add_tag(int $tag, array $options) * * @since 1.0.0 * + * @param integer $tag_id Tag ID. + * @param integer $subscriber_id Subscriber ID. + * * @see https://developers.convertkit.com/#remove-tag-from-a-subscriber * * @return false|mixed */ - public function remove_tag_from_subscriber(int $subscriber_id) + public function remove_tag_from_subscriber(int $tag_id, int $subscriber_id) { - + return $this->delete( + sprintf('subscribers/%s/tags/%s', $subscriber_id, $tag_id), + [ + 'api_secret' => $this->api_secret, + ] + ); } /** @@ -420,13 +430,22 @@ public function remove_tag_from_subscriber(int $subscriber_id) * * @since 1.0.0 * + * @param integer $tag_id Tag ID. + * @param string $email Subscriber email address. + * * @see https://developers.convertkit.com/#remove-tag-from-a-subscriber-by-email * * @return false|mixed */ - public function remove_tag_from_subscriber_by_email(string $email) + public function remove_tag_from_subscriber_by_email(int $tag_id, string $email) { - + return $this->post( + sprintf('tags/%s/unsubscribe', $tag_id), + [ + 'api_secret' => $this->api_secret, + 'email' => $email, + ] + ); } /** diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index 163a669..8138855 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -601,6 +601,70 @@ public function testTagSubscriberWithCustomFields() $this->assertEquals($subscriber->subscriber->fields->last_name, 'Last Name'); } + /** + * Test that remove_tag_from_subscriber() works. + * + * @since 1.0.0 + * + * @return void + */ + public function testRemoveTagFromSubscriber() + { + // Tag the subscriber first. + $result = $this->api->tag_subscriber( + (int) $_ENV['CONVERTKIT_API_TAG_ID'], + $this->generateEmailAddress() + ); + + // Get subscriber ID. + $subscriberID = $result->subscription->subscriber->id; + + // Remove tag from subscriber. + $result = $this->api->remove_tag_from_subscriber( + (int) $_ENV['CONVERTKIT_API_TAG_ID'], + $subscriberID + ); + + // Confirm that the subscriber no longer has the tag. + $result = $this->api->get_subscriber_tags($subscriberID); + $this->assertIsArray($result->tags); + $this->assertEmpty($result->tags); + } + + /** + * Test that remove_tag_from_subscriber() throws a ClientException when an invalid + * tag ID is specified. + * + * @since 1.0.0 + * + * @return void + */ + public function testRemoveTagFromSubscriberWithInvalidTagID() + { + $this->expectException(GuzzleHttp\Exception\ClientException::class); + $result = $this->api->remove_tag_from_subscriber( + 12345, + $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] + ); + } + + /** + * Test that remove_tag_from_subscriber() throws a ClientException when an invalid + * subscriber ID is specified. + * + * @since 1.0.0 + * + * @return void + */ + public function testRemoveTagFromSubscriberWithInvalidSubscriberID() + { + $this->expectException(GuzzleHttp\Exception\ClientException::class); + $result = $this->api->remove_tag_from_subscriber( + (int) $_ENV['CONVERTKIT_API_TAG_ID'], + 12345 + ); + } + /// /** From 71a0264dc961a1e639a9c1252d90bd06068994fc Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 13 Mar 2023 14:05:09 +0000 Subject: [PATCH 5/9] Added remove_tag_from_subscriber_by_email() and tests --- tests/ConvertKitAPITest.php | 48 ++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index 8138855..e860c96 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -665,7 +665,53 @@ public function testRemoveTagFromSubscriberWithInvalidSubscriberID() ); } - /// + /** + * Test that remove_tag_from_subscriber() works. + * + * @since 1.0.0 + * + * @return void + */ + public function testRemoveTagFromSubscriberByEmail() + { + // Tag the subscriber first. + $email = $this->generateEmailAddress(); + $result = $this->api->tag_subscriber( + (int) $_ENV['CONVERTKIT_API_TAG_ID'], + $email + ); + + // Get subscriber ID. + $subscriberID = $result->subscription->subscriber->id; + + // Remove tag from subscriber. + $result = $this->api->remove_tag_from_subscriber_by_email( + (int) $_ENV['CONVERTKIT_API_TAG_ID'], + $email + ); + + // Confirm that the subscriber no longer has the tag. + $result = $this->api->get_subscriber_tags($subscriberID); + $this->assertIsArray($result->tags); + $this->assertEmpty($result->tags); + } + + /** + * Test that remove_tag_from_subscriber() throws a ClientException when an invalid + * tag ID is specified. + * + * @since 1.0.0 + * + * @return void + */ + public function testRemoveTagFromSubscriberByEmailWithInvalidTagID() + { + $this->expectException(GuzzleHttp\Exception\ClientException::class); + $result = $this->api->remove_tag_from_subscriber_by_email( + 12345, + $_ENV['CONVERTKIT_API_SUBSCRIBER_EMAIL'] + ); + } /** * Test that get_resources() for Forms returns the expected data. From aa936a9906856c693043833baa2020d6f7eec168 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 13 Mar 2023 14:08:07 +0000 Subject: [PATCH 6/9] Added get_tag_subscriptions() and tests --- tests/ConvertKitAPITest.php | 117 ++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index e860c96..4b39d0c 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -713,6 +713,123 @@ public function testRemoveTagFromSubscriberByEmailWithInvalidTagID() ); } + /** + * Test that get_tag_subscriptions() returns the expected data + * when a valid Tag ID is specified. + * + * @since 1.0.0 + * + * @return void + */ + public function testGetTagSubscriptions() + { + $result = $this->api->get_tag_subscriptions((int) $_ENV['CONVERTKIT_API_TAG_ID']); + + // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10. + $result = get_object_vars($result); + $this->assertArrayHasKey('total_subscriptions', $result); + $this->assertArrayHasKey('page', $result); + $this->assertArrayHasKey('total_pages', $result); + $this->assertArrayHasKey('subscriptions', $result); + $this->assertIsArray($result['subscriptions']); + + // Assert sort order is ascending. + $this->assertGreaterThanOrEqual( + $result['subscriptions'][0]->created_at, + $result['subscriptions'][1]->created_at + ); + } + + /** + * Test that get_tag_subscriptions() returns the expected data + * when a valid Tag ID is specified and the sort order is descending. + * + * @since 1.0.0 + * + * @return void + */ + public function testGetTagSubscriptionsWithDescSortOrder() + { + $result = $this->api->get_tag_subscriptions((int) $_ENV['CONVERTKIT_API_TAG_ID'], 'desc'); + + // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10. + $result = get_object_vars($result); + $this->assertArrayHasKey('total_subscriptions', $result); + $this->assertArrayHasKey('page', $result); + $this->assertArrayHasKey('total_pages', $result); + $this->assertArrayHasKey('subscriptions', $result); + $this->assertIsArray($result['subscriptions']); + + // Assert sort order. + $this->assertLessThanOrEqual( + $result['subscriptions'][0]->created_at, + $result['subscriptions'][1]->created_at + ); + } + + /** + * Test that get_tag_subscriptions() returns the expected data + * when a valid Tag ID is specified and the subscription status + * is cancelled. + * + * @since 1.0.0 + * + * @return void + */ + public function testGetTagSubscriptionsWithCancelledSubscriberState() + { + $result = $this->api->get_tag_subscriptions((int) $_ENV['CONVERTKIT_API_TAG_ID'], 'asc', 'cancelled'); + + // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10. + $result = get_object_vars($result); + $this->assertArrayHasKey('total_subscriptions', $result); + $this->assertGreaterThan(1, $result['total_subscriptions']); + $this->assertArrayHasKey('page', $result); + $this->assertArrayHasKey('total_pages', $result); + $this->assertArrayHasKey('subscriptions', $result); + $this->assertIsArray($result['subscriptions']); + } + + /** + * Test that get_tag_subscriptions() returns the expected data + * when a valid Tag ID is specified and the page is set to 2. + * + * @since 1.0.0 + * + * @return void + */ + public function testGetTagSubscriptionsWithPage() + { + $result = $this->api->get_tag_subscriptions((int) $_ENV['CONVERTKIT_API_TAG_ID'], 'asc', 'active', 2); + + // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10. + $result = get_object_vars($result); + $this->assertArrayHasKey('total_subscriptions', $result); + $this->assertArrayHasKey('page', $result); + $this->assertEquals($result['page'], 2); + $this->assertArrayHasKey('total_pages', $result); + $this->assertArrayHasKey('subscriptions', $result); + $this->assertIsArray($result['subscriptions']); + } + + /** + * Test that get_tag_subscriptions() returns the expected data + * when a valid Tag ID is specified. + * + * @since 1.0.0 + * + * @return void + */ + public function testGetTagSubscriptionsWithInvalidFormID() + { + $this->expectException(GuzzleHttp\Exception\ClientException::class); + $result = $this->api->get_tag_subscriptions(12345); + } + + + + /// + /** * Test that get_resources() for Forms returns the expected data. * From d9b680014ff0ae60e9323c080035fb381966ccff Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 13 Mar 2023 14:09:55 +0000 Subject: [PATCH 7/9] Coding standards --- src/ConvertKit_API.php | 47 +++++++++++++++++++------------------ tests/ConvertKitAPITest.php | 10 ++++---- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/ConvertKit_API.php b/src/ConvertKit_API.php index 15ccb06..215418f 100644 --- a/src/ConvertKit_API.php +++ b/src/ConvertKit_API.php @@ -296,7 +296,7 @@ public function get_sequence_subscriptions( * Gets all tags. * * @since 1.0.0 - * + * * @see https://developers.convertkit.com/#list-tags * * @return false|mixed @@ -309,10 +309,10 @@ public function get_tags() /** * Creates a tag. * + * @param string $tag Tag Name. + * * @since 1.0.0 - * - * @param string $tag Tag Name. - * + * * @see https://developers.convertkit.com/#create-a-tag * * @return false|mixed @@ -322,10 +322,8 @@ public function create_tag(string $tag) return $this->post( 'tags', [ - 'api_key' => $this->api_key, - 'tag' => [ - 'name' => $tag, - ], + 'api_key' => $this->api_key, + 'tag' => ['name' => $tag], ] ); } @@ -333,10 +331,10 @@ public function create_tag(string $tag) /** * Tags a subscriber with the given existing Tag. * - * @param integer $tag_id Tag ID. - * @param string $email Email Address. - * @param string $first_name First Name. - * @param array $fields Custom Fields. + * @param integer $tag_id Tag ID. + * @param string $email Email Address. + * @param string $first_name First Name. + * @param array $fields Custom Fields. * * @see https://developers.convertkit.com/#tag-a-subscriber * @@ -373,9 +371,9 @@ public function tag_subscriber( * * @param integer $tag Tag ID. * @param array $options Array of user data. - * + * * @deprecated 1.0.0 Use tag_subscriber($tag_id, $email, $first_name, $fields). - * + * * @see https://developers.convertkit.com/#tag-a-subscriber * * @throws \InvalidArgumentException If the provided arguments are not of the expected type. @@ -385,7 +383,10 @@ public function tag_subscriber( public function add_tag(int $tag, array $options) { // This function is deprecated in 1.0, as we prefer functions with structured arguments. - trigger_error( 'add_tag() is deprecated in 1.0. Use tag_subscribe($tag_id, $email, $first_name, $fields) instead.', E_USER_NOTICE); + trigger_error( + 'add_tag() is deprecated in 1.0. Use tag_subscribe($tag_id, $email, $first_name, $fields) instead.', + E_USER_NOTICE + ); if (!is_int($tag)) { throw new \InvalidArgumentException(); @@ -406,11 +407,11 @@ public function add_tag(int $tag, array $options) /** * Removes a tag from a subscriber. * + * @param integer $tag_id Tag ID. + * @param integer $subscriber_id Subscriber ID. + * * @since 1.0.0 - * - * @param integer $tag_id Tag ID. - * @param integer $subscriber_id Subscriber ID. - * + * * @see https://developers.convertkit.com/#remove-tag-from-a-subscriber * * @return false|mixed @@ -428,11 +429,11 @@ public function remove_tag_from_subscriber(int $tag_id, int $subscriber_id) /** * Removes a tag from a subscriber by email address. * + * @param integer $tag_id Tag ID. + * @param string $email Subscriber email address. + * * @since 1.0.0 - * - * @param integer $tag_id Tag ID. - * @param string $email Subscriber email address. - * + * * @see https://developers.convertkit.com/#remove-tag-from-a-subscriber-by-email * * @return false|mixed diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index 4b39d0c..6cb2d80 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -492,7 +492,7 @@ public function testCreateTag() { $tag = 'Tag Test ' . mt_rand(); $result = $this->api->create_tag($tag); - + // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10. $tag = get_object_vars($result); $this->assertArrayHasKey('id', $tag); @@ -603,9 +603,9 @@ public function testTagSubscriberWithCustomFields() /** * Test that remove_tag_from_subscriber() works. - * + * * @since 1.0.0 - * + * * @return void */ public function testRemoveTagFromSubscriber() @@ -667,9 +667,9 @@ public function testRemoveTagFromSubscriberWithInvalidSubscriberID() /** * Test that remove_tag_from_subscriber() works. - * + * * @since 1.0.0 - * + * * @return void */ public function testRemoveTagFromSubscriberByEmail() From b8895671691f2c5f3234ba6e1e704c3f9d8ca943 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 13 Mar 2023 14:19:51 +0000 Subject: [PATCH 8/9] Fix failing test --- tests/ConvertKitAPITest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ConvertKitAPITest.php b/tests/ConvertKitAPITest.php index 6cb2d80..7948cd6 100644 --- a/tests/ConvertKitAPITest.php +++ b/tests/ConvertKitAPITest.php @@ -490,15 +490,15 @@ public function testGetTags() */ public function testCreateTag() { - $tag = 'Tag Test ' . mt_rand(); - $result = $this->api->create_tag($tag); + $tagName = 'Tag Test ' . mt_rand(); + $result = $this->api->create_tag($tagName); // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10. $tag = get_object_vars($result); $this->assertArrayHasKey('id', $tag); $this->assertArrayHasKey('name', $tag); $this->assertArrayHasKey('created_at', $tag); - $this->assertEquals($tag['name'], $tag); + $this->assertEquals($tag['name'], $tagName); } /** From 80d80b147af873825acef00fa9f455472f7bcb43 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 13 Mar 2023 14:21:14 +0000 Subject: [PATCH 9/9] Update .env files --- .env.dist.testing | 1 + .env.example | 1 + 2 files changed, 2 insertions(+) diff --git a/.env.dist.testing b/.env.dist.testing index 4d5f08e..a8a44f4 100644 --- a/.env.dist.testing +++ b/.env.dist.testing @@ -3,6 +3,7 @@ CONVERTKIT_API_LEGACY_FORM_URL="https://app.convertkit.com/landing_pages/470099" CONVERTKIT_API_LANDING_PAGE_URL="https://cheerful-architect-3237.ck.page/cc5eb21744" CONVERTKIT_API_LEGACY_LANDING_PAGE_URL="https://app.convertkit.com/landing_pages/470103" CONVERTKIT_API_SEQUENCE_ID="1030824" +CONVERTKIT_API_TAG_NAME="wordpress" CONVERTKIT_API_TAG_ID="2744672" CONVERTKIT_API_SUBSCRIBER_EMAIL="optin@n7studios.com" CONVERTKIT_API_SUBSCRIBER_ID="1579118532" diff --git a/.env.example b/.env.example index 2cbb1ac..3185e06 100644 --- a/.env.example +++ b/.env.example @@ -7,6 +7,7 @@ CONVERTKIT_API_LEGACY_FORM_URL="https://app.convertkit.com/landing_pages/470099" CONVERTKIT_API_LANDING_PAGE_URL="https://cheerful-architect-3237.ck.page/cc5eb21744" CONVERTKIT_API_LEGACY_LANDING_PAGE_URL="https://app.convertkit.com/landing_pages/470103" CONVERTKIT_API_SEQUENCE_ID="1030824" +CONVERTKIT_API_TAG_NAME="wordpress" CONVERTKIT_API_TAG_ID="2744672" CONVERTKIT_API_SUBSCRIBER_EMAIL="optin@n7studios.com" CONVERTKIT_API_SUBSCRIBER_ID="1579118532"