reddit-0.3.0.0: Library for interfacing with Reddit's API
Safe HaskellNone
LanguageHaskell2010

Reddit

Contents

Description

This module should be most of what you need to operate the library. It exports functionality for running built RedditT actions, as well as re-exporting a few helpful types from around the library. Not every type is exported, however, due to clashing record fields. It's recommended to import modules from Reddit.Types.* qualified so that you can use all the record fields without having to deal with ambiguous functions.

Synopsis

Documentation

runReddit :: MonadIO m => Text -> Text -> ClientParams -> RedditT m a -> m (Either (APIError RedditError) a) Source #

Run a Reddit action (or a RedditT transformer action). This uses the default logged-in settings for RedditOptions: rate limiting enabled, default manager, login via username and password, and the default user-agent. You should change the user agent if you're making anything more complex than a basic script, since Reddit's API policy says that you should have a uniquely identifiable user agent.

runRedditAnon :: MonadIO m => RedditT m a -> m (Either (APIError RedditError) a) Source #

Run a Reddit action (or a RedditT transformer action). This uses the default logged-out settings, so you won't be able to do anything that requires authentication (like checking messages or making a post). At the moment, authentication isn't statically checked, so it'll return a runtime error if you try to do anything you don't have permissions for.

runRedditWith :: MonadIO m => RedditOptions -> RedditT m a -> m (Either (APIError RedditError) a) Source #

Run a Reddit or RedditT action with custom settings. You probably won't need this function for most things, but it's handy if you want to persist a connection over multiple Reddit sessions or use a custom user agent string.

runResumeRedditWith :: MonadIO m => RedditOptions -> RedditT m a -> m (Either (APIError RedditError, Maybe (RedditT m a)) a) Source #

Run a Reddit or RedditT action with custom settings. You probably won't need this function for most things, but it's handy if you want to persist a connection over multiple Reddit sessions or use a custom user agent string.

interpretIO :: MonadIO m => RedditState -> RedditT m a -> m (Either (APIError RedditError, Maybe (RedditT m a)) a) Source #

data RedditOptions Source #

Options for how we should run the Reddit action.

Instances

Instances details
Default RedditOptions Source # 
Instance details

Defined in Reddit

Methods

def :: RedditOptions #

defaultRedditOptions :: RedditOptions Source #

The default set of options

data LoginMethod Source #

Should we log in to Reddit? If so, should we use a stored set of credentials or get a new fresh set?

Constructors

Anonymous

Don't login, instead use an anonymous account

Credentials Text Text ClientParams

Login using the specified username and password

StoredDetails LoginDetails

Login using a stored set of credentials. Usually the best way to get these is to do runRedditAnon $ login user pass.

Instances

Instances details
Show LoginMethod Source # 
Instance details

Defined in Reddit

Default LoginMethod Source # 
Instance details

Defined in Reddit

Methods

def :: LoginMethod #

Re-exports

data APIError a #

Error type for the API, where a is the type that should be returned when something goes wrong on the other end - i.e. any error that isn't directly related to this library.

Constructors

APIError a

A type that represents any error that happens on the API end. Define your own custom type with a FromJSON instance if you want to handle them, or you can use () if you just want to ignore them all.

HTTPError HttpException

Something went wrong when we tried to do a HTTP operation.

InvalidURLError

You're trying to create an invalid URL somewhere - check your Builder's base URL and your Routes.

ParseError String

Failed when parsing the response, and it wasn't an error on their end.

EmptyError

Empty error to serve as a zero element for Monoid.

Instances

Instances details
Eq a => Eq (APIError a) 
Instance details

Defined in Network.API.Builder.Error

Methods

(==) :: APIError a -> APIError a -> Bool #

(/=) :: APIError a -> APIError a -> Bool #

Show a => Show (APIError a) 
Instance details

Defined in Network.API.Builder.Error

Methods

showsPrec :: Int -> APIError a -> ShowS #

show :: APIError a -> String #

showList :: [APIError a] -> ShowS #

Semigroup (APIError a) 
Instance details

Defined in Network.API.Builder.Error

Methods

(<>) :: APIError a -> APIError a -> APIError a #

sconcat :: NonEmpty (APIError a) -> APIError a #

stimes :: Integral b => b -> APIError a -> APIError a #

Monoid (APIError a) 
Instance details

Defined in Network.API.Builder.Error

Methods

mempty :: APIError a #

mappend :: APIError a -> APIError a -> APIError a #

mconcat :: [APIError a] -> APIError a #

newtype POSTWrapped a Source #

Constructors

POSTWrapped a 

Instances

Instances details
Functor POSTWrapped Source # 
Instance details

Defined in Reddit.Types.Reddit

Methods

fmap :: (a -> b) -> POSTWrapped a -> POSTWrapped b #

(<$) :: a -> POSTWrapped b -> POSTWrapped a #

Eq a => Eq (POSTWrapped a) Source # 
Instance details

Defined in Reddit.Types.Reddit

Read a => Read (POSTWrapped a) Source # 
Instance details

Defined in Reddit.Types.Reddit

Show a => Show (POSTWrapped a) Source # 
Instance details

Defined in Reddit.Types.Reddit

FromJSON (POSTWrapped [CommentReference]) Source # 
Instance details

Defined in Reddit.Types.Comment

FromJSON (POSTWrapped CaptchaID) Source # 
Instance details

Defined in Reddit.Types.Captcha

FromJSON (POSTWrapped PostID) Source # 
Instance details

Defined in Reddit.Types.Post

FromJSON (POSTWrapped Comment) Source # 
Instance details

Defined in Reddit.Types.Comment

FromJSON (POSTWrapped CommentID) Source # 
Instance details

Defined in Reddit.Types.Comment

FromJSON (POSTWrapped MessageID) Source # 
Instance details

Defined in Reddit.Types.Message

newtype Modhash Source #

Constructors

Modhash Text 

Instances

Instances details
Eq Modhash Source # 
Instance details

Defined in Reddit.Types.Reddit

Methods

(==) :: Modhash -> Modhash -> Bool #

(/=) :: Modhash -> Modhash -> Bool #

Read Modhash Source # 
Instance details

Defined in Reddit.Types.Reddit

Show Modhash Source # 
Instance details

Defined in Reddit.Types.Reddit

FromJSON Modhash Source # 
Instance details

Defined in Reddit.Types.Reddit

newtype RedditT m a Source #

Constructors

RedditT (FreeT (RedditF m) m a) 

Instances

Instances details
MonadTrans RedditT Source # 
Instance details

Defined in Reddit.Types.Reddit

Methods

lift :: Monad m => m a -> RedditT m a #

Monad m => Monad (RedditT m) Source # 
Instance details

Defined in Reddit.Types.Reddit

Methods

(>>=) :: RedditT m a -> (a -> RedditT m b) -> RedditT m b #

(>>) :: RedditT m a -> RedditT m b -> RedditT m b #

return :: a -> RedditT m a #

Monad m => Functor (RedditT m) Source # 
Instance details

Defined in Reddit.Types.Reddit

Methods

fmap :: (a -> b) -> RedditT m a -> RedditT m b #

(<$) :: a -> RedditT m b -> RedditT m a #

Monad m => Applicative (RedditT m) Source # 
Instance details

Defined in Reddit.Types.Reddit

Methods

pure :: a -> RedditT m a #

(<*>) :: RedditT m (a -> b) -> RedditT m a -> RedditT m b #

liftA2 :: (a -> b -> c) -> RedditT m a -> RedditT m b -> RedditT m c #

(*>) :: RedditT m a -> RedditT m b -> RedditT m b #

(<*) :: RedditT m a -> RedditT m b -> RedditT m a #

MonadIO m => MonadIO (RedditT m) Source # 
Instance details

Defined in Reddit.Types.Reddit

Methods

liftIO :: IO a -> RedditT m a #

data RedditF m a where Source #

Constructors

FailWith :: APIError RedditError -> RedditF m a 
Nest :: RedditT m b -> (Either (APIError RedditError) b -> a) -> RedditF m a 
NestResuming :: RedditT m b -> (Either (APIError RedditError, Maybe (RedditT m b)) b -> a) -> RedditF m a 
ReceiveRoute :: Receivable b => Route -> (b -> a) -> RedditF m a 
RunRoute :: FromJSON b => Route -> (b -> a) -> RedditF m a 
WithBaseURL :: Text -> RedditT m b -> (b -> a) -> RedditF m a 
WithHeaders :: ([Header] -> [Header]) -> RedditT m b -> (b -> a) -> RedditF m a 

Instances

Instances details
Functor (RedditF m) Source # 
Instance details

Defined in Reddit.Types.Reddit

Methods

fmap :: (a -> b) -> RedditF m a -> RedditF m b #

(<$) :: a -> RedditF m b -> RedditF m a #

type Reddit a = RedditT IO a Source #

withBaseURL :: Monad m => Text -> RedditT m a -> RedditT m a Source #

withHeaders :: Monad m => ([Header] -> [Header]) -> RedditT m a -> RedditT m a Source #