Syndicate bookmarks via jobs
This commit is contained in:
parent
917a673f05
commit
f007b24065
9 changed files with 161 additions and 10 deletions
54
app/Jobs/SyndicateBookmarkToTwitter.php
Normal file
54
app/Jobs/SyndicateBookmarkToTwitter.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Bookmark;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class SyndicateBookmarkToTwitter implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $bookmark;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Bookmark $bookmark)
|
||||
{
|
||||
$this->bookmark = $bookmark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Client $guzzle)
|
||||
{
|
||||
//send webmention
|
||||
$response = $guzzle->request(
|
||||
'POST',
|
||||
'https://brid.gy/publish/webmention',
|
||||
[
|
||||
'form_params' => [
|
||||
'source' => $this->bookmark->longurl,
|
||||
'target' => 'https://brid.gy/publish/twitter',
|
||||
'bridgy_omit_link' => 'maybe',
|
||||
],
|
||||
]
|
||||
);
|
||||
//parse for syndication URL
|
||||
if ($response->getStatusCode() == 201) {
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$this->bookmark->update(['syndicates->twitter' => $json->url]);
|
||||
$this->bookmark->save();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue