module Network.Nakadi.EventTypes.CursorDistances
( cursorsDistance'
, cursorsDistanceR'
, cursorDistance
, cursorDistanceR
) where
import Network.Nakadi.Internal.Prelude
import Control.Lens
import Network.Nakadi.Internal.Http
import qualified Network.Nakadi.Internal.Lenses as L
path :: EventTypeName -> ByteString
path eventTypeName =
"/event-types/"
<> encodeUtf8 (unEventTypeName eventTypeName)
<> "/cursor-distances"
cursorsDistance' ::
MonadNakadi m
=> Config
-> EventTypeName
-> [CursorDistanceQuery]
-> m [CursorDistanceResult]
cursorsDistance' config eventTypeName cursorDistanceQuery =
httpJsonBody config ok200 []
(setRequestMethod "POST"
. setRequestPath (path eventTypeName)
. setRequestBodyJSON cursorDistanceQuery)
cursorsDistanceR' ::
MonadNakadiEnv r m
=> EventTypeName
-> [CursorDistanceQuery]
-> m [CursorDistanceResult]
cursorsDistanceR' eventTypeName cursorDistanceQuery = do
config <- asks (view L.nakadiConfig)
cursorsDistance' config eventTypeName cursorDistanceQuery
cursorDistance ::
MonadNakadi m
=> Config
-> EventTypeName
-> Cursor
-> Cursor
-> m Int64
cursorDistance config eventTypeName cursor cursor' =
let cursorDistanceQuery = CursorDistanceQuery { _initialCursor = cursor
, _finalCursor = cursor' }
in cursorsDistance' config eventTypeName [cursorDistanceQuery] >>= \case
distanceResult:_ -> return $ distanceResult^.L.distance
_ -> throwIO CursorDistanceNoResult
cursorDistanceR ::
MonadNakadiEnv r m
=> EventTypeName
-> Cursor
-> Cursor
-> m Int64
cursorDistanceR eventTypeName cursor cursor' = do
config <- asks (view L.nakadiConfig)
cursorDistance config eventTypeName cursor cursor'