From 6f8122bed6cff659a22072990d1a8afb051e39c2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 31 May 2018 16:02:24 -0600 Subject: [PATCH] Add ActivityPub DiscoverActor util --- app/Util/ActivityPub/DiscoverActor.php | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/Util/ActivityPub/DiscoverActor.php diff --git a/app/Util/ActivityPub/DiscoverActor.php b/app/Util/ActivityPub/DiscoverActor.php new file mode 100644 index 000000000..6c81b3d1a --- /dev/null +++ b/app/Util/ActivityPub/DiscoverActor.php @@ -0,0 +1,49 @@ +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; + } + +} \ No newline at end of file