module Twilio.Types.AuthToken
(
AuthToken
, getAuthToken
, parseAuthToken
) where
import Control.Monad
import Data.Aeson
import Data.Char
import Data.Text (Text)
import qualified Data.Text as T
newtype AuthToken = AuthToken { getAuthToken' :: Text }
deriving (Show, Eq, Ord)
getAuthToken :: AuthToken -> Text
getAuthToken = getAuthToken'
parseAuthToken :: Text -> Maybe AuthToken
parseAuthToken = parseAuthToken'
parseAuthToken' :: MonadPlus m => Text -> m AuthToken
parseAuthToken' token
| T.length token == 32
, T.all (\x -> isLower x || isNumber x) token
= return $ AuthToken token
| otherwise
= mzero
instance FromJSON AuthToken where
parseJSON (String v) = parseAuthToken' v
parseJSON _ = mzero