module Network.Livy.Env
(
Env (..)
, HasEnv (..)
, newEnv
) where
import Control.Lens
import Control.Monad.IO.Class
import qualified Data.ByteString as S
import Network.HTTP.Client
data Env = Env
{ _envManager :: !Manager
, _envHost :: !S.ByteString
, _envPort :: !Int
}
class HasEnv a where
environment :: Lens' a Env
{-# MINIMAL environment #-}
envManager :: Lens' a Manager
envHost :: Lens' a S.ByteString
envPort :: Lens' a Int
envManager = environment . lens _envManager (\s a -> s {_envManager = a })
envHost = environment . lens _envHost (\s a -> s { _envHost = a })
envPort = environment . lens _envPort (\s a -> s { _envPort = a })
instance HasEnv Env where
environment = id
newEnv :: MonadIO m => S.ByteString -> Int -> m Env
newEnv h p = do
man <- liftIO $ newManager defaultManagerSettings
return $ Env man h p