module TD.Data.EncryptedCredentials
(EncryptedCredentials(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.ByteString as BS
data EncryptedCredentials
= EncryptedCredentials
{ EncryptedCredentials -> Maybe ByteString
_data :: Maybe BS.ByteString
, EncryptedCredentials -> Maybe ByteString
hash :: Maybe BS.ByteString
, EncryptedCredentials -> Maybe ByteString
secret :: Maybe BS.ByteString
}
deriving (EncryptedCredentials -> EncryptedCredentials -> Bool
(EncryptedCredentials -> EncryptedCredentials -> Bool)
-> (EncryptedCredentials -> EncryptedCredentials -> Bool)
-> Eq EncryptedCredentials
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncryptedCredentials -> EncryptedCredentials -> Bool
== :: EncryptedCredentials -> EncryptedCredentials -> Bool
$c/= :: EncryptedCredentials -> EncryptedCredentials -> Bool
/= :: EncryptedCredentials -> EncryptedCredentials -> Bool
Eq, Int -> EncryptedCredentials -> ShowS
[EncryptedCredentials] -> ShowS
EncryptedCredentials -> String
(Int -> EncryptedCredentials -> ShowS)
-> (EncryptedCredentials -> String)
-> ([EncryptedCredentials] -> ShowS)
-> Show EncryptedCredentials
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EncryptedCredentials -> ShowS
showsPrec :: Int -> EncryptedCredentials -> ShowS
$cshow :: EncryptedCredentials -> String
show :: EncryptedCredentials -> String
$cshowList :: [EncryptedCredentials] -> ShowS
showList :: [EncryptedCredentials] -> ShowS
Show)
instance I.ShortShow EncryptedCredentials where
shortShow :: EncryptedCredentials -> String
shortShow EncryptedCredentials
{ _data :: EncryptedCredentials -> Maybe ByteString
_data = Maybe ByteString
_data_
, hash :: EncryptedCredentials -> Maybe ByteString
hash = Maybe ByteString
hash_
, secret :: EncryptedCredentials -> Maybe ByteString
secret = Maybe ByteString
secret_
}
= String
"EncryptedCredentials"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_data" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
_data_
, String
"hash" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
hash_
, String
"secret" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
secret_
]
instance AT.FromJSON EncryptedCredentials where
parseJSON :: Value -> Parser EncryptedCredentials
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"encryptedCredentials" -> Value -> Parser EncryptedCredentials
parseEncryptedCredentials Value
v
String
_ -> Parser EncryptedCredentials
forall a. Monoid a => a
mempty
where
parseEncryptedCredentials :: A.Value -> AT.Parser EncryptedCredentials
parseEncryptedCredentials :: Value -> Parser EncryptedCredentials
parseEncryptedCredentials = String
-> (Object -> Parser EncryptedCredentials)
-> Value
-> Parser EncryptedCredentials
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"EncryptedCredentials" ((Object -> Parser EncryptedCredentials)
-> Value -> Parser EncryptedCredentials)
-> (Object -> Parser EncryptedCredentials)
-> Value
-> Parser EncryptedCredentials
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ByteString
_data_ <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"data"
Maybe ByteString
hash_ <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"hash"
Maybe ByteString
secret_ <- (String -> ByteString) -> Maybe String -> Maybe ByteString
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> ByteString
I.readBytes (Maybe String -> Maybe ByteString)
-> Parser (Maybe String) -> Parser (Maybe ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"secret"
EncryptedCredentials -> Parser EncryptedCredentials
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EncryptedCredentials -> Parser EncryptedCredentials)
-> EncryptedCredentials -> Parser EncryptedCredentials
forall a b. (a -> b) -> a -> b
$ EncryptedCredentials
{ _data :: Maybe ByteString
_data = Maybe ByteString
_data_
, hash :: Maybe ByteString
hash = Maybe ByteString
hash_
, secret :: Maybe ByteString
secret = Maybe ByteString
secret_
}
parseJSON Value
_ = Parser EncryptedCredentials
forall a. Monoid a => a
mempty