jonnybarnes.uk/app/Jobs/SyndicateBookmarkToTwitter.php

55 lines
1.3 KiB
PHP
Raw Normal View History

2016-05-19 15:01:28 +01:00
<?php
namespace App\Jobs;
2017-10-13 13:45:57 +01:00
use App\Bookmark;
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 SyndicateBookmarkToTwitter 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
2017-10-13 13:45:57 +01:00
protected $bookmark;
2016-05-19 15:01:28 +01:00
/**
* Create a new job instance.
*
* @return void
*/
2017-10-13 13:45:57 +01:00
public function __construct(Bookmark $bookmark)
2016-05-19 15:01:28 +01:00
{
2017-10-13 13:45:57 +01:00
$this->bookmark = $bookmark;
2016-05-19 15:01:28 +01:00
}
/**
* Execute the job.
*
* @return void
*/
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' => [
2017-10-13 13:45:57 +01:00
'source' => $this->bookmark->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());
2017-10-13 13:45:57 +01:00
$this->bookmark->update(['syndicates->twitter' => $json->url]);
$this->bookmark->save();
}
2016-05-19 15:01:28 +01:00
}
}