From 5fde78a34364370632ad15d7652ee455154b796f Mon Sep 17 00:00:00 2001 From: jem Date: Sun, 26 Apr 2020 18:35:09 +0200 Subject: [PATCH] more direct --- public/index.html | 2 +- src/main/dda/masto_embed/api.cljs | 35 ++++++++++++++----------------- src/main/dda/masto_embed/app.cljs | 22 +++++++++++++------ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/public/index.html b/public/index.html index 5d22a58..798c377 100644 --- a/public/index.html +++ b/public/index.html @@ -5,7 +5,7 @@ masto-embed -
Here the timeline will appear.
diff --git a/src/main/dda/masto_embed/api.cljs b/src/main/dda/masto_embed/api.cljs index cb9e276..8bd490d 100644 --- a/src/main/dda/masto_embed/api.cljs +++ b/src/main/dda/masto_embed/api.cljs @@ -19,20 +19,11 @@ [clojure.spec.alpha :as s] [clojure.spec.test.alpha :as st] [orchestra.core :refer-macros [defn-spec]] - [clojure.pprint :as pprint :refer [pprint]] [cljs.core.async :refer [go]] [cljs.core.async.interop :refer-macros [edn [data] (js->clj data :keywordize-keys true)) -(defn mastodon-client [mastodon-config] - (or (some-> mastodon-config clj->js Mastodon.) - (exit-with-error "missing Mastodon client configuration!"))) +(defn-spec mastodon-client any? + [host-url ::host-url] + (let [mastodon-config + {:access_token "unused" + :api_url (str host-url "/api/v1/")}] + (some-> mastodon-config clj->js Mastodon.))) -(defn get-account-statuses [mastodon-config callback] - (.then (.get (mastodon-client mastodon-config) - (str "accounts/" (:account-id mastodon-config) "/statuses") +(defn-spec get-account-statuses any? + [host-url ::host-url + account-id ::account-id + callback fn?] + (.then (.get (mastodon-client host-url) + (str "accounts/" account-id "/statuses") #js {}) #(let [response (-> % .-data js->edn)] (if-let [error (:error response)] (exit-with-error error) (callback response))))) -(defn get-directory [mastodon-config callback] - (.then (.get (mastodon-client mastodon-config) +(defn-spec get-directory any? + [host-url ::host-url + callback fn?] + (.then (.get (mastodon-client host-url) (str "directory?local=true") #js {}) #(let [response (-> % .-data js->edn)] (if-let [error (:error response)] (exit-with-error error) (callback response))))) - -(def my-config (create-config "2" "https://social.meissa-gmbh.de")) diff --git a/src/main/dda/masto_embed/app.cljs b/src/main/dda/masto_embed/app.cljs index 2902bfb..648abf2 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -20,11 +20,20 @@ (def masto-embed "masto-embed") -(defn mastodon-config-from-document [] - (let [masto-embed (.getElementById js/document masto-embed) - host-url (.getAttribute masto-embed "host_url") - account-id (.getAttribute masto-embed "account_id")] - (api/create-config account-id host-url))) +(defn host-url-from-document [] + (-> js/document + (.getElementById masto-embed) + (.getAttribute "host_url"))) + +(defn account-name-from-document [] + (-> js/document + (.getElementById masto-embed) + (.getAttribute "account_name"))) + +(defn account-id-from-document [] + (-> js/document + (.getElementById masto-embed) + (.getAttribute "account_id"))) (defn render-to-document [input] @@ -35,5 +44,6 @@ (defn init [] (api/get-account-statuses - (mastodon-config-from-document) + (host-url-from-document) + (account-id-from-document) render-to-document)) \ No newline at end of file