From 61746c417f09fda72bea92dc004abf7f9af59ad0 Mon Sep 17 00:00:00 2001 From: jem Date: Sat, 25 Apr 2020 13:42:54 +0200 Subject: [PATCH] use more dedicated ns --- shadow-cljs.edn | 2 +- src/main/dda/masto_embed/api.cljs | 54 +++++++++++++++++++++ src/main/dda/masto_embed/app.cljs | 66 ++++++++------------------ src/main/dda/masto_embed/js_api.cljs | 38 +++++++++++++++ src/test/dda/masto_embed/app_test.cljs | 20 ++++++-- 5 files changed, 128 insertions(+), 52 deletions(-) create mode 100644 src/main/dda/masto_embed/api.cljs create mode 100644 src/main/dda/masto_embed/js_api.cljs 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 [