1
0
Fork 0
pixelfed/app/Util/ActivityPub/DiscoverActor.php

50 lines
981 B
PHP
Raw 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;
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([
'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
'User-Agent' => 'PixelFedBot - https://pixelfed.org',
2018-05-31 22:02:24 +00:00
])->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();
if (empty($res) || !in_array('type', $res) || $res['type'] !== 'Person') {
throw new \Exception('Invalid Actor Object');
}
return $res;
}
}