{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Network.Ipfs.Client where
import Control.Monad.Except
import Control.Monad.Reader
import Network.HTTP.Client as Net hiding (Proxy)
import Servant.Client
newtype IpfsT m a = IpfsT { unIpfs :: ReaderT (Manager, BaseUrl, String) (ExceptT ClientError m) a }
deriving ( Functor
, Applicative
, Monad
, MonadIO
, MonadReader (Manager, BaseUrl, String)
, MonadError ClientError
)
instance MonadTrans IpfsT where
lift = IpfsT . lift . lift
type Ipfs a = IpfsT IO a
runIpfs' :: BaseUrl -> Ipfs a -> IO ()
runIpfs' url ipfs = do
manager' <- liftIO $ newManager defaultManagerSettings
ret <- runExceptT (runReaderT (unIpfs ipfs) (manager', url, showBaseUrl url))
case ret of
Left err -> putStrLn $ "Error: " ++ show err
Right _ -> putStr ""
runIpfs :: Ipfs a -> IO ()
runIpfs = runIpfs' (BaseUrl Http "localhost" 5001 "/api/v0")