module Network.Nakadi.EventTypes.Schemas
( eventTypeSchemasGet
, eventTypeSchemasGetR
, eventTypeSchema
, eventTypeSchemaR
) where
import Network.Nakadi.Internal.Prelude
import Control.Lens
import Network.Nakadi.Internal.Http
import qualified Network.Nakadi.Internal.Lenses as L
path :: EventTypeName -> Maybe SchemaVersion -> ByteString
path eventTypeName maybeSchemaVersion =
"/event-types/"
<> encodeUtf8 (unEventTypeName eventTypeName)
<> "/schemas"
<> case maybeSchemaVersion of
Just schemaVersion -> "/" <> encodeUtf8 (unSchemaVersion schemaVersion)
Nothing -> ""
eventTypeSchemasGet ::
MonadNakadi m
=> Config
-> EventTypeName
-> Maybe Offset
-> Maybe Limit
-> m EventTypeSchemasResponse
eventTypeSchemasGet config eventTypeName offset limit =
httpJsonBody config ok200 []
(setRequestMethod "GET"
. setRequestPath (path eventTypeName Nothing)
. setRequestQueryParameters [ ("offset", offset')
, ("limit", limit') ])
where offset' = encodeUtf8 (tshow (maybe defaultOffset unOffset offset))
limit' = encodeUtf8 (tshow (maybe defaultLimit unLimit limit))
defaultOffset = 0
defaultLimit = 20
eventTypeSchemasGetR ::
MonadNakadiEnv r m
=> EventTypeName
-> Maybe Offset
-> Maybe Limit
-> m EventTypeSchemasResponse
eventTypeSchemasGetR eventTypeName offset limit = do
config <- asks (view L.nakadiConfig)
eventTypeSchemasGet config eventTypeName offset limit
eventTypeSchema ::
MonadNakadi m
=> Config
-> EventTypeName
-> SchemaVersion
-> m EventTypeSchema
eventTypeSchema config eventTypeName schemaVersion =
httpJsonBody config ok200 []
(setRequestMethod "GET" . setRequestPath (path eventTypeName (Just schemaVersion)))
eventTypeSchemaR ::
MonadNakadiEnv r m
=> EventTypeName
-> SchemaVersion
-> m EventTypeSchema
eventTypeSchemaR eventTypeName schemaVersion = do
config <- asks (view L.nakadiConfig)
eventTypeSchema config eventTypeName schemaVersion