The reddit package

[Tags:bsd2, library, test]

A library for interfacing with Reddit's API in Haskell. Handles logins, rate-limiting and converting to and from JSON responses. Supports most user-facing Reddit API functions, as well as some moderator endpoints. Check out the readme at Contributions are welcome.

[Skip to Readme]


Dependencies aeson (==0.9.*), api-builder (>=0.10 && <0.12), base (>=4.6 && <4.9), bytestring (==0.10.*), data-default-class (==0.0.1), free (==4.*), http-client (>=0.4.11 && <0.4.21), http-client-tls (>=0.2 && <0.2.3), http-types (==0.8.*), network (==2.6.*), text (==1.*), time (==1.5.*), transformers (==0.4.*), unordered-containers (==0.2.5.*), vector (>=0.10 && <0.12) [details]
License BSD2
Copyright Copyright (c) Fraser Murray, 2013-2015
Author Fraser Murray
Category Network
Home page
Source repository head: git clone
Uploaded Fri Aug 21 11:53:52 UTC 2015 by Intolerable
Distributions NixOS:
Downloads 382 total (6 in the last 30 days)
0 []
Status Docs available [build log]
Last success reported on 2015-08-21 [all 1 reports]
Hackage Matrix CI




Maintainer's Corner

For package maintainers and hackage trustees

Readme for reddit

Readme for reddit-

reddit for haskell Build Status

A Haskell library for interacting with the Reddit API.

### A couple of examples

Let's get all the posts from the frontpage of Reddit and write a summary of each of them to the console:

{-# LANGUAGE OverloadedStrings #-}
import Reddit
import Reddit.Types.Post

import Control.Monad
import Control.Monad.IO.Class
import Data.Monoid
import qualified Data.Text as Text
import qualified Data.Text.IO as Text

main = runRedditAnon $ do
  Listing _ _ posts <- getPosts
  forM_ posts $ \post -> do
    liftIO $ Text.putStrLn $
       "[" <> tshow (score post) <> "] " <>
       title post <> " (" <> tshow (subreddit post) <> ")"

tshow = Text.pack . show

Let's check to see which of a group of users has the highest link karma:

{-# LANGUAGE OverloadedStrings #-}
import Reddit
import Reddit.Types.User

import Data.List
import Data.Ord

usersToCheck = ["nikita-volkov", "simonmar", "bos", "roche"]

main = runRedditAnon $ do
  infos <- mapM (getUserInfo . Username) usersToCheck
  return $ maximumBy (comparing linkKarma) infos


Pure tests

cabal test test

This suite will only run test that don't require doing any IO. Helpful because it runs quickly and isn't subject to any network problems.

Anonymous tests

cabal test test-anon

There's also a suite of tests that can be run anonymously without having to set up a user account and an empty subreddit.

Full IO tests

cabal test test-io

The test test suite will run the tests that don't rely on doing any IO, but the test-io should be used too to ensure that IO functions do what they're supposed to do. If you want to run the IO suite, add a file test.cfg to the reddit/ directory, containing (one field per line):

  • a reddit username
  • a reddit password
  • a subreddit name (the user should be a moderator for the subredit)