{-# LANGUAGE OverloadedStrings #-}
module Network.Ipfs.Api.Dag 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 (_dagGet, _dagResolve)
import Network.Ipfs.Api.Internal.Call (call, multipartCall)
import Network.Ipfs.Api.Types (DagPutObj, DagResolveObj,
DagReturnType)
import Network.Ipfs.Client (IpfsT)
get :: MonadIO m => Text -> IpfsT m DagReturnType
get :: Text -> IpfsT m Text
get = ClientM Text -> IpfsT m Text
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM Text -> IpfsT m Text)
-> (Text -> ClientM Text) -> Text -> IpfsT m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ClientM Text
_dagGet
resolve :: MonadIO m => Text -> IpfsT m DagResolveObj
resolve :: Text -> IpfsT m DagResolveObj
resolve = ClientM DagResolveObj -> IpfsT m DagResolveObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM DagResolveObj -> IpfsT m DagResolveObj)
-> (Text -> ClientM DagResolveObj) -> Text -> IpfsT m DagResolveObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ClientM DagResolveObj
_dagResolve
put :: MonadIO m => Text -> IpfsT m (Maybe DagPutObj)
put :: Text -> IpfsT m (Maybe DagPutObj)
put = (Response ByteString -> Maybe DagPutObj)
-> IpfsT m (Response ByteString) -> IpfsT m (Maybe DagPutObj)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Response ByteString -> Maybe DagPutObj
decodeResponse (IpfsT m (Response ByteString) -> IpfsT m (Maybe DagPutObj))
-> (Text -> IpfsT m (Response ByteString))
-> Text
-> IpfsT m (Maybe DagPutObj)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> IpfsT m (Response ByteString)
forall (m :: * -> *).
MonadIO m =>
Text -> Text -> IpfsT m (Response ByteString)
multipartCall Text
"dag/put"
where
decodeResponse :: Response ByteString -> Maybe DagPutObj
decodeResponse = ByteString -> Maybe DagPutObj
forall a. FromJSON a => ByteString -> Maybe a
decode (ByteString -> Maybe DagPutObj)
-> (Response ByteString -> ByteString)
-> Response ByteString
-> Maybe DagPutObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response ByteString -> ByteString
forall body. Response body -> body
responseBody