module Database.Orchestrate.Ref
( getRef
, listRefs
) where
import Control.Applicative
import Control.Error
import Control.Lens
import Control.Monad
import Data.Aeson
import Data.Aeson.Types (Parser)
import qualified Data.HashMap.Strict as M
import qualified Data.Text as T
import Network.Wreq
import Database.Orchestrate.Types
import Database.Orchestrate.Utils
getRef :: FromJSON r => Collection -> Key -> Ref -> OrchestrateIO (Maybe r)
getRef c k r =
join . fmap (decode . (^.responseBody)) <$> api404 [] [c, k, "refs", r] [] getWith
listRefs :: FromJSON v
=> Collection
-> Key
-> Maybe Int
-> Maybe Int
-> Bool
-> OrchestrateIO (ResultList (TombstoneItem v))
listRefs c k limit offset values =
apiCheckDecode [] [c, k, "refs"] parms getWith
where ifm True = Just
ifm False = const Nothing
parms = catMaybes [ ifm values $ "values" := ("true" :: T.Text)
, ("limit" :=) . show <$> limit
, ("offset" :=) . show <$> offset
]