2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Note;
|
2016-10-26 22:00:26 +01:00
|
|
|
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;
|
|
|
|
|
2016-09-20 13:13:05 +01:00
|
|
|
class SyndicateToTwitter 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.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Note $note)
|
|
|
|
{
|
|
|
|
$this->note = $note;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
2016-10-26 22:00:26 +01:00
|
|
|
* @param \GuzzleHttp\Client $guzzle
|
2016-05-19 15:01:28 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-10-26 22:00:26 +01:00
|
|
|
public function handle(Client $guzzle)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2016-10-26 22:00:26 +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',
|
2017-09-20 14:14:29 +01:00
|
|
|
'bridgy_omit_link' => 'maybe',
|
2016-10-26 22:00:26 +01:00
|
|
|
],
|
|
|
|
]
|
2016-05-19 15:01:28 +01:00
|
|
|
);
|
2016-10-26 22:00:26 +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
|
|
|
}
|
|
|
|
}
|