aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Config.hs
blob: b58304865143bcc9c7eb1466adeb402d76f834e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}

module Model.Config
  ( getConfig
  , Config(..)
  ) where

import Data.ConfigFile
import Data.Text (Text)
import qualified Data.Text as T

import Control.Monad.Trans.Error (runErrorT)
import Control.Monad.IO.Class (liftIO)
import Control.Monad (join)
import Control.Arrow (left)

data Config = Config
  { mailTo :: Text
  , mailFrom :: Text
  , dayForNextWeekNotification :: Text
  } deriving (Read, Eq, Show)

getConfig :: FilePath -> IO (Either Text Config)
getConfig filePath =
  left (T.pack . show) <$> (runErrorT $ do
    cp <- join $ liftIO $ readfile emptyCP filePath
    Config <$>
      (T.pack <$> get cp "DEFAULT" "mail-to") <*>
      (T.pack <$> get cp "DEFAULT" "mail-from") <*>
      (T.pack <$> get cp "DEFAULT" "day-for-next-week-notification")
  )