Loading appinfo/info.xml +1 −0 Original line number Diff line number Diff line Loading @@ -29,5 +29,6 @@ <command>OCA\EcloudAccounts\Command\MigrateWebmailAddressbooks</command> <command>OCA\EcloudAccounts\Command\MapActiveAttributetoLDAP</command> <command>OCA\EcloudAccounts\Command\DeleteSendgridContact</command> <command>OCA\EcloudAccounts\Command\RefreshSendGridSegment</command> </commands> </info> lib/Command/RefreshSendGridSegment.php 0 → 100644 +65 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace OCA\EcloudAccounts\Command; use Exception; use OCA\EcloudAccounts\Service\SendGridService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class RefreshSendGridSegment extends Command { private SendGridService $sendGridService; public function __construct(SendGridService $sendGridService) { $this->sendGridService = $sendGridService; parent::__construct(); } protected function configure(): void { $this ->setName('ecloud-accounts:refresh-sendgrid-segment') ->setDescription('Refreshes the SendGrid segment') ->addOption( 'segment-id', null, InputOption::VALUE_REQUIRED, 'The ID of the SendGrid segment' ) ->addOption( 'refresh', null, InputOption::VALUE_NONE, 'Trigger the refresh of the SendGrid segment' ); } protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('refresh')) { $segmentId = $input->getOption('segment-id'); if (!$segmentId) { $output->writeln('<error>option --segment-id is required.</error>'); return Command::FAILURE; } try { $success = $this->sendGridService->refreshSendGridSegment($segmentId); if ($success) { $output->writeln('<info>Segment refreshed successfully.</info>'); return Command::SUCCESS; } } catch (Exception $e) { $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); return Command::FAILURE; } return 0; } $output->writeln('No action taken.'); return 0; } } lib/Service/SendGridService.php +25 −0 Original line number Diff line number Diff line Loading @@ -12,10 +12,12 @@ use OCP\IConfig; class SendGridService { private \SendGrid $sendGridClient; private $config; private $apiKey; public function __construct(IConfig $config) { $this->config = $config; $apiKey = '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'; $this->apiKey = $apiKey; $this->sendGridClient = new \SendGrid($apiKey); } Loading Loading @@ -103,4 +105,27 @@ class SendGridService { throw new Exception("Failed to delete contacts: " . $response->body()); } } public function refreshSendGridSegment($segmentId) { $data = [ 'user_time_zone' => 'America/Chicago' ]; try { $response = $this->sendGridClient->client ->marketing() ->segments() ->_($segmentId) ->refresh() ->post($data); if ($response->statusCode() === 202) { return true; } else { throw new Exception("Failed to delete contacts: " . $response->body()); } } catch (Exception $e) { throw new Exception('Caught exception: ' . $e->getMessage()); } } } Loading
appinfo/info.xml +1 −0 Original line number Diff line number Diff line Loading @@ -29,5 +29,6 @@ <command>OCA\EcloudAccounts\Command\MigrateWebmailAddressbooks</command> <command>OCA\EcloudAccounts\Command\MapActiveAttributetoLDAP</command> <command>OCA\EcloudAccounts\Command\DeleteSendgridContact</command> <command>OCA\EcloudAccounts\Command\RefreshSendGridSegment</command> </commands> </info>
lib/Command/RefreshSendGridSegment.php 0 → 100644 +65 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace OCA\EcloudAccounts\Command; use Exception; use OCA\EcloudAccounts\Service\SendGridService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class RefreshSendGridSegment extends Command { private SendGridService $sendGridService; public function __construct(SendGridService $sendGridService) { $this->sendGridService = $sendGridService; parent::__construct(); } protected function configure(): void { $this ->setName('ecloud-accounts:refresh-sendgrid-segment') ->setDescription('Refreshes the SendGrid segment') ->addOption( 'segment-id', null, InputOption::VALUE_REQUIRED, 'The ID of the SendGrid segment' ) ->addOption( 'refresh', null, InputOption::VALUE_NONE, 'Trigger the refresh of the SendGrid segment' ); } protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('refresh')) { $segmentId = $input->getOption('segment-id'); if (!$segmentId) { $output->writeln('<error>option --segment-id is required.</error>'); return Command::FAILURE; } try { $success = $this->sendGridService->refreshSendGridSegment($segmentId); if ($success) { $output->writeln('<info>Segment refreshed successfully.</info>'); return Command::SUCCESS; } } catch (Exception $e) { $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); return Command::FAILURE; } return 0; } $output->writeln('No action taken.'); return 0; } }
lib/Service/SendGridService.php +25 −0 Original line number Diff line number Diff line Loading @@ -12,10 +12,12 @@ use OCP\IConfig; class SendGridService { private \SendGrid $sendGridClient; private $config; private $apiKey; public function __construct(IConfig $config) { $this->config = $config; $apiKey = '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'; $this->apiKey = $apiKey; $this->sendGridClient = new \SendGrid($apiKey); } Loading Loading @@ -103,4 +105,27 @@ class SendGridService { throw new Exception("Failed to delete contacts: " . $response->body()); } } public function refreshSendGridSegment($segmentId) { $data = [ 'user_time_zone' => 'America/Chicago' ]; try { $response = $this->sendGridClient->client ->marketing() ->segments() ->_($segmentId) ->refresh() ->post($data); if ($response->statusCode() === 202) { return true; } else { throw new Exception("Failed to delete contacts: " . $response->body()); } } catch (Exception $e) { throw new Exception('Caught exception: ' . $e->getMessage()); } } }