From 79cffc22feac4a1903afbf9210863bb0fd28ec19 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 22 Jan 2021 02:23:57 +0000 Subject: [PATCH] Add Integtomat implementation of PostPusher Add an Integromat post pusher and add it to the queue worker so that posts are pushed both to IFTTT (for Twitter) and Integromat (for LinkedIn). References #340 --- .../QueueWorker/PostPusherQueueWorker.php | 2 + .../PostPusher/IntegromatPostPusher.php | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php diff --git a/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php b/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php index ac050de..ddc0ac6 100644 --- a/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php +++ b/web/modules/custom/blog/src/Plugin/QueueWorker/PostPusherQueueWorker.php @@ -9,6 +9,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Queue\QueueWorkerBase; use Drupal\opdavies_blog\Entity\Node\Post; use Drupal\opdavies_blog\Service\PostPusher\IftttPostPusher; +use Drupal\opdavies_blog\Service\PostPusher\IntegromatPostPusher; use Drupal\opdavies_blog\Service\PostPusher\PostPusher; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -54,6 +55,7 @@ final class PostPusherQueueWorker extends QueueWorkerBase implements ContainerFa $container->get('entity_type.manager')->getStorage('node'), [ $container->get(IftttPostPusher::class), + $container->get(IntegromatPostPusher::class), ] ); } diff --git a/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php b/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php new file mode 100644 index 0000000..86436b4 --- /dev/null +++ b/web/modules/custom/blog/src/Service/PostPusher/IntegromatPostPusher.php @@ -0,0 +1,43 @@ +configFactory = $configFactory; + + parent::__construct($client); + } + + public function push(Post $post): void { + $url = $this->configFactory + ->get('opdavies_blog.settings') + ->get('integromat_webhook_url'); + + Assert::notNull($url, 'Cannot push the post if there is no URL.'); + + $this->client->post($url, [ + 'form_params' => [ + 'text' => $this->t('@text', ['@text' => $post->toTweet()]) + ->render(), + ], + ]); + } + +}