{-# LANGUAGE OverloadedStrings #-}
module Network.Ipfs.Api.Object where
import Control.Monad.IO.Class (MonadIO)
import Data.Aeson (decode)
import Data.Text (Text)
import Network.HTTP.Client (responseBody)
import Network.Ipfs.Api.Internal (_objectAddLink, _objectData,
_objectDiff, _objectGet,
_objectGetLinks, _objectNew,
_objectRmLink, _objectStat)
import Network.Ipfs.Api.Internal.Call (call, multipartCall)
import Network.Ipfs.Api.Types (ObjectDiffObj, ObjectGetObj,
ObjectLinksObj, ObjectObj,
ObjectReturnType,
ObjectStatObj)
import Network.Ipfs.Client (IpfsT)
object :: MonadIO m => Text -> IpfsT m ObjectReturnType
object = call . _objectData
new :: MonadIO m => IpfsT m ObjectObj
new = call _objectNew
getLinks :: MonadIO m => Text -> IpfsT m ObjectLinksObj
getLinks = call . _objectGetLinks
addLink :: MonadIO m => Text -> Text -> Text -> IpfsT m ObjectLinksObj
addLink hash name = call . _objectAddLink hash (Just name) . Just
rmLink :: MonadIO m => Text -> Text -> IpfsT m ObjectLinksObj
rmLink key = call . _objectRmLink key . Just
appendData :: MonadIO m => Text -> Text -> IpfsT m (Maybe ObjectLinksObj)
appendData key = fmap decodeResponse . multipartCall ("object/patch/append-data?arg=" <> key)
where
decodeResponse = decode . responseBody
setData :: MonadIO m => Text -> Text -> IpfsT m (Maybe ObjectLinksObj)
setData key = fmap decodeResponse . multipartCall ("object/patch/set-data?arg=" <> key)
where
decodeResponse = decode . responseBody
get :: MonadIO m => Text -> IpfsT m ObjectGetObj
get = call . _objectGet
diff :: MonadIO m => Text -> Text -> IpfsT m ObjectDiffObj
diff firstKey = call . _objectDiff firstKey . Just
put :: MonadIO m => Text -> IpfsT m (Maybe ObjectObj)
put = fmap decodeResponse . multipartCall "object/put"
where
decodeResponse = decode . responseBody
objectStat :: MonadIO m => Text -> IpfsT m ObjectStatObj
objectStat = call . _objectStat