jonnybarnes.uk/app/Jobs/SyndicateToTwitter.php
Jonny Barnes fafab6e013 Squashed commit of the following:
commit d198ef5fc3a535b6384f5de33ac41cf8d2bd9a40
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 26 22:00:11 2016 +0100

    Add latest bridgy related changes

commit b1c72c8f70df03134bea14d2668fb90915fb7853
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 26 19:13:15 2016 +0100

    Have links on Facebook

commit e99618618ae1fc84081db241d05fd15ce65af66f
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 26 18:15:47 2016 +0100

    Add a job to syndicate to facebook

commit c37653e2b1a2237172b24dfa3b0bc4da30b52927
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 26 18:15:25 2016 +0100

    Fix some typos in the comments

commit c65bd20a94478cc1e5832b22d48d824a00411f92
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 26 17:54:13 2016 +0100

    Add necessary a links to facilitate bridgy publishing

commit b62d3a4daf39ebf8c495f381702a25ed0715e1fe
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 26 17:46:04 2016 +0100

    Send webmentions to bridgy in order to syndicate
2016-10-26 22:00:26 +01:00

55 lines
1.3 KiB
PHP

<?php
namespace App\Jobs;
use App\Note;
use GuzzleHttp\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class SyndicateToTwitter implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $note;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Note $note)
{
$this->note = $note;
}
/**
* Execute the job.
*
* @param \GuzzleHttp\Client $guzzle
* @return void
*/
public function handle(Client $guzzle)
{
//send webmention
$response = $guzzle->request(
'POST',
'https://brid.gy/publish/webmention',
[
'form_params' => [
'source' => $this->note->longurl,
'target' => 'https://brid.gy/publish/twitter',
],
]
);
//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();
}
}
}