- defp webfinger_from_xml(doc) do
- magic_key = XML.string_from_xpath(~s{//Link[@rel="magic-public-key"]/@href}, doc)
- "data:application/magic-public-key," <> magic_key = magic_key
- topic = XML.string_from_xpath(~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href}, doc)
- subject = XML.string_from_xpath("//Subject", doc)
- salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc)
- subscribe_address = XML.string_from_xpath(~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template}, doc)
- ap_id = XML.string_from_xpath(~s{//Link[@rel="self" and @type="application/activity+json"]/@href}, doc)
- data = %{
- "magic_key" => magic_key,
- "topic" => topic,
- "subject" => subject,
- "salmon" => salmon,
- "subscribe_address" => subscribe_address,
- "ap_id" => ap_id
- }
+ defp webfinger_from_json(doc) do
+ data =
+ Enum.reduce(doc["links"], %{"subject" => doc["subject"]}, fn link, data ->
+ case {link["type"], link["rel"]} do
+ {"application/activity+json", "self"} ->
+ Map.put(data, "ap_id", link["href"])
+
+ {"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "self"} ->
+ Map.put(data, "ap_id", link["href"])
+
+ {_, "magic-public-key"} ->
+ "data:application/magic-public-key," <> magic_key = link["href"]
+ Map.put(data, "magic_key", magic_key)
+
+ {"application/atom+xml", "http://schemas.google.com/g/2010#updates-from"} ->
+ Map.put(data, "topic", link["href"])
+
+ {_, "salmon"} ->
+ Map.put(data, "salmon", link["href"])
+
+ {_, "http://ostatus.org/schema/1.0/subscribe"} ->
+ Map.put(data, "subscribe_address", link["template"])
+
+ _ ->
+ Logger.debug("Unhandled type: #{inspect(link["type"])}")
+ data
+ end
+ end)
+