2024-10-09 22:45:28 +00:00
|
|
|
defmodule ActivityPub do
|
2024-10-14 01:02:59 +00:00
|
|
|
def get(url, actor_url, private_key) do
|
|
|
|
|
headers = ActivityPub.Headers.signing_headers("GET", url, "", actor_url, private_key)
|
|
|
|
|
|
|
|
|
|
Req.new(url: url)
|
|
|
|
|
|> Req.Request.put_header("accept", "application/activity+json")
|
|
|
|
|
|> Req.Request.put_headers(headers)
|
|
|
|
|
|> Req.get()
|
|
|
|
|
|> case do
|
|
|
|
|
{:ok, response} ->
|
|
|
|
|
{:ok, response.body}
|
|
|
|
|
|
|
|
|
|
other ->
|
|
|
|
|
other
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-10-10 00:01:44 +00:00
|
|
|
def fetch_actor(actor_id) do
|
2024-10-14 01:02:59 +00:00
|
|
|
request =
|
|
|
|
|
Req.new(url: actor_id)
|
|
|
|
|
|> Req.Request.put_header("accept", "application/json")
|
2024-10-10 00:01:44 +00:00
|
|
|
|
2024-10-14 01:02:59 +00:00
|
|
|
case Req.get(request) do
|
|
|
|
|
{:ok, result} ->
|
|
|
|
|
{:ok, result.body}
|
2024-10-10 00:01:44 +00:00
|
|
|
|
2024-10-14 01:02:59 +00:00
|
|
|
error ->
|
|
|
|
|
error
|
|
|
|
|
end
|
2024-10-10 00:01:44 +00:00
|
|
|
end
|
2024-10-09 22:45:28 +00:00
|
|
|
end
|