From 5ddc691dff7cee5ae45cdd09202153eaace62b11 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Sat, 17 Jun 2023 08:34:35 +0200 Subject: [PATCH] respect origin author --- src/main/clj/dda/activity_pub_poc/core.clj | 6 --- .../souk}/activitypub.clj | 11 ++--- .../souk}/json_ld.clj | 40 +++++++++---------- .../activity_pub_poc/core.clj | 14 +++++++ 4 files changed, 37 insertions(+), 34 deletions(-) delete mode 100644 src/main/clj/dda/activity_pub_poc/core.clj rename src/main/clj/{dda/activity_pub_poc => lambdaisland/souk}/activitypub.clj (92%) rename src/main/clj/{dda/activity_pub_poc => lambdaisland/souk}/json_ld.clj (88%) create mode 100644 src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/core.clj diff --git a/src/main/clj/dda/activity_pub_poc/core.clj b/src/main/clj/dda/activity_pub_poc/core.clj deleted file mode 100644 index 34df236..0000000 --- a/src/main/clj/dda/activity_pub_poc/core.clj +++ /dev/null @@ -1,6 +0,0 @@ -(ns activity-pub-poc.core) - -(defn -main - "I don't do a whole lot ... yet." - [& args] - (println "Hello, World!")) diff --git a/src/main/clj/dda/activity_pub_poc/activitypub.clj b/src/main/clj/lambdaisland/souk/activitypub.clj similarity index 92% rename from src/main/clj/dda/activity_pub_poc/activitypub.clj rename to src/main/clj/lambdaisland/souk/activitypub.clj index 98d38c8..82dcb5e 100644 --- a/src/main/clj/dda/activity_pub_poc/activitypub.clj +++ b/src/main/clj/lambdaisland/souk/activitypub.clj @@ -1,10 +1,9 @@ -(ns dda.activity-pub-poc.activitypub +(ns lambdaisland.souk.activitypub "Interact with ActivityPub instances" (:require [clojure.string :as str] - [dda.activity-pub-poc.json-ld :as ld] - [lambdaisland.uri :as uri] - [clojure.inspector :as ins])) + [lambdaisland.souk.json-ld :as ld] + [lambdaisland.uri :as uri])) (def common-prefixes {"dcterms" "http://purl.org/dc/terms/" @@ -50,7 +49,7 @@ "suspended" "toot:suspended"}]) (defn GET [url] - (ld/internalize (ld/expand (ld/json-get url)) common-prefixes)) + (ld/internalize (ld/expand (:body (ld/json-get url))) common-prefixes)) (defn kw->iri [kw] (if (string? kw) @@ -77,5 +76,3 @@ (let [[username domain] (str/split (:path iri) #"@")] {:domain domain :username username})))) - -(ins/inspect-tree (GET ld/team-url)) diff --git a/src/main/clj/dda/activity_pub_poc/json_ld.clj b/src/main/clj/lambdaisland/souk/json_ld.clj similarity index 88% rename from src/main/clj/dda/activity_pub_poc/json_ld.clj rename to src/main/clj/lambdaisland/souk/json_ld.clj index 66b069b..eb65aec 100644 --- a/src/main/clj/dda/activity_pub_poc/json_ld.clj +++ b/src/main/clj/lambdaisland/souk/json_ld.clj @@ -1,22 +1,17 @@ -(ns dda.activity-pub-poc.json-ld - (:require - [hato.client :as http] - [clojure.string :as str] - [clojure.walk :as walk] - [clojure.inspector :as ins] - )) - -(def team-url "https://social.meissa-gmbh.de/users/team") - -;; TODO: use a real cacheing lib instead of simple atom? -(def context-cache (atom {})) +(ns lambdaisland.souk.json-ld + "Interfacing with JSON-LD endpoints, and converting to and from idiomatic + Clojure data." + (:require [hato.client :as hato] + [clojure.string :as str] + [clojure.walk :as walk])) (defn json-get [url] - (:body - (http/get url - {:headers {"Accept" "application/json"} - :http-client {:redirect-policy :normal} - :as :json-string-keys}))) + (hato/get url + {:headers {"Accept" "application/json"} + :http-client {:redirect-policy :normal} + :as :json-string-keys})) + +(def context-cache (atom {})) ;; url -> context (defn fetch-context [url] (if-let [ctx (get @context-cache url)] @@ -24,7 +19,7 @@ (get (swap! context-cache (fn [cache] - (assoc cache url (get (json-get url) "@context")))) + (assoc cache url (get (:body (json-get url)) "@context")))) url))) (defn expand-context @@ -85,7 +80,7 @@ "@value" v)) v)]))) v) - + (sequential? v) (into (empty v) (map #(apply-context % ctx)) v) @@ -170,6 +165,9 @@ (get iri->prop ?iri ?iri)))] (assoc (walk/postwalk convert-val v) "@context" context))) -(expand-context (get (json-get team-url) "@context")) +;; (compact +;; (expand (:body (json-get "https://toot.cat/users/plexus"))) +;; common-prefixes) -(ins/inspect-tree (expand (json-get team-url))) +;; "name" +;; "profileName" diff --git a/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/core.clj b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/core.clj new file mode 100644 index 0000000..43c7f90 --- /dev/null +++ b/src/main/clj/org/domaindrivenarchitecture/activity_pub_poc/core.clj @@ -0,0 +1,14 @@ +(ns org.domaindrivenarchitecture.activity-pub-poc.core + (:require [lambdaisland.souk.activitypub :as ap] + [lambdaisland.souk.json-ld :as ld] + [clojure.inspector :as ins]) ) + +(def team-url "https://social.meissa-gmbh.de/users/team") + +(def context (ld/expand-context (get (ld/json-get team-url) "@context"))) + +(def expanded-ld (ins/inspect-tree (ld/expand (ld/json-get team-url)))) + +(def ap-resource (ap/GET team-url)) + +(ins/inspect-tree ap-resource)