Permalink
Browse files

add functions to get karma from social services

  • Loading branch information...
1 parent a695415 commit b576075b6faf802a0a5f006a3a39b19182f889d0 @sunng87 committed Feb 25, 2012
Showing with 58 additions and 1 deletion.
  1. +0 −1 project.clj
  2. +58 −0 src/karmalet/social.clj
View
@@ -2,7 +2,6 @@
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]
[compojure "1.0.1"]
- [reddit.clj "0.3.3"]
[clj-http "0.3.2"]
[korma "0.3.0-beta4"]
[com.rabbitmq/amqp-client "2.7.1"]
View
@@ -0,0 +1,58 @@
+(ns karmalet.social
+ (:require [clj-http.client :as client]))
+
+(defn- get-json [url]
+ (let [resp (client/get url {:as :json} )]
+ (if (= 200 (:status resp))
+ (:body resp)
+ nil)))
+
+(defn- get-page [url]
+ (let [resp (client/get url)]
+ (if (= 200 (:status resp))
+ (:body resp)
+ nil)))
+
+(defmacro defsocial [fn-name url-pattern callback]
+ `(defn ~fn-name [userid#]
+ (let [url# (format ~url-pattern userid#)
+ resp# (get-json url#)]
+ (if-not (nil? resp#)
+ (~callback resp#)))))
+
+(defsocial reddit-karma
+ "http://www.reddit.com/user/%s/about.json"
+ (fn [r]
+ (-> r
+ :data
+ :link_karma)))
+
+(defsocial twitter-followers
+ "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=%s&count=1"
+ (fn [r]
+ (-> r
+ first
+ :user
+ :followers_count)))
+
+(defsocial github-followers
+ "https://api.github.com/users/%s"
+ (fn [r]
+ (-> r
+ :followers)))
+
+(defsocial stackoverflow-karma
+ "http://api.stackoverflow.com/1.1/users/%s"
+ (fn [r]
+ (-> r
+ :users
+ first
+ :reputation)))
+
+(defsocial hackernews-karma
+ "http://api.ihackernews.com/profile/%s"
+ (fn [r]
+ (-> r
+ :karma)))
+
+

0 comments on commit b576075

Please sign in to comment.