module Text.XML.Twiml.Types
( Natural
, URL
, parseURL
, Method(..)
, Key(..)
, Digit(..)
, SayAttributes(..)
, defaultSayAttributes
, Voice(..)
, Lang(..)
, LangAlice(..)
, PlayAttributes(..)
, defaultPlayAttributes
, GatherAttributes(..)
, defaultGatherAttributes
, Gather'
, RecordAttributes(..)
, defaultRecordAttributes
, SmsAttributes(..)
, defaultSmsAttributes
, DialAttributes(..)
, defaultDialAttributes
, DialNoun(..)
, NumberAttributes(..)
, defaultNumberAttributes
, SipAttributes(..)
, defaultSipAttributes
, Transport(..)
, ClientAttributes(..)
, defaultClientAttributes
, ConferenceAttributes(..)
, defaultConferenceAttributes
, ConferenceBeep(..)
, QueueAttributes(..)
, defaultQueueAttributes
, EnqueueAttributes(..)
, defaultEnqueueAttributes
, RedirectAttributes(..)
, defaultRedirectAttributes
, RejectAttributes(..)
, defaultRejectAttributes
, Reason(..)
, PauseAttributes(..)
, defaultPauseAttributes
, HasLoop(..)
, HasAction(..)
, HasMethod(..)
, HasTimeout(..)
, HasFinishOnKey(..)
, Lens
, Lens'
, lens
, (^.)
, over
, to'
, Fix(..)
, Foldable(..)
, Base(..)
, (:/~)
, Yes
, No
) where
import Network.URI (URI(..), parseURIReference)
import Unsafe.Coerce (unsafeCoerce)
data SayAttributes = SayAttributes
{ sayVoice :: Maybe Voice
, sayLoop :: Maybe Natural
}
defaultSayAttributes :: SayAttributes
defaultSayAttributes = SayAttributes
{ sayVoice = Nothing
, sayLoop = Nothing
}
data Voice
= Man (Maybe Lang)
| Woman (Maybe Lang)
| Alice (Maybe LangAlice)
data Lang
= English
| EnglishUK
| Spanish
| French
| German
| Italian
instance Show Lang where
show English = "en"
show EnglishUK = "en-gb"
show Spanish = "es"
show French = "fr"
show German = "de"
show Italian = "it"
data LangAlice
= DaDK
| DeDE
| EnAU
| EnCA
| EnGB
| EnIN
| EnUS
| CaES
| EsES
| EsMX
| FiFI
| FrCA
| FrFR
| ItIT
| JaJP
| KoKR
| NbNO
| NlNL
| PlPL
| PtBR
| PtPT
| RuRU
| SvSE
| ZhCN
| ZhHK
| ZhTW
instance Show LangAlice where
show DaDK = "da-DK"
show DeDE = "de-DE"
show EnAU = "en-AU"
show EnCA = "en-CA"
show EnGB = "en-GB"
show EnIN = "en-IN"
show EnUS = "en-US"
show CaES = "ca-ES"
show EsES = "es-ES"
show EsMX = "es-MX"
show FiFI = "fi-FI"
show FrCA = "fr-CA"
show FrFR = "fr-FR"
show ItIT = "it-IT"
show JaJP = "ja-JP"
show KoKR = "ko-KR"
show NbNO = "nb-NO"
show NlNL = "nl-NL"
show PlPL = "pl-PL"
show PtBR = "pt-BR"
show PtPT = "pt-PT"
show RuRU = "ru-RU"
show SvSE = "sv-SE"
show ZhCN = "zh-CN"
show ZhHK = "zh-HK"
show ZhTW = "zh-TW"
data PlayAttributes = PlayAttributes
{ playLoop :: Maybe Natural
, playDigits :: Maybe [Digit]
}
defaultPlayAttributes :: PlayAttributes
defaultPlayAttributes = PlayAttributes
{ playLoop = Nothing
, playDigits = Nothing
}
data GatherAttributes = GatherAttributes
{ gatherAction :: Maybe URL
, gatherMethod :: Maybe Method
, gatherTimeout :: Maybe Natural
, gatherFinishOnKey :: Maybe Key
, gatherNumDigits :: Maybe Natural
}
defaultGatherAttributes :: GatherAttributes
defaultGatherAttributes = GatherAttributes
{ gatherAction = Nothing
, gatherMethod = Nothing
, gatherTimeout = Nothing
, gatherFinishOnKey = Nothing
, gatherNumDigits = Nothing
}
data Gather'
data RecordAttributes = RecordAttributes
{ recordAction :: Maybe URL
, recordMethod :: Maybe Method
, recordTimeout :: Maybe Natural
, recordFinishOnKey :: Maybe Key
, recordMaxLength :: Maybe Natural
, recordTranscribe :: Maybe Bool
, recordTranscribeCallback :: Maybe URL
, recordPlayBeep :: Maybe Bool
}
defaultRecordAttributes :: RecordAttributes
defaultRecordAttributes = RecordAttributes
{ recordAction = Nothing
, recordMethod = Nothing
, recordTimeout = Nothing
, recordFinishOnKey = Nothing
, recordMaxLength = Nothing
, recordTranscribe = Nothing
, recordTranscribeCallback = Nothing
, recordPlayBeep = Nothing
}
data SmsAttributes = SmsAttributes
{ smsTo :: Maybe String
, smsFrom :: Maybe String
, smsAction :: Maybe URL
, smsMethod :: Maybe Method
, smsStatusCallback :: Maybe URL
}
defaultSmsAttributes :: SmsAttributes
defaultSmsAttributes = SmsAttributes
{ smsTo = Nothing
, smsFrom = Nothing
, smsAction = Nothing
, smsMethod = Nothing
, smsStatusCallback = Nothing
}
data DialAttributes = DialAttributes
{ dialAction :: Maybe URL
, dialMethod :: Maybe Method
, dialTimeout :: Maybe Natural
, dialHangupOnStar :: Maybe Bool
, dialTimeLimit :: Maybe Natural
, dialCallerId :: Maybe String
, dialRecord :: Maybe Bool
}
defaultDialAttributes :: DialAttributes
defaultDialAttributes = DialAttributes
{ dialAction = Nothing
, dialMethod = Nothing
, dialTimeout = Nothing
, dialHangupOnStar = Nothing
, dialTimeLimit = Nothing
, dialCallerId = Nothing
, dialRecord = Nothing
}
data NumberAttributes = NumberAttributes
{ numberSendDigits :: Maybe [Digit]
, numberURL :: Maybe URL
, numberMethod :: Maybe Method
}
defaultNumberAttributes :: NumberAttributes
defaultNumberAttributes = NumberAttributes
{ numberSendDigits = Nothing
, numberURL = Nothing
, numberMethod = Nothing
}
data SipAttributes = SipAttributes
{ sipUsername :: Maybe String
, sipPassword :: Maybe String
, sipTransport :: Maybe Transport
, sipHeaders :: Maybe String
, sipURL :: Maybe URL
, sipMethod :: Maybe Method
}
defaultSipAttributes :: SipAttributes
defaultSipAttributes = SipAttributes
{ sipUsername = Nothing
, sipPassword = Nothing
, sipTransport = Nothing
, sipHeaders = Nothing
, sipURL = Nothing
, sipMethod = Nothing
}
data Transport = TCP | UDP
deriving Show
data ClientAttributes = ClientAttributes
{ clientURL :: Maybe URL
, clientMethod :: Maybe Method
}
defaultClientAttributes :: ClientAttributes
defaultClientAttributes = ClientAttributes
{ clientURL = Nothing
, clientMethod = Nothing
}
data ConferenceAttributes = ConferenceAttributes
{ conferenceMuted :: Maybe Bool
, conferenceBeep :: Maybe Bool
, conferenceStartOnEnter :: Maybe Bool
, conferenceEndOnExit :: Maybe Bool
, conferenceWaitURL :: Maybe URL
, conferenceWaitMethod :: Maybe Method
, conferenceMaxParticipants :: Maybe Natural
}
defaultConferenceAttributes :: ConferenceAttributes
defaultConferenceAttributes = ConferenceAttributes
{ conferenceMuted = Nothing
, conferenceBeep = Nothing
, conferenceStartOnEnter = Nothing
, conferenceEndOnExit = Nothing
, conferenceWaitURL = Nothing
, conferenceWaitMethod = Nothing
, conferenceMaxParticipants = Nothing
}
data ConferenceBeep
= Yes
| No
| OnExit
| OnEnter
instance Show ConferenceBeep where
show Yes = "yes"
show No = "no"
show OnExit = "onExit"
show OnEnter = "onEnter"
data QueueAttributes = QueueAttributes
{ queueURL :: Maybe URL
, queueMethod :: Maybe Method
}
defaultQueueAttributes :: QueueAttributes
defaultQueueAttributes = QueueAttributes
{ queueURL = Nothing
, queueMethod = Nothing
}
data DialNoun
= Number NumberAttributes String
| Sip SipAttributes URL
| Client ClientAttributes String
| Conference ConferenceAttributes String
| Queue QueueAttributes String
data EnqueueAttributes = EnqueueAttributes
{ enqueueAction :: Maybe URL
, enqueueMethod :: Maybe Method
, enqueueWaitURL :: Maybe URL
, enqueueWaitURLMethod :: Maybe Method
}
defaultEnqueueAttributes :: EnqueueAttributes
defaultEnqueueAttributes = EnqueueAttributes
{ enqueueAction = Nothing
, enqueueMethod = Nothing
, enqueueWaitURL = Nothing
, enqueueWaitURLMethod = Nothing
}
data RedirectAttributes = RedirectAttributes
{ redirectMethod :: Maybe Method
}
defaultRedirectAttributes :: RedirectAttributes
defaultRedirectAttributes = RedirectAttributes
{ redirectMethod = Nothing
}
data RejectAttributes = RejectAttributes
{ rejectReason :: Maybe Reason
}
defaultRejectAttributes :: RejectAttributes
defaultRejectAttributes = RejectAttributes
{ rejectReason = Nothing
}
data Reason = Rejected | Busy
instance Show Reason where
show Rejected = "rejected"
show Busy = "busy"
data PauseAttributes = PauseAttributes
{ pauseLength :: Maybe Natural
}
defaultPauseAttributes :: PauseAttributes
defaultPauseAttributes = PauseAttributes
{ pauseLength = Nothing
}
class HasLoop t where
loop :: Lens t t (Maybe Natural) Natural
class HasAction t where
action :: Lens t t (Maybe URL) URL
class HasMethod t where
method :: Lens t t (Maybe Method) Method
class HasTimeout t where
timeout :: Lens t t (Maybe Natural) Natural
class HasFinishOnKey t where
finishOnKey :: Lens t t (Maybe Key) Key
data URL = URL { getURL :: String }
instance Show URL where
show = getURL
isHttp :: URI -> Bool
isHttp uri = case uriScheme uri of
"" -> True
"http:" -> True
"https:" -> True
_ -> False
parseURL :: String -> Maybe URL
parseURL url = parseURIReference url
>>= (\uri -> if isHttp uri then Just (URL url) else Nothing)
data Method = GET | POST
deriving Show
type Natural = Int
data Key
= K0
| K1
| K2
| K3
| K4
| K5
| K6
| K7
| K8
| K9
| KStar
| KPound
instance Show Key where
show K0 = "0"
show K1 = "1"
show K2 = "2"
show K3 = "3"
show K4 = "4"
show K5 = "5"
show K6 = "6"
show K7 = "7"
show K8 = "8"
show K9 = "9"
show KStar = "*"
show KPound = "#"
data GatherNoun
data Digit
= D0
| D1
| D2
| D3
| D4
| D5
| D6
| D7
| D8
| D9
| W
instance Show Digit where
show D0 = "0"
show D1 = "1"
show D2 = "2"
show D3 = "3"
show D4 = "4"
show D5 = "5"
show D6 = "6"
show D7 = "7"
show D8 = "8"
show D9 = "9"
show W = "w"
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
lens sa sbt afb s = fmap (sbt s) $ afb (sa s)
type Lens' s a = Lens s s a a
newtype Accessor r a = Accessor { runAccessor :: r }
instance Functor (Accessor r) where
fmap _ (Accessor m) = Accessor m
instance Contravariant (Accessor r) where
contramap _ (Accessor m) = Accessor m
type Getting r s a = (a -> Accessor r a) -> s -> Accessor r s
infixl 8 ^.
(^.) :: s -> Getting a s a -> a
s ^. l = runAccessor (l Accessor s)
type Setting p s t a b = p a (Mutator b) -> s -> Mutator t
newtype Mutator a = Mutator { runMutator :: a }
instance Functor Mutator where
fmap f (Mutator a) = Mutator $ f a
over :: Profunctor p => Setting p s t a b -> p a b -> s -> t
over l f = runMutator #. l (Mutator #. f)
type IndexPreservingGetter s a
= forall p f. (Profunctor p, Contravariant f, Functor f) => p a (f a) -> p s (f s)
to' :: (s -> a) -> IndexPreservingGetter s a
to' f = dimap f coerce
coerce :: (Contravariant f, Functor f) => f a -> f b
coerce a = fmap absurd $ contramap absurd a
class Contravariant f where
contramap :: (a -> b) -> f b -> f a
newtype Void = Void Void
absurd :: Void -> a
absurd (Void a) = absurd a
class Profunctor h where
lmap :: (a -> b) -> h b c -> h a c
rmap :: (b -> c) -> h a b -> h a c
dimap :: (a -> b) -> (c -> d) -> h b c -> h a d
dimap f g = lmap f . rmap g
(#.) :: (b -> c) -> h a b -> h a c
(#.) = \f -> \p -> p `seq` rmap f p
instance Profunctor (->) where
dimap ab cd bc = cd . bc . ab
lmap = flip (.)
rmap = (.)
(#.) _ = unsafeCoerce
newtype Fix f = Fix { unFix :: f (Fix f) }
type family Base t :: * -> *
class Functor (Base t) => Foldable t where
project :: t -> Base t t
cata :: (Base t a -> a) -> t -> a
cata f = c where c = f . fmap c . project
data Yes
data No
class TypeCast a b | a -> b
instance TypeCast a a
class TypeEq a b c | a b -> c
instance TypeEq x x Yes
instance TypeCast No b => TypeEq x y b
class TypeEq x y No => (:/~) x y
instance TypeEq x y No => (:/~) x y