Creddit
Clojure wrapper for Reddit API
Installation
Declare creddit in your project.clj:
Use creddit in your clojure code:
(require '[creddit.core :as creddit])
Usage
You will need your Reddit application credentials found here https://www.reddit.com/prefs/apps/
I would recommend using a library such as cprop or environ to load them in
Your credentials should like this:
{:user-client <USER_CLIENT>,
:user-secret <USER_SECRET>,
:username <REDDIT_USERNAME>,
:password <REDDIT_PASSWORD>}
The username and password are needed for some actions like submitting but are optional for anonymous actions.
Once you have your credentials loaded in you can initialise the client:
(def creddit-client (creddit/init credentials))
Functions
Frontpage
Retrieve posts from frontpage
limit: Maximum number of posts to retrieve (Minimum: 1, Maximum: 100)
time: Time span of query (One of :hour, :day, :week, :month, :year, :all)
(creddit/frontpage creddit-client limit time)
(creddit/controversial creddit-client limit time)
(creddit/new creddit-client limit time)
(creddit/rising creddit-client limit time)
(creddit/top creddit-client limit time)
Subreddit
Retrieve posts from subreddit
subreddit: Name of subreddit (Eg: "programming", "funny", "pics" etc...)
limit: Maximum number of posts to retrieve (Minimum: 1, Maximum: 100)
time: Time span of query (One of :hour, :day, :week, :month, :year, :all)
(creddit/subreddit creddit-client subreddit limit time)
(creddit/subreddit-controversial creddit-client subreddit limit time)
(creddit/subreddit-new creddit-client subreddit limit time)
(creddit/subreddit-rising creddit-client subreddit limit time)
(creddit/subreddit-top creddit-client subreddit limit time)
Retrieve recent comments from subreddit
subreddit: Name of subreddit (Eg: "programming", "funny", "pics" etc...)
limit: Maximum number of comments to retrieve (Minimum: 1, Maximum: 100)
time: Time span of query (One of :hour, :day, :week, :month, :year, :all)
commentId: ID without fullname prefix of the comment you would like to search from.
(creddit/subreddit-comments creddit-client subreddit limit)
(creddit/subreddit-comments-after creddit-client subreddit commentId limit time)
(creddit/subreddit-comments-before creddit-client subreddit commentId limit time)
Search subreddit's posts
subreddit: Name of subreddit (Eg: "programming", "funny", "pics" etc...)
query: Search term (Eg: "clojure tutorials", "dank memes" etc...)
limit: Maximum number of posts to retrieve (Minimum: 1, Maximum: 100)
(creddit/subreddit-search creddit-client subreddit query limit)
Retrieve about from subreddit
subreddit: Name of subreddit (Eg: "programming", "funny", "pics" etc...)
(creddit/subreddit-about creddit-client subreddit)
Retrieve moderators of a subreddit
subreddit: Name of subreddit (Eg: "programming", "funny", "pics" etc...)
(creddit/subreddit-moderators creddit-client subreddit)
Subreddits
Retrieve list of subreddits
limit: Maximum number of subreddits to retrieve (Minimum: 1, Maximum: 100)
(creddit/subreddits creddit-client limit)
(creddit/subreddits-new creddit-client limit)
(creddit/subreddits-popular creddit-client limit)
(creddit/subreddits-gold creddit-client limit)
(creddit/subreddits-default creddit-client limit)
Search for subreddit
subreddit: Subreddit search term (Eg: "programming", "clojure", "nodejs" etc...)
limit: Maximum number of subreddits to retrieve (Minimum: 1, Maximum: 100)
(creddit/subreddits-search creddit-client subreddit limit)
User
Retrieve user profile
username: Name of user (Eg: "thisisbillgates", "awildsketchappeared", "way_fairer" etc...)
(creddit/user creddit-client username)
(creddit/user-trophies creddit-client username)
Retrieve user posts
username: Name of user (Eg: "thisisbillgates", "awildsketchappeared", "way_fairer" etc...)
limit: Maximum number of posts to retrieve (Minimum: 1, Maximum: 100)
time: Time span of query (One of :hour, :day, :week, :month, :year, :all)
postId: ID without fullname prefix of the post you would like to search from.
(creddit/user-posts creddit-client username limit time)
(creddit/user-posts-after creddit-client username postId limit time)
(creddit/user-posts-before creddit-client username postId limit time)
Retrieve user comments
username: Name of user (Eg: "thisisbillgates", "awildsketchappeared", "way_fairer" etc...)
limit: Maximum number of posts to retrieve (Minimum: 1, Maximum: 100)
time: Time span of query (One of :hour, :day, :week, :month, :year, :all)
commentId: ID without fullname prefix of the comment you would like to search from.
(creddit/user-comments creddit-client username limit time)
(creddit/user-comments-after creddit-client username commentId limit time)
(creddit/user-comments-before creddit-client username commentId limit time)
Users
Retrieve users
limit: Maximum number of users to retrieve (Minimum: 1, Maximum: 100)
(creddit/users creddit-client limit)
(creddit/users-new creddit-client limit)
(creddit/users-popular creddit-client limit)
Listings
Retrieve specific posts
names: Sequence of fully specified fullnames.
(creddit/listing creddit-client names)
Submitting
Submit self or link posts
subreddit: Name of subreddit (Eg: "programming", "funny", "pics" etc...)
kind: "self" or "link" (image uploads are not supported)
title: Title for the post (Eg: "test post please ignore")
content: Text for self posts or url for link posts
(creddit/submit creddit-client subreddit kind title content)
Development
Testing
Run tests
$ lein test
Contributing
Want to become a Creddit contributor?
Then checkout our code of conduct and contributing guidelines.
Copyright & License
Copyright (c) 2017 Conor Hughes - Released under the MIT license.