more direct
This commit is contained in:
parent
de0c47124c
commit
5fde78a343
3 changed files with 33 additions and 26 deletions
|
@ -5,7 +5,7 @@
|
|||
<title>masto-embed</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="masto-embed" account_id="2"
|
||||
<div id="masto-embed" account_name="team" account_id="2"
|
||||
host_url="https://social.meissa-gmbh.de">
|
||||
Here the timeline will appear.
|
||||
</div>
|
||||
|
|
|
@ -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 [<p!]]))
|
||||
|
||||
(s/def ::account-id string?)
|
||||
(s/def ::host-url string?)
|
||||
|
||||
(defn-spec create-config map?
|
||||
[account-id ::account-id
|
||||
host-url ::host-url]
|
||||
{:access_token "unused"
|
||||
:account-id account-id
|
||||
:api_url (str host-url "/api/v1/") })
|
||||
|
||||
(defn exit-with-error [error]
|
||||
(js/console.error error)
|
||||
(js/process.exit 1))
|
||||
|
@ -40,26 +31,32 @@
|
|||
(defn js->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"))
|
||||
|
|
|
@ -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))
|
Loading…
Reference in a new issue