From d9467f5f1d4bd667c19aa41ea5ae9d43e7348ae0 Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 24 Apr 2020 18:22:41 +0200 Subject: [PATCH] works now in a more clojure way --- src/main/dda/masto_embed/app.cljs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/dda/masto_embed/app.cljs b/src/main/dda/masto_embed/app.cljs index 8b1e146..1371185 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -11,7 +11,7 @@ (array-seq (aget response "data")))) -(defn init [] +(defn luccas-fn [] (let [config (js-obj "api_url" "https://social.meissa-gmbh.de/api/v1/" "access_token" "...") masto (new Mastodon config) rest-endpoint "accounts/:id/statuses" @@ -23,4 +23,31 @@ result)) (defn add-one [a] - (+ a 1)) \ No newline at end of file + (+ a 1)) + +;from yogthos / mastodon-bot + +(defn exit-with-error [error] + (js/console.error error) + (js/process.exit 1)) + +(defn js->edn [data] + (js->clj data :keywordize-keys true)) + +(def mastodon-config + {:access_token "XXXX" + :account-id "2" + :api_url "https://social.meissa-gmbh.de/api/v1/"}) + +(def mastodon-client (or (some-> mastodon-config clj->js Mastodon.) + (exit-with-error "missing Mastodon client configuration!"))) + +(defn get-mastodon-timeline [callback] + (.then (.get mastodon-client (str "accounts/" (:account-id mastodon-config) "/statuses") #js {}) + #(let [response (-> % .-data js->edn)] + (if-let [error (:error response)] + (exit-with-error error) + (callback response))))) + +(defn init [] + (get-mastodon-timeline pprint)) \ No newline at end of file