♻️ DRY sync//history
This commit is contained in:
parent
a148fd32d7
commit
fda7c13926
4 changed files with 48 additions and 30 deletions
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Commands;
|
||||
|
||||
use App\Data\WatchData;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Services\Trakt;
|
||||
|
||||
class TraktWatchImport extends Command
|
||||
{
|
||||
|
|
@ -13,19 +13,8 @@ class TraktWatchImport extends Command
|
|||
public function handle(): int
|
||||
{
|
||||
$watched = WatchData::from($this->arguments());
|
||||
$data = $watched->structuredData;
|
||||
$resp = $this->app->make(Trakt::class)->syncHistory($watched, $this->output);
|
||||
|
||||
$headers = [
|
||||
'trakt-api-version' => 2,
|
||||
'trakt-api-key' => env('TRAKT_APP_ID'),
|
||||
'Authorization' => 'Bearer ' . env('TRAKT_OAUTH_TOKEN'),
|
||||
];
|
||||
|
||||
$this->info(sprintf('Submitting %s to trakt with headers %s', json_encode($data), json_encode($headers)));
|
||||
$response = Http::withHeaders($headers)->post('https://api.trakt.tv/sync/history', $data);
|
||||
|
||||
$this->line('Response: ' . PHP_EOL . json_encode($response->json(), JSON_PRETTY_PRINT));
|
||||
|
||||
return static::SUCCESS;
|
||||
return $resp->ok() ? static::SUCCESS : static::FAILURE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue