realize new auth outline

This commit is contained in:
jem 2020-05-30 17:14:49 +02:00
parent 9c525deb9d
commit db728d330f
4 changed files with 27 additions and 32 deletions

View file

@ -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"
{:auth {;; add Twitter config to mirror Twitter accounts
:twitter {:consumer_key "XXXX"
:consumer_secret "XXXX"
:access_token_key "XXXX"
:access_token_secret "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

View file

@ -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?]

View file

@ -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]

View file

@ -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))
(twitter. (clj->js twitter-auth))
(catch js/Error e
(infra/exit-with-error
(str "failed to connect to Twitter: " (.-message e)))))))
(str "failed to connect to Twitter: " (.-message e))))))
(defn strip-utm [news-link]
(first (string/split news-link #"\?utm")))