jonnybarnes.uk/app/Jobs/SyndicateNoteToTwitter.php

58 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;
2016-09-20 13:13:05 +01:00
use Illuminate\Bus\Queueable;
2016-05-19 15:01:28 +01:00
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
2017-10-13 13:45:57 +01:00
class SyndicateNoteToTwitter implements ShouldQueue
2016-05-19 15:01:28 +01:00
{
2016-09-20 13:13:05 +01:00
use InteractsWithQueue, Queueable, SerializesModels;
2016-05-19 15:01:28 +01:00
protected $note;
/**
* Create a new job instance.
*
* @param \App\Models\Note $note
2016-05-19 15:01:28 +01:00
*/
public function __construct(Note $note)
{
$this->note = $note;
}
/**
* Execute the job.
*
* @param \GuzzleHttp\Client $guzzle
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
}
}