module Facebook.Object.Action
( createAction
, Action(..)
) where
import Control.Arrow (first)
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.Function (on)
import Data.String (IsString(..))
import Data.Text (Text)
import qualified Data.Conduit as C
import Facebook.Types
import Facebook.Monad
import Facebook.Graph
createAction :: (C.MonadResource m, MonadBaseControl IO m) =>
Action
-> [Argument]
-> Maybe AppAccessToken
-> UserAccessToken
-> FacebookT Auth m Id
createAction (Action action) query mapptoken usertoken = do
creds <- getCreds
let post :: (C.MonadResource m, MonadBaseControl IO m) => Text -> AccessToken anyKind -> FacebookT Auth m Id
post prepath = postObject (prepath <> appName creds <> ":" <> action) query
case mapptoken of
Nothing -> post "/me/" usertoken
Just apptoken -> post ("/" <> idCode (accessTokenUserId usertoken) <> "/") apptoken
newtype Action = Action { unAction :: Text }
instance Show Action where
show = show . unAction
instance Eq Action where
(==) = (==) `on` unAction
(/=) = (/=) `on` unAction
instance Ord Action where
compare = compare `on` unAction
(<=) = (<=) `on` unAction
(<) = (<) `on` unAction
(>=) = (>=) `on` unAction
(>) = (>) `on` unAction
instance Read Action where
readsPrec = (fmap (first Action) .) . readsPrec
instance IsString Action where
fromString = Action . fromString