Compare commits
No commits in common. "5ddc691dff7cee5ae45cdd09202153eaace62b11" and "9aed2c89a9ba4e15b80c161c5cc320391bba981e" have entirely different histories.
5ddc691dff
...
9aed2c89a9
4 changed files with 33 additions and 37 deletions
|
@ -1,9 +1,10 @@
|
||||||
(ns lambdaisland.souk.activitypub
|
(ns dda.activity-pub-poc.activitypub
|
||||||
"Interact with ActivityPub instances"
|
"Interact with ActivityPub instances"
|
||||||
(:require
|
(:require
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[lambdaisland.souk.json-ld :as ld]
|
[dda.activity-pub-poc.json-ld :as ld]
|
||||||
[lambdaisland.uri :as uri]))
|
[lambdaisland.uri :as uri]
|
||||||
|
[clojure.inspector :as ins]))
|
||||||
|
|
||||||
(def common-prefixes
|
(def common-prefixes
|
||||||
{"dcterms" "http://purl.org/dc/terms/"
|
{"dcterms" "http://purl.org/dc/terms/"
|
||||||
|
@ -49,7 +50,7 @@
|
||||||
"suspended" "toot:suspended"}])
|
"suspended" "toot:suspended"}])
|
||||||
|
|
||||||
(defn GET [url]
|
(defn GET [url]
|
||||||
(ld/internalize (ld/expand (:body (ld/json-get url))) common-prefixes))
|
(ld/internalize (ld/expand (ld/json-get url)) common-prefixes))
|
||||||
|
|
||||||
(defn kw->iri [kw]
|
(defn kw->iri [kw]
|
||||||
(if (string? kw)
|
(if (string? kw)
|
||||||
|
@ -76,3 +77,5 @@
|
||||||
(let [[username domain] (str/split (:path iri) #"@")]
|
(let [[username domain] (str/split (:path iri) #"@")]
|
||||||
{:domain domain
|
{:domain domain
|
||||||
:username username}))))
|
:username username}))))
|
||||||
|
|
||||||
|
(ins/inspect-tree (GET ld/team-url))
|
6
src/main/clj/dda/activity_pub_poc/core.clj
Normal file
6
src/main/clj/dda/activity_pub_poc/core.clj
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
(ns activity-pub-poc.core)
|
||||||
|
|
||||||
|
(defn -main
|
||||||
|
"I don't do a whole lot ... yet."
|
||||||
|
[& args]
|
||||||
|
(println "Hello, World!"))
|
|
@ -1,17 +1,21 @@
|
||||||
(ns lambdaisland.souk.json-ld
|
(ns dda.activity-pub-poc.json-ld
|
||||||
"Interfacing with JSON-LD endpoints, and converting to and from idiomatic
|
(:require
|
||||||
Clojure data."
|
[hato.client :as http]
|
||||||
(:require [hato.client :as hato]
|
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.walk :as walk]))
|
[clojure.walk :as walk]
|
||||||
|
[clojure.inspector :as ins]
|
||||||
|
))
|
||||||
|
|
||||||
|
(def team-url "https://social.meissa-gmbh.de/users/team")
|
||||||
|
|
||||||
|
(def context-cache (atom {}))
|
||||||
|
|
||||||
(defn json-get [url]
|
(defn json-get [url]
|
||||||
(hato/get url
|
(:body
|
||||||
|
(http/get url
|
||||||
{:headers {"Accept" "application/json"}
|
{:headers {"Accept" "application/json"}
|
||||||
:http-client {:redirect-policy :normal}
|
:http-client {:redirect-policy :normal}
|
||||||
:as :json-string-keys}))
|
:as :json-string-keys})))
|
||||||
|
|
||||||
(def context-cache (atom {})) ;; url -> context
|
|
||||||
|
|
||||||
(defn fetch-context [url]
|
(defn fetch-context [url]
|
||||||
(if-let [ctx (get @context-cache url)]
|
(if-let [ctx (get @context-cache url)]
|
||||||
|
@ -19,7 +23,7 @@
|
||||||
(get
|
(get
|
||||||
(swap! context-cache
|
(swap! context-cache
|
||||||
(fn [cache]
|
(fn [cache]
|
||||||
(assoc cache url (get (:body (json-get url)) "@context"))))
|
(assoc cache url (get (json-get url) "@context"))))
|
||||||
url)))
|
url)))
|
||||||
|
|
||||||
(defn expand-context
|
(defn expand-context
|
||||||
|
@ -165,9 +169,6 @@
|
||||||
(get iri->prop ?iri ?iri)))]
|
(get iri->prop ?iri ?iri)))]
|
||||||
(assoc (walk/postwalk convert-val v) "@context" context)))
|
(assoc (walk/postwalk convert-val v) "@context" context)))
|
||||||
|
|
||||||
;; (compact
|
(expand-context (get (json-get team-url) "@context"))
|
||||||
;; (expand (:body (json-get "https://toot.cat/users/plexus")))
|
|
||||||
;; common-prefixes)
|
|
||||||
|
|
||||||
;; "name"
|
(ins/inspect-tree (expand (json-get team-url)))
|
||||||
;; "profileName"
|
|
|
@ -1,14 +0,0 @@
|
||||||
(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)
|
|
Loading…
Reference in a new issue