From db728d330fa69aa1a8c0a22e4d44dc512c50f32a Mon Sep 17 00:00:00 2001 From: jem Date: Sat, 30 May 2020 17:14:49 +0200 Subject: [PATCH] realize new auth outline --- README.md | 23 +++++++++++------------ src/main/mastodon_bot/core.cljs | 16 ++++++++-------- src/main/mastodon_bot/mastodon_api.cljs | 9 +++------ src/main/mastodon_bot/twitter_api.cljs | 11 +++++------ 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 473cfb8..43fa316 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,16 @@ If you get a [permission failure](https://github.com/anmonteiro/lumo/issues/206) with later timestamps to avoid duplicate posts. On the first run the timestamp will default to current time. ```clojure -{;; add Twitter config to mirror Twitter accounts - :twitter {:access-keys - {:consumer_key "XXXX" - :consumer_secret "XXXX" - :access_token_key "XXXX" - :access_token_secret "XXXX"}} +{:auth {;; add Twitter config to mirror Twitter accounts + :twitter {:consumer_key "XXXX" + :consumer_secret "XXXX" + :access_token_key "XXXX" + :access_token_secret "XXXX"} + :mastodon {:access_token "XXXX" + ;; account number you see when you log in and go to your profile + ;; e.g: https://mastodon.social/web/accounts/294795 + :account-id "XXXX" + :api_url "https://botsin.space/api/v1/"}} ;; add Tumblr config to mirror Tumblr accounts :tumblr {:access-keys {:consumer_key "XXXX" @@ -45,12 +49,7 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w ;; add RSS config to follow feeds :rss {"Hacker News" "https://hnrss.org/newest" "r/Clojure" "https://www.reddit.com/r/clojure/.rss"} - :mastodon {:access_token "XXXX" - ;; account number you see when you log in and go to your profile - ;; e.g: https://mastodon.social/web/accounts/294795 - :account-id "XXXX" - :api_url "https://botsin.space/api/v1/" - } + :transform [{:source {:type :twitter-source ;; optional, defaults to false :include-replies? false diff --git a/src/main/mastodon_bot/core.cljs b/src/main/mastodon_bot/core.cljs index da5bd60..d236892 100755 --- a/src/main/mastodon_bot/core.cljs +++ b/src/main/mastodon_bot/core.cljs @@ -13,22 +13,22 @@ [mastodon-bot.tumblr-api :as tumblr] [cljs.core :refer [*command-line-args*]])) -(s/def ::mastodon-auth masto/mastodon-auth?) -(s/def ::transform transform/transformations?) +(s/def ::mastodon masto/mastodon-auth?) (s/def ::twitter twitter/twitter-auth?) +(s/def ::transform transform/transformations?) (s/def ::tumblr map?) (s/def ::rss map?) +(s/def ::auth (s/keys :opt-un [::mastodon ::twitter])) +(def config? + (s/keys :req-un [::auth ::transform])) -(def config? (s/keys :req-un [::mastodon-config] - :opt-un [::twitter ::tumblr ::rss])) - -(defn-spec mastodon-auth ::mastodon-auth +(defn-spec mastodon-auth ::mastodon [config config?] - (:mastodon-config config)) + (get-in config [:auth :mastodon])) (defn-spec twitter-auth ::twitter [config config?] - (:twitter config)) + (get-in config [:auth :twitter])) (defn-spec transform ::transform [config config?] diff --git a/src/main/mastodon_bot/mastodon_api.cljs b/src/main/mastodon_bot/mastodon_api.cljs index 0678460..7d6555d 100755 --- a/src/main/mastodon_bot/mastodon_api.cljs +++ b/src/main/mastodon_bot/mastodon_api.cljs @@ -28,10 +28,7 @@ ::visibility ::append-screen-name? ::sensitive? - ::media-only? - ])) -(def mastodon-config? (s/merge mastodon-auth? mastodon-target?)) - + ::media-only?])) (defn-spec max-post-length ::max-post-length [target mastodon-target?] @@ -45,9 +42,9 @@ (infra/exit-with-error "missing Mastodon auth configuration!"))) (defn-spec delete-status any? - [mastodon-config mastodon-config? + [mastodon-auth mastodon-auth? status-id string?] - (.delete (mastodon-client mastodon-config) (str "statuses/" status-id) #js {})) + (.delete (mastodon-client mastodon-auth) (str "statuses/" status-id) #js {})) (defn post-status ([mastodon-auth target status-text] diff --git a/src/main/mastodon_bot/twitter_api.cljs b/src/main/mastodon_bot/twitter_api.cljs index 1d2e5bc..cd72bb5 100755 --- a/src/main/mastodon_bot/twitter_api.cljs +++ b/src/main/mastodon_bot/twitter_api.cljs @@ -26,12 +26,11 @@ (defn-spec twitter-client any? [twitter-auth twitter-auth?] - (let [{:keys [access-keys]} twitter-auth] - (try - (twitter. (clj->js access-keys)) - (catch js/Error e - (infra/exit-with-error - (str "failed to connect to Twitter: " (.-message e))))))) + (try + (twitter. (clj->js twitter-auth)) + (catch js/Error e + (infra/exit-with-error + (str "failed to connect to Twitter: " (.-message e)))))) (defn strip-utm [news-link] (first (string/split news-link #"\?utm")))