use more dedicated ns

This commit is contained in:
jem 2020-04-25 13:42:54 +02:00
parent 73b739e594
commit 61746c417f
5 changed files with 128 additions and 52 deletions

View file

@ -5,7 +5,7 @@
"src/test"]
:dependencies
[]
[[orchestra "2018.12.06-2"]]
:dev-http {8080 "public"}
:builds
{:test

View file

@ -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 [<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))
(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 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)))))

View file

@ -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 [<p!]]))
(defn get-content-seq [response]
(map
#(aget % "content")
(array-seq
(aget response "data"))))
(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"
id-config (js-obj "id" "2")
result (go
(let [response (<p! (.get masto rest-endpoint id-config))]
(get-content-seq response)))]
(pprint result)
result))
(defn add-one [a]
(+ 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))
[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))
(api/get-mastodon-timeline mastodon-config render-to-document))

View file

@ -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 [<p!]]))
(defn get-content-seq [response]
(map
#(aget % "content")
(array-seq
(aget response "data"))))
(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"
id-config (js-obj "id" "2")
result (go
(let [response (<p! (.get masto rest-endpoint id-config))]
(get-content-seq response)))]
(pprint result)
result))

View file

@ -1,8 +1,20 @@
; 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-test
(:require
[cljs.test :refer (deftest is)]
[dda.masto-embed.app :as sut]))
(deftest a-failing-test
(is (= 3
(sut/add-one 2))))