Created
October 30, 2014 09:17
-
-
Save realyze/2c3bbf0f8625bf28b40e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns slack-nag.core | |
(:require [clj-http.client :as client] | |
[hiccup.util] | |
[clojure.data.json :as json]) | |
(:gen-class)) | |
;; RB env vars | |
(def ^:private rb-url (delay (System/getenv "RB_URL"))) | |
(def ^:private rb-user (delay (System/getenv "RB_USER"))) | |
(def ^:private rb-password (delay (System/getenv "RB_PASSWORD"))) | |
;; Slack env vars | |
(def ^:private slack-token (delay (System/getenv "SLACK_TOKEN"))) | |
(def ^:const slack-api-base-url "https://slack.com/api") | |
;; RB session id needs to be updated every now and then (it expires). | |
(def rb-session-id (atom nil)) | |
(def cs (clj-http.cookies/cookie-store)) | |
(defn get-slack-users | |
"Returns JSON list of slack users." | |
[] | |
(hiccup.util/with-base-url slack-api-base-url | |
(let [url-with-qs (hiccup.util/url "/users.list" {:token @slack-token})] | |
(client/get (hiccup.util/to-str url-with-qs) | |
{:content-type :json | |
:throw-exceptions false | |
:as :json})))) | |
(defn get-rb-sessionid | |
[] | |
(let [url (hiccup.util/url @rb-url "/api/review-requests/")] | |
(client/get (hiccup.util/to-str url) | |
{:throw-exceptions false | |
:cookie-store cs | |
:basic-auth [@rb-url @rb-password]}) | |
(:value (get (clj-http.cookies/get-cookies cs) "rbsessionid")) | |
)) | |
(defn get-review-requests | |
[] | |
(hiccup.util/with-base-url @rb-url | |
(let [url (hiccup.util/url "/api/review-requests/")] | |
(client/get (hiccup.util/to-str url) | |
{:cookies {:rbsessionid {:value @rb-session-id}} | |
:throw-exceptions false | |
})))) | |
(defn -main | |
"I don't do a whole lot ... yet." | |
[& args] | |
(do | |
(reset! rb-session-id (get-rb-sessionid)) | |
(println @rb-session-id) | |
(println (get-review-requests)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment