Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
LemmyPublisher
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 publishToChannel
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Modules\Lemmy\Services;
4
5use App\Exceptions\PlatformAuthException;
6use App\Models\Article;
7use App\Models\PlatformAccount;
8use App\Models\PlatformChannel;
9use App\Services\Auth\LemmyAuthService;
10use Exception;
11
12class LemmyPublisher
13{
14    private LemmyApiService $api;
15    private PlatformAccount $account;
16
17    public function __construct(PlatformAccount $account)
18    {
19        $this->api = new LemmyApiService($account->instance_url);
20        $this->account = $account;
21    }
22
23    /**
24     * @param array<string, mixed> $extractedData
25     * @return array<string, mixed>
26     * @throws PlatformAuthException
27     * @throws Exception
28     */
29    public function publishToChannel(Article $article, array $extractedData, PlatformChannel $channel): array
30    {
31        $token = LemmyAuthService::getToken($this->account);
32
33        // Use the language ID from extracted data (should be set during validation)
34        $languageId = $extractedData['language_id'] ?? null;
35
36        return $this->api->createPost(
37            $token,
38            $extractedData['title'] ?? 'Untitled',
39            $extractedData['description'] ?? '',
40            $channel->channel_id,
41            $article->url,
42            $extractedData['thumbnail'] ?? null,
43            $languageId
44        );
45    }
46
47}