mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add ActivityPub DiscoverActor util
This commit is contained in:
parent
27e779b08d
commit
6f8122bed6
1 changed files with 49 additions and 0 deletions
49
app/Util/ActivityPub/DiscoverActor.php
Normal file
49
app/Util/ActivityPub/DiscoverActor.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Util\ActivityPub;
|
||||
|
||||
use \Zttp\Zttp;
|
||||
|
||||
class DiscoverActor {
|
||||
|
||||
protected $url;
|
||||
protected $response;
|
||||
|
||||
public function __construct($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
$res = Zttp::withHeaders([
|
||||
'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => 'PixelFedBot - https://pixelfed.org'
|
||||
])->get($this->url);
|
||||
$this->response = $res->body();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getResponse()
|
||||
{
|
||||
return json_decode($this->response, true);
|
||||
}
|
||||
|
||||
public function getJsonResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function discover()
|
||||
{
|
||||
$this->fetch();
|
||||
$res = $this->getResponse();
|
||||
|
||||
if(empty($res) || !in_array('type', $res) || $res['type'] !== 'Person') {
|
||||
throw new \Exception('Invalid Actor Object');
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue