'Reddit.clj: clojure wrapper for Reddit API'

Tue 26 July 2011
  • ANN tags:
  • clojure
  • project
  • reddit published: true comments: false

As mentioned in Rage Viewer, I have another clojure library to communicate with Reddit. Now it's public available as "reddit.clj".

Reddit.clj is managed with leiningen. The current reddit.clj release is 0.1.3 0.2.0. You can include it in your project.clj:
[cc lang="clojure"]
(defproject xxxx "1.0.0-SNAPSHOT"
:dependencies [[reddit.clj "0.2.0"]])
[/cc]

This is a simple tutorial for you to getting started :
[cc lang="clojure"]
;; include reddit.clj
(require '[reddit.clj.core :as reddit])
;; create a reddit client with reddit/login.
;; you can also ignore the arguments to use it
;; anonymously
(def rc (reddit/login "your-reddit-name" "your-reddit-passwd"))

;; load reddits from subreddit "clojure", and print titles
(doseq
[title (map :title (reddit/reddits rc "clojure"))]
(println title))

;; enhance reddit client to enable writing, for login user only
;; this operation will retrieve reddit user modhash under the hood
(def rc (reddit/enhance rc))

;; vote-up a thing on reddit
(reddit/vote-up rc "t3_iz61z")

;; you may also submit links to reddit.
;; permalink will be returned when success.
;; be careful to use this API because reddit may ask you for a
;; captcha. But as a library, reddit.clj will return nil on this case.
;; use it at your own risk.
(reddit/submit-link rc "title" "url" "subreddit-name")

[/cc]

Detailed API documents are listed here.

This library should be useful to crawl data from reddit which is rich of information. Reddit.clj is hosted on github.