module TD.Data.MessageSponsor
(MessageSponsor(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.Photo as Photo
data
=
{ MessageSponsor -> Maybe Text
url :: Maybe T.Text
, MessageSponsor -> Maybe Photo
photo :: Maybe Photo.Photo
, MessageSponsor -> Maybe Text
info :: Maybe T.Text
}
deriving (MessageSponsor -> MessageSponsor -> Bool
(MessageSponsor -> MessageSponsor -> Bool)
-> (MessageSponsor -> MessageSponsor -> Bool) -> Eq MessageSponsor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageSponsor -> MessageSponsor -> Bool
== :: MessageSponsor -> MessageSponsor -> Bool
$c/= :: MessageSponsor -> MessageSponsor -> Bool
/= :: MessageSponsor -> MessageSponsor -> Bool
Eq, Int -> MessageSponsor -> ShowS
[MessageSponsor] -> ShowS
MessageSponsor -> String
(Int -> MessageSponsor -> ShowS)
-> (MessageSponsor -> String)
-> ([MessageSponsor] -> ShowS)
-> Show MessageSponsor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageSponsor -> ShowS
showsPrec :: Int -> MessageSponsor -> ShowS
$cshow :: MessageSponsor -> String
show :: MessageSponsor -> String
$cshowList :: [MessageSponsor] -> ShowS
showList :: [MessageSponsor] -> ShowS
Show)
instance I.ShortShow MessageSponsor where
shortShow :: MessageSponsor -> String
shortShow MessageSponsor
{ url :: MessageSponsor -> Maybe Text
url = Maybe Text
url_
, photo :: MessageSponsor -> Maybe Photo
photo = Maybe Photo
photo_
, info :: MessageSponsor -> Maybe Text
info = Maybe Text
info_
}
= String
"MessageSponsor"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
, String
"photo" String -> Maybe Photo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Photo
photo_
, String
"info" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
info_
]
instance AT.FromJSON MessageSponsor where
parseJSON :: Value -> Parser MessageSponsor
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
"messageSponsor" -> Value -> Parser MessageSponsor
parseMessageSponsor Value
v
String
_ -> Parser MessageSponsor
forall a. Monoid a => a
mempty
where
parseMessageSponsor :: A.Value -> AT.Parser MessageSponsor
parseMessageSponsor :: Value -> Parser MessageSponsor
parseMessageSponsor = String
-> (Object -> Parser MessageSponsor)
-> Value
-> Parser MessageSponsor
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageSponsor" ((Object -> Parser MessageSponsor)
-> Value -> Parser MessageSponsor)
-> (Object -> Parser MessageSponsor)
-> Value
-> Parser MessageSponsor
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"url"
Maybe Photo
photo_ <- Object
o Object -> Key -> Parser (Maybe Photo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"photo"
Maybe Text
info_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"info"
MessageSponsor -> Parser MessageSponsor
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageSponsor -> Parser MessageSponsor)
-> MessageSponsor -> Parser MessageSponsor
forall a b. (a -> b) -> a -> b
$ MessageSponsor
{ url :: Maybe Text
url = Maybe Text
url_
, photo :: Maybe Photo
photo = Maybe Photo
photo_
, info :: Maybe Text
info = Maybe Text
info_
}
parseJSON Value
_ = Parser MessageSponsor
forall a. Monoid a => a
mempty