summaryrefslogtreecommitdiffstats
path: root/Regfish/Types.hs
blob: 734c6c3ca89d5f1756f5eb4f037b514d8d22f27a (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}


module Regfish.Types where

import Control.Lens
import Control.Monad.Reader
import Control.Monad.State
import qualified Data.ByteString.Char8 as BS8
import Data.SafeCopy (base, deriveSafeCopy)
import Data.Typeable
import qualified Network.HTTP.Client as C
import qualified Network.Wreq as W


deriveSafeCopy 0 'base ''C.CookieJar
deriveSafeCopy 0 'base ''W.Cookie


newtype Regfish a = Regfish
    { runRegfish_ :: ReaderT RFConfig (StateT RFState IO) a
    }
  deriving
    ( Applicative
    , Functor
    , Monad
    , MonadIO
    , MonadReader RFConfig
    , MonadState RFState
    )


-- TODO reduce number of aliases?
type Password = String
type RRaux = Integer
type RRdata = String
type RRid = Integer
type RRname = String
type RRttl = Integer
type RRtype = String
type SessionToken = BS8.ByteString
type Url = String
type Username = String


data RFConfig = RFConfig
    { _username :: Username
    , _password :: Password
    , _allinone :: Url
    }
  deriving (Show)


data RFState = RFState
    { _cookieJar :: C.CookieJar
    }
  deriving (Show, Typeable)
          -- ^ TODO rm Show


makeLenses ''RFState


data RR = RR String String Integer RRData
  deriving (Show)


data RRData
    = A String
    | AAAA String
    | ALIAS String
    | CNAME String
    | MX Integer String
    | NS String
    | TXT String
    | SRV String
  deriving (Show)


-- TODO kill Record?
data Record = Record String String String Int Int String
    deriving (Show)


deriveSafeCopy 0 'base ''RFState
deriveSafeCopy 0 'base ''RFConfig