2020-04-24 11:55:33 +00:00
|
|
|
(ns dda.masto-embed.app
|
2020-04-24 15:22:51 +00:00
|
|
|
(:require
|
|
|
|
["mastodon-api" :as Mastodon]
|
|
|
|
[clojure.pprint :as pprint :refer [pprint]]
|
|
|
|
[cljs.core.async :refer [go]]
|
|
|
|
[cljs.core.async.interop :refer-macros [<p!]]))
|
2020-04-24 13:27:41 +00:00
|
|
|
|
2020-04-24 11:55:33 +00:00
|
|
|
(defn get-content-seq [response]
|
2020-04-24 13:27:41 +00:00
|
|
|
(map
|
|
|
|
#(aget % "content")
|
|
|
|
(array-seq
|
|
|
|
(aget response "data"))))
|
2020-04-24 09:24:09 +00:00
|
|
|
|
2020-04-24 16:22:41 +00:00
|
|
|
(defn luccas-fn []
|
2020-04-24 11:55:33 +00:00
|
|
|
(let [config (js-obj "api_url" "https://social.meissa-gmbh.de/api/v1/" "access_token" "...")
|
|
|
|
masto (new Mastodon config)
|
|
|
|
rest-endpoint "accounts/:id/statuses"
|
2020-04-24 16:04:25 +00:00
|
|
|
id-config (js-obj "id" "2")
|
|
|
|
result (go
|
|
|
|
(let [response (<p! (.get masto rest-endpoint id-config))]
|
|
|
|
(get-content-seq response)))]
|
|
|
|
(pprint result)
|
|
|
|
result))
|
2020-04-24 12:42:30 +00:00
|
|
|
|
2020-04-24 12:52:51 +00:00
|
|
|
(defn add-one [a]
|
2020-04-24 16:22:41 +00:00
|
|
|
(+ 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))
|