diff --git a/src/nuotl_twitter/processor.clj b/src/nuotl_twitter/processor.clj index 6dd0668..34d9aa2 100644 --- a/src/nuotl_twitter/processor.clj +++ b/src/nuotl_twitter/processor.clj @@ -12,20 +12,23 @@ (re-pattern (url :url)) (html-url (url :display-url) (url :expanded-url)))) +(defrecord Return [output success]) +(defrecord Output [event tweeter message]) + (defn- swap-in-urls [tweet output] (let [urls (tweet :urls)] (loop [i 0 text (:text (:event output))] (if (< i (count urls)) (recur (inc i) (fix-text text (urls i))) - {:output (assoc-in output [:event :text] text) :success true})))) + (Return. (assoc-in output [:event :text] text) true))))) (defn is-me? [tweet output] (if (= (:_id (:tweeter tweet)) (:application-id tweet)) - {:output output :success false} - {:output output :success true})) + (Return. output false) + (Return. output true))) (defn get-tweeter [tweet output] - {:output (assoc output :tweeter (:tweeter tweet)) :success true}) + (Return. (assoc output :tweeter (:tweeter tweet)) true)) (defn is-approved? [tweet output] (if (contains? @@ -33,34 +36,34 @@ (. (:name (:tweeter tweet)) toLowerCase)) {:output output :success true} (if (dao/tweeter-approved? (:_id (:tweeter tweet))) - {:output output :success true} - {:output (assoc output :message :unapproved) :success false}))) + (Return. output true) + (Return. (assoc output :message :unapproved) false)))) (defn is-mention? [tweet output] (if (= (str "@" (. (:application-screen-name tweet) toLowerCase)) (nth (clojure.string/split (:text tweet) #" ") 0)) - {:output output :success true} - {:output output :success false} + (Return. output true) + (Return. output false) )) (defn parse-tweet [tweet output] (let [parse-result (tweet-parser/parse-tweet (:text tweet))] (if (nil? (:event parse-result)) - {:output (assoc output :message (:error parse-result)) :success false} - {:output (assoc output :event (merge (:event output) (:event parse-result))) :success true}))) + (Return.(assoc output :message (:error parse-result)) false) + (Return.(assoc output :event (merge (:event output) (:event parse-result))) true)))) (defn url-present? [tweet output] (if (empty? (:urls tweet)) - {:output (merge output {:event nil :message :no-url}) :success false} - {:output output :success true})) + (Return. (merge output {:event nil :message :no-url}) false) + (Return. output true))) (defn clean-up-event [tweet output] (let [event (merge (:event output) (select-keys tweet [:_id :tags :in-response-to]))] (let [event (assoc event :tweeter (:_id (:tweeter tweet)))] - {:output (merge output {:event event :message :success}) :success true}))) + (Return. (merge output {:event event :message :success}) true)))) (def logic [ is-me? @@ -74,7 +77,7 @@ ]) (defn process-tweet [tweet] - (loop [i 0 ret {:output {:event nil :tweeter nil :message nil} :success true}] + (loop [i 0 ret (Return. {:event nil :tweeter nil :message nil} true)] (if (and (:success ret) (< i (count logic))) (recur (inc i) ((logic i) tweet (:output ret))) (:output ret))))