{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
module Network.Reddit.Multireddit
(
getMultireddit
, addToMultireddit
, removeFromMultireddit
, deleteMultireddit
, copyMultireddit
, createMultireddit
, updateMultireddit
, listFilters
, addFilter
, removeFilter
, clearFilters
, module M
) where
import Data.Aeson ( KeyValue((.=)) )
import Data.Foldable ( traverse_ )
import Network.Reddit.Internal
import Network.Reddit.Me
import Network.Reddit.Types
import Network.Reddit.Types.Account
import Network.Reddit.Types.Multireddit
import Network.Reddit.Types.Multireddit as M
( MultiName
, MultiPath(MultiPath)
, MultiUpdate
, MultiVisibility(..)
, Multireddit(Multireddit)
, NewMulti
, NewMultiF(NewMultiF)
, defaultMultiUpdate
, mkMultiName
, multiUpdate
)
import Network.Reddit.Types.Subreddit
import Network.Reddit.Utils
import Web.HttpApiData ( ToHttpApiData(..) )
getMultireddit :: MonadReddit m => MultiPath -> m Multireddit
getMultireddit :: MultiPath -> m Multireddit
getMultireddit MultiPath
mpath =
APIAction Multireddit -> m Multireddit
forall a (m :: * -> *).
(MonadReddit m, FromJSON a) =>
APIAction a -> m a
runAction APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments = [ PathSegment
"api", PathSegment
"multi", MultiPath -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece MultiPath
mpath ] }
addToMultireddit :: MonadReddit m => MultiPath -> SubredditName -> m ()
addToMultireddit :: MultiPath -> SubredditName -> m ()
addToMultireddit MultiPath
mpath SubredditName
sname =
APIAction () -> m ()
forall (m :: * -> *). MonadReddit m => APIAction () -> m ()
runAction_ APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments = [ PathSegment
"api"
, PathSegment
"multi"
, MultiPath -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece MultiPath
mpath
, PathSegment
"r"
, SubredditName -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece SubredditName
sname
]
, $sel:method:APIAction :: Method
method = Method
PUT
, $sel:requestData:APIAction :: WithData
requestData =
[(PathSegment, PathSegment)] -> WithData
mkTextFormData [ ( PathSegment
"model"
, [Pair] -> PathSegment
textObject [ PathSegment
"name" PathSegment -> SubredditName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => PathSegment -> v -> kv
.= SubredditName
sname ]
)
]
}
removeFromMultireddit :: MonadReddit m => MultiPath -> SubredditName -> m ()
removeFromMultireddit :: MultiPath -> SubredditName -> m ()
removeFromMultireddit MultiPath
mpath SubredditName
sname =
APIAction () -> m ()
forall (m :: * -> *). MonadReddit m => APIAction () -> m ()
runAction_ APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments = [ PathSegment
"api"
, PathSegment
"multi"
, MultiPath -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece MultiPath
mpath
, PathSegment
"r"
, SubredditName -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece SubredditName
sname
]
, $sel:method:APIAction :: Method
method = Method
DELETE
}
deleteMultireddit :: MonadReddit m => MultiPath -> m ()
deleteMultireddit :: MultiPath -> m ()
deleteMultireddit MultiPath
mpath =
APIAction () -> m ()
forall (m :: * -> *). MonadReddit m => APIAction () -> m ()
runAction_ APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments = [ PathSegment
"api", PathSegment
"multi", MultiPath -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece MultiPath
mpath ]
, $sel:method:APIAction :: Method
method = Method
DELETE
}
copyMultireddit :: MonadReddit m => MultiPath -> MultiName -> m Multireddit
copyMultireddit :: MultiPath -> MultiName -> m Multireddit
copyMultireddit MultiPath
mpath MultiName
mname = do
Account { Username
$sel:username:Account :: Account -> Username
username :: Username
username } <- m Account
forall (m :: * -> *). MonadReddit m => m Account
getMe
APIAction Multireddit -> m Multireddit
forall a (m :: * -> *).
(MonadReddit m, FromJSON a) =>
APIAction a -> m a
runAction APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments = [ PathSegment
"api", PathSegment
"multi", PathSegment
"copy" ]
, $sel:method:APIAction :: Method
method = Method
POST
, $sel:requestData:APIAction :: WithData
requestData =
[(PathSegment, PathSegment)] -> WithData
mkTextFormData [ ( PathSegment
"to"
, MultiPath -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toQueryParam (MultiPath -> PathSegment) -> MultiPath -> PathSegment
forall a b. (a -> b) -> a -> b
$ Username -> MultiName -> MultiPath
MultiPath Username
username MultiName
mname
)
, (PathSegment
"from", MultiPath -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toQueryParam MultiPath
mpath)
, (PathSegment
"display_name", MultiName -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toQueryParam MultiName
mname)
]
}
createMultireddit :: MonadReddit m => NewMulti -> MultiPath -> m Multireddit
createMultireddit :: NewMulti -> MultiPath -> m Multireddit
createMultireddit NewMulti
newm MultiPath
mpath =
APIAction Multireddit -> m Multireddit
forall a (m :: * -> *).
(MonadReddit m, FromJSON a) =>
APIAction a -> m a
runAction APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments = [ PathSegment
"api", PathSegment
"multi", MultiPath -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece MultiPath
mpath ]
, $sel:method:APIAction :: Method
method = Method
POST
, $sel:requestData:APIAction :: WithData
requestData = [(PathSegment, PathSegment)] -> WithData
mkTextFormData [ (PathSegment
"model", NewMulti -> PathSegment
forall a. ToJSON a => a -> PathSegment
textEncode NewMulti
newm) ]
}
updateMultireddit
:: MonadReddit m => MultiUpdate -> MultiPath -> m Multireddit
updateMultireddit :: MultiUpdate -> MultiPath -> m Multireddit
updateMultireddit MultiUpdate
mupd MultiPath
mpath =
APIAction Multireddit -> m Multireddit
forall a (m :: * -> *).
(MonadReddit m, FromJSON a) =>
APIAction a -> m a
runAction APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments = [ PathSegment
"api", PathSegment
"multi", MultiPath -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece MultiPath
mpath ]
, $sel:method:APIAction :: Method
method = Method
PUT
, $sel:requestData:APIAction :: WithData
requestData = [(PathSegment, PathSegment)] -> WithData
mkTextFormData [ (PathSegment
"model", MultiUpdate -> PathSegment
forall a. ToJSON a => a -> PathSegment
textEncode MultiUpdate
mupd) ]
}
listFilters :: MonadReddit m => SubredditName -> m Multireddit
listFilters :: SubredditName -> m Multireddit
listFilters SubredditName
special = do
Account { Username
username :: Username
$sel:username:Account :: Account -> Username
username } <- m Account
forall (m :: * -> *). MonadReddit m => m Account
getMe
APIAction Multireddit -> m Multireddit
forall a (m :: * -> *).
(MonadReddit m, FromJSON a) =>
APIAction a -> m a
runAction APIAction Any
forall a. APIAction a
defaultAPIAction { $sel:pathSegments:APIAction :: [PathSegment]
pathSegments = Username -> SubredditName -> [PathSegment]
filterPath Username
username SubredditName
special }
addFilter :: MonadReddit m
=> SubredditName
-> SubredditName
-> m ()
addFilter :: SubredditName -> SubredditName -> m ()
addFilter SubredditName
special SubredditName
sname = do
Account { Username
username :: Username
$sel:username:Account :: Account -> Username
username } <- m Account
forall (m :: * -> *). MonadReddit m => m Account
getMe
APIAction () -> m ()
forall (m :: * -> *). MonadReddit m => APIAction () -> m ()
runAction_ APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments =
Username -> SubredditName -> [PathSegment]
filterPath Username
username SubredditName
special [PathSegment] -> [PathSegment] -> [PathSegment]
forall a. Semigroup a => a -> a -> a
<> [ PathSegment
"r", SubredditName -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece SubredditName
sname ]
, $sel:method:APIAction :: Method
method = Method
PUT
, $sel:requestData:APIAction :: WithData
requestData =
[(PathSegment, PathSegment)] -> WithData
mkTextFormData [ ( PathSegment
"model"
, [Pair] -> PathSegment
textObject [ PathSegment
"name" PathSegment -> SubredditName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => PathSegment -> v -> kv
.= SubredditName
sname ]
)
]
}
removeFilter :: MonadReddit m
=> SubredditName
-> SubredditName
-> m ()
removeFilter :: SubredditName -> SubredditName -> m ()
removeFilter SubredditName
special SubredditName
sname = do
Account { Username
username :: Username
$sel:username:Account :: Account -> Username
username } <- m Account
forall (m :: * -> *). MonadReddit m => m Account
getMe
APIAction () -> m ()
forall (m :: * -> *). MonadReddit m => APIAction () -> m ()
runAction_ APIAction Any
forall a. APIAction a
defaultAPIAction
{ $sel:pathSegments:APIAction :: [PathSegment]
pathSegments =
Username -> SubredditName -> [PathSegment]
filterPath Username
username SubredditName
special [PathSegment] -> [PathSegment] -> [PathSegment]
forall a. Semigroup a => a -> a -> a
<> [ PathSegment
"r", SubredditName -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece SubredditName
sname ]
, $sel:method:APIAction :: Method
method = Method
DELETE
}
clearFilters :: MonadReddit m => SubredditName -> m ()
clearFilters :: SubredditName -> m ()
clearFilters SubredditName
special = do
Multireddit { Seq SubredditName
$sel:subreddits:Multireddit :: Multireddit -> Seq SubredditName
subreddits :: Seq SubredditName
subreddits } <- SubredditName -> m Multireddit
forall (m :: * -> *).
MonadReddit m =>
SubredditName -> m Multireddit
listFilters SubredditName
special
(SubredditName -> m ()) -> Seq SubredditName -> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (SubredditName -> SubredditName -> m ()
forall (m :: * -> *).
MonadReddit m =>
SubredditName -> SubredditName -> m ()
removeFilter SubredditName
special) Seq SubredditName
subreddits
filterPath :: Username -> SubredditName -> [PathSegment]
filterPath :: Username -> SubredditName -> [PathSegment]
filterPath Username
uname SubredditName
sname =
[ PathSegment
"api", PathSegment
"filter", PathSegment
"user", Username -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece Username
uname, PathSegment
"f", SubredditName -> PathSegment
forall a. ToHttpApiData a => a -> PathSegment
toUrlPiece SubredditName
sname ]