Remove references to the toTweet() method

This commit is contained in:
Oliver Davies 2021-04-21 00:44:56 +01:00
parent 7542a2a542
commit 909374edcb
3 changed files with 18 additions and 5 deletions

View file

@ -6,6 +6,7 @@ namespace Drupal\opdavies_blog\Service\PostPusher;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\opdavies_blog\Action\ConvertPostToTweet;
use Drupal\opdavies_blog\Entity\Node\Post;
use GuzzleHttp\ClientInterface;
use Webmozart\Assert\Assert;
@ -17,12 +18,14 @@ final class IftttPostPusher extends WebhookPostPusher {
private ConfigFactoryInterface $configFactory;
public function __construct(
ConvertPostToTweet $convertPostToTweetAction,
ClientInterface $client,
ConfigFactoryInterface $configFactory
) {
$this->convertPostToTweetAction = $convertPostToTweetAction;
$this->configFactory = $configFactory;
parent::__construct($client);
parent::__construct($convertPostToTweetAction, $client);
}
public function push(Post $post): void {
@ -34,7 +37,7 @@ final class IftttPostPusher extends WebhookPostPusher {
$this->client->post($url, [
'form_params' => [
'value1' => $this->t('Blogged: @text', ['@text' => $post->toTweet()])
'value1' => $this->t('Blogged: @text', ['@text' => ($this->convertPostToTweetAction)($post)])
->render(),
],
]);

View file

@ -6,6 +6,7 @@ namespace Drupal\opdavies_blog\Service\PostPusher;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\opdavies_blog\Action\ConvertPostToTweet;
use Drupal\opdavies_blog\Entity\Node\Post;
use GuzzleHttp\ClientInterface;
use Webmozart\Assert\Assert;
@ -17,12 +18,14 @@ final class IntegromatPostPusher extends WebhookPostPusher {
private ConfigFactoryInterface $configFactory;
public function __construct(
ConvertPostToTweet $convertPostToTweetAction,
ClientInterface $client,
ConfigFactoryInterface $configFactory
) {
$this->convertPostToTweetAction = $convertPostToTweetAction;
$this->configFactory = $configFactory;
parent::__construct($client);
parent::__construct($convertPostToTweetAction, $client);
}
public function push(Post $post): void {
@ -34,7 +37,7 @@ final class IntegromatPostPusher extends WebhookPostPusher {
$this->client->post($url, [
'form_params' => [
'text' => $this->t('@text', ['@text' => $post->toTweet()])
'text' => $this->t('@text', ['@text' => ($this->convertPostToTweetAction)($post)])
->render(),
],
]);

View file

@ -4,13 +4,20 @@ declare(strict_types=1);
namespace Drupal\opdavies_blog\Service\PostPusher;
use Drupal\opdavies_blog\Action\ConvertPostToTweet;
use GuzzleHttp\ClientInterface;
abstract class WebhookPostPusher implements PostPusher {
protected ConvertPostToTweet $convertPostToTweetAction;
protected ClientInterface $client;
public function __construct(ClientInterface $client) {
public function __construct(
ConvertPostToTweet $convertPostToTweetAction,
ClientInterface $client
) {
$this->convertPostToTweetAction = $convertPostToTweetAction;
$this->client = $client;
}