pixelfed/app/Util/ActivityPub/DiscoverActor.php

51 lines
995 B
PHP
Raw Permalink Normal View History

2018-05-31 22:02:24 +00:00
<?php
namespace App\Util\ActivityPub;
2018-08-28 03:07:36 +00:00
use Zttp\Zttp;
2018-05-31 22:02:24 +00:00
2018-08-28 03:07:36 +00:00
class DiscoverActor
{
protected $url;
2024-09-11 11:43:17 +00:00
2018-08-28 03:07:36 +00:00
protected $response;
2018-05-31 22:02:24 +00:00
2018-08-28 03:07:36 +00:00
public function __construct($url)
{
$this->url = $url;
}
2018-05-31 22:02:24 +00:00
2018-08-28 03:07:36 +00:00
public function fetch()
{
$res = Zttp::withHeaders([
2024-09-11 11:43:17 +00:00
'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => 'PixelfedBot - https://pixelfed.org',
])->get($this->url);
2018-08-28 03:07:36 +00:00
$this->response = $res->body();
return $this;
2018-05-31 22:02:24 +00:00
}
2018-08-28 03:07:36 +00:00
public function getResponse()
{
return json_decode($this->response, true);
}
2018-05-31 22:02:24 +00:00
2018-08-28 03:07:36 +00:00
public function getJsonResponse()
{
return $this->response;
}
public function discover()
{
$this->fetch();
$res = $this->getResponse();
2024-09-11 11:43:17 +00:00
if (empty($res) || ! in_array('type', $res) || $res['type'] !== 'Person') {
2018-08-28 03:07:36 +00:00
throw new \Exception('Invalid Actor Object');
}
return $res;
}
}