Skip to content

Commit 4fea065

Browse files
committed
Added get_webhook() function and test
1 parent 0261903 commit 4fea065

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/ConvertKit_API.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,23 @@ public function get_subscriber_tags(int $subscriber_id)
589589
);
590590
}
591591

592+
/**
593+
* Returns all created webhooks.
594+
*
595+
* @since 1.0.0
596+
*
597+
* @return false|object
598+
*/
599+
public function get_webhooks()
600+
{
601+
return $this->get(
602+
'automations/hooks',
603+
[
604+
'api_secret' => $this->api_secret,
605+
]
606+
);
607+
}
608+
592609
/**
593610
* Creates a webhook that will be called based on the chosen event types.
594611
*

tests/ConvertKitAPITest.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,32 @@ public function testGetSubscriberTagsWithInvalidSubscriberID()
694694
}
695695

696696
/**
697-
* Test that creating and destroying a webhook works.
697+
* Test that get_webhooks() returns the expected data.
698+
*
699+
* @since 1.0.0
700+
*
701+
* @return void
702+
*/
703+
public function testGetWebhooks()
704+
{
705+
// Create a webhook first.
706+
$result = $this->api->create_webhook(
707+
'https://webhook.site/2705fef6-34ef-4252-9c78-d511c540b58d',
708+
'subscriber.subscriber_activate',
709+
);
710+
$ruleID = $result->rule->id;
711+
712+
// List webhooks, confirming the webhook created exists in the list.
713+
$webhooks = $this->api->get_webhooks();
714+
$this->assertIsArray($webhooks);
715+
716+
// Destroy the webhook.
717+
$result = $this->api->destroy_webhook($ruleID);
718+
$this->assertEquals($result->success, true);
719+
}
720+
721+
/**
722+
* Test that create_webhook() and destroy_webhook() works.
698723
*
699724
* We do both, so we don't end up with unnecessary webhooks remaining
700725
* on the ConvertKit account when running tests.
@@ -718,7 +743,7 @@ public function testCreateAndDestroyWebhook()
718743
}
719744

720745
/**
721-
* Test that creating and destroying a webhook works with an event parameter.
746+
* Test that create_webhook() and destroy_webhook() works with an event parameter.
722747
*
723748
* We do both, so we don't end up with unnecessary webhooks remaining
724749
* on the ConvertKit account when running tests.
@@ -743,7 +768,7 @@ public function testCreateAndDestroyWebhookWithEventParameter()
743768
}
744769

745770
/**
746-
* Test that create_webook() throws an InvalidArgumentException when an invalid
771+
* Test that create_webhook() throws an InvalidArgumentException when an invalid
747772
* event is specified.
748773
*
749774
* @since 1.0.0

0 commit comments

Comments
 (0)