module TD.Data.Minithumbnail
(Minithumbnail(..)) 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 Minithumbnail
= Minithumbnail
{ Minithumbnail -> Maybe Int
width :: Maybe Int
, Minithumbnail -> Maybe Int
height :: Maybe Int
, Minithumbnail -> Maybe ByteString
_data :: Maybe BS.ByteString
}
deriving (Minithumbnail -> Minithumbnail -> Bool
(Minithumbnail -> Minithumbnail -> Bool)
-> (Minithumbnail -> Minithumbnail -> Bool) -> Eq Minithumbnail
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Minithumbnail -> Minithumbnail -> Bool
== :: Minithumbnail -> Minithumbnail -> Bool
$c/= :: Minithumbnail -> Minithumbnail -> Bool
/= :: Minithumbnail -> Minithumbnail -> Bool
Eq, Int -> Minithumbnail -> ShowS
[Minithumbnail] -> ShowS
Minithumbnail -> String
(Int -> Minithumbnail -> ShowS)
-> (Minithumbnail -> String)
-> ([Minithumbnail] -> ShowS)
-> Show Minithumbnail
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Minithumbnail -> ShowS
showsPrec :: Int -> Minithumbnail -> ShowS
$cshow :: Minithumbnail -> String
show :: Minithumbnail -> String
$cshowList :: [Minithumbnail] -> ShowS
showList :: [Minithumbnail] -> ShowS
Show)
instance I.ShortShow Minithumbnail where
shortShow :: Minithumbnail -> String
shortShow Minithumbnail
{ width :: Minithumbnail -> Maybe Int
width = Maybe Int
width_
, height :: Minithumbnail -> Maybe Int
height = Maybe Int
height_
, _data :: Minithumbnail -> Maybe ByteString
_data = Maybe ByteString
_data_
}
= String
"Minithumbnail"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"width" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
width_
, String
"height" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
height_
, String
"_data" String -> Maybe ByteString -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ByteString
_data_
]
instance AT.FromJSON Minithumbnail where
parseJSON :: Value -> Parser Minithumbnail
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
"minithumbnail" -> Value -> Parser Minithumbnail
parseMinithumbnail Value
v
String
_ -> Parser Minithumbnail
forall a. Monoid a => a
mempty
where
parseMinithumbnail :: A.Value -> AT.Parser Minithumbnail
parseMinithumbnail :: Value -> Parser Minithumbnail
parseMinithumbnail = String
-> (Object -> Parser Minithumbnail)
-> Value
-> Parser Minithumbnail
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Minithumbnail" ((Object -> Parser Minithumbnail) -> Value -> Parser Minithumbnail)
-> (Object -> Parser Minithumbnail)
-> Value
-> Parser Minithumbnail
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
width_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"width"
Maybe Int
height_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"height"
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"
Minithumbnail -> Parser Minithumbnail
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Minithumbnail -> Parser Minithumbnail)
-> Minithumbnail -> Parser Minithumbnail
forall a b. (a -> b) -> a -> b
$ Minithumbnail
{ width :: Maybe Int
width = Maybe Int
width_
, height :: Maybe Int
height = Maybe Int
height_
, _data :: Maybe ByteString
_data = Maybe ByteString
_data_
}
parseJSON Value
_ = Parser Minithumbnail
forall a. Monoid a => a
mempty