Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
lzwjava committed Aug 16, 2014
1 parent cf9b173 commit 6b217eb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
4 changes: 3 additions & 1 deletion project.clj
Expand Up @@ -3,4 +3,6 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]])
:dependencies [[org.clojure/clojure "1.6.0"]
[http-kit "2.1.18"]
[cheshire "5.3.1"]])
21 changes: 16 additions & 5 deletions src/clj_slack/core.clj
@@ -1,6 +1,17 @@
(ns clj-slack.core)
(ns clj-slack.core
(:use [cheshire.core])
(:require [org.httpkit.client :as http]))

(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
(defn remove-nil [& params]
(let [map (apply hash-map params)]
(into {} (filter second map))))

(defn create-link
[link text]
(format "<%s|%s>" link text))

(defn send-msg [url text & {:keys [username icon_url icon_emoji]}]
(let [map (remove-nil :text text :username username :icon_url icon_url :icon_emoji icon_emoji)]
(let [options {:timeout 15000
:body (generate-string map)}]
(= (:status @(http/post url options)) 200))))
10 changes: 7 additions & 3 deletions test/clj_slack/core_test.clj
Expand Up @@ -2,6 +2,10 @@
(:require [clojure.test :refer :all]
[clj-slack.core :refer :all]))

(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
(def slackUrl "")

(deftest send-msg-test
(testing "send-msg"
(let [text (str "There's sth new!\n" (create-link "http://www.baidu.com" "Click here!"))
res (send-msg slackUrl text :username "lzwjava" :icon_emoji ":ghost:")]
(is res true))))

0 comments on commit 6b217eb

Please sign in to comment.