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
This commit is contained in:
parent
7204e2c5e8
commit
79cffc22fe
|
@ -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),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opdavies_blog\Service\PostPusher;
|
||||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\opdavies_blog\Entity\Node\Post;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class IntegromatPostPusher extends HttpPostPusher {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
private ConfigFactoryInterface $configFactory;
|
||||
|
||||
public function __construct(
|
||||
ClientInterface $client,
|
||||
ConfigFactoryInterface $configFactory
|
||||
) {
|
||||
$this->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(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue