jonnybarnes.uk/app/Jobs/SyndicateNoteToTwitter.php

61 lines
1.4 KiB
PHP
Raw Normal View History

2016-05-19 15:01:28 +01:00
<?php
declare(strict_types=1);
2016-05-19 15:01:28 +01:00
namespace App\Jobs;
2017-12-19 16:00:42 +00:00
use App\Models\Note;
use GuzzleHttp\Client;
2019-10-27 19:31:33 +00:00
use GuzzleHttp\Exception\GuzzleException;
2016-09-20 13:13:05 +01:00
use Illuminate\Bus\Queueable;
2016-05-19 15:01:28 +01:00
use Illuminate\Contracts\Queue\ShouldQueue;
2019-10-27 16:29:15 +00:00
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
2016-05-19 15:01:28 +01:00
2017-10-13 13:45:57 +01:00
class SyndicateNoteToTwitter implements ShouldQueue
2016-05-19 15:01:28 +01:00
{
2019-10-27 19:31:33 +00:00
use InteractsWithQueue;
use Queueable;
use SerializesModels;
2016-05-19 15:01:28 +01:00
2019-10-27 19:31:33 +00:00
/** @var Note */
2016-05-19 15:01:28 +01:00
protected $note;
/**
* Create a new job instance.
*/
public function __construct(Note $note)
{
$this->note = $note;
}
/**
* Execute the job.
*
2022-07-09 10:08:26 +01:00
*
2019-10-27 19:31:33 +00:00
* @throws GuzzleException
2016-05-19 15:01:28 +01:00
*/
public function handle(Client $guzzle)
2016-05-19 15:01:28 +01:00
{
//send webmention
$response = $guzzle->request(
'POST',
'https://brid.gy/publish/webmention',
[
'form_params' => [
'source' => $this->note->longurl,
'target' => 'https://brid.gy/publish/twitter',
'bridgy_omit_link' => 'maybe',
],
]
2016-05-19 15:01:28 +01:00
);
//parse for syndication URL
if ($response->getStatusCode() == 201) {
$json = json_decode((string) $response->getBody());
$tweet_id = basename(parse_url($json->url, PHP_URL_PATH));
$this->note->tweet_id = $tweet_id;
$this->note->save();
}
2016-05-19 15:01:28 +01:00
}
}