diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 19e4f0f..c040ea1 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -5,7 +5,7 @@ "src/test"] :dependencies - [] + [[orchestra "2018.12.06-2"]] :dev-http {8080 "public"} :builds {:test diff --git a/src/main/dda/masto_embed/api.cljs b/src/main/dda/masto_embed/api.cljs new file mode 100644 index 0000000..85c6563 --- /dev/null +++ b/src/main/dda/masto_embed/api.cljs @@ -0,0 +1,54 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. +(ns dda.masto-embed.api + (:require + ["mastodon-api" :as Mastodon] + [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 get-mastodon-timeline [mastodon-config callback] + (.then (.get (mastodon-client mastodon-config) + (str "accounts/" (:account-id mastodon-config) "/statuses") + #js {}) + #(let [response (-> % .-data js->edn)] + (if-let [error (:error response)] + (exit-with-error error) + (callback response))))) \ No newline at end of file diff --git a/src/main/dda/masto_embed/app.cljs b/src/main/dda/masto_embed/app.cljs index 1bdf1ab..f5b9240 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -1,53 +1,25 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. (ns dda.masto-embed.app (:require - ["mastodon-api" :as Mastodon] - [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)) + [dda.masto-embed.api :as api] + [clojure.pprint :as pprint :refer [pprint]])) (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))))) + (api/create-config "2" "https://social.meissa-gmbh.de")) (defn render-to-document [input] @@ -57,4 +29,4 @@ (set! input))) (defn init [] - (get-mastodon-timeline render-to-document)) \ No newline at end of file + (api/get-mastodon-timeline mastodon-config render-to-document)) \ No newline at end of file diff --git a/src/main/dda/masto_embed/js_api.cljs b/src/main/dda/masto_embed/js_api.cljs new file mode 100644 index 0000000..84559fe --- /dev/null +++ b/src/main/dda/masto_embed/js_api.cljs @@ -0,0 +1,38 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you under the Apache License, Version 2.0 (the +; "License"); you may not use this file except in compliance +; with the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. +(ns dda.masto-embed.js-api + (:require + ["mastodon-api" :as Mastodon] + [clojure.pprint :as pprint :refer [pprint]] + [cljs.core.async :refer [go]] + [cljs.core.async.interop :refer-macros [