module Web.Twitter.Conduit.Cursor
( CursorKey (..)
, IdsCursorKey
, UsersCursorKey
, ListsCursorKey
, WithCursor (..)
) where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
import Data.Monoid
#endif
import Data.Aeson
import Data.Text (Text)
import Web.Twitter.Types (checkError)
class CursorKey a where
cursorKey :: a -> Text
data IdsCursorKey
instance CursorKey IdsCursorKey where
cursorKey = const "ids"
data UsersCursorKey
instance CursorKey UsersCursorKey where
cursorKey = const "users"
data ListsCursorKey
instance CursorKey ListsCursorKey where
cursorKey = const "lists"
#if __GLASGOW_HASKELL__ >= 706
#endif
data WithCursor cursorKey wrapped = WithCursor
{ previousCursor :: Integer
, nextCursor :: Integer
, contents :: [wrapped]
} deriving Show
instance (FromJSON wrapped, CursorKey c) =>
FromJSON (WithCursor c wrapped) where
parseJSON (Object o) = checkError o >>
WithCursor <$> o .: "previous_cursor"
<*> o .: "next_cursor"
<*> o .: cursorKey (undefined :: c)
parseJSON _ = mempty