module Network.Nakadi.EventTypes.CursorDistances
( cursorsDistance'
, cursorDistance
) 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 b m
=> EventTypeName
-> [CursorDistanceQuery]
-> m [CursorDistanceResult]
cursorsDistance' eventTypeName cursorDistanceQuery =
httpJsonBody ok200 []
(setRequestMethod "POST"
. setRequestPath (path eventTypeName)
. setRequestBodyJSON cursorDistanceQuery)
cursorDistance ::
MonadNakadi b m
=> EventTypeName
-> Cursor
-> Cursor
-> m Int64
cursorDistance eventTypeName cursor cursor' =
let cursorDistanceQuery = CursorDistanceQuery { _initialCursor = cursor
, _finalCursor = cursor' }
in cursorsDistance' eventTypeName [cursorDistanceQuery] >>= \case
distanceResult:_ -> return $ distanceResult^.L.distance
_ -> throwM CursorDistanceNoResult