module TD.Data.MessageLink
(MessageLink(..)) 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
data MessageLink
= MessageLink
{ MessageLink -> Maybe Text
link :: Maybe T.Text
, MessageLink -> Maybe Bool
is_public :: Maybe Bool
}
deriving (MessageLink -> MessageLink -> Bool
(MessageLink -> MessageLink -> Bool)
-> (MessageLink -> MessageLink -> Bool) -> Eq MessageLink
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageLink -> MessageLink -> Bool
== :: MessageLink -> MessageLink -> Bool
$c/= :: MessageLink -> MessageLink -> Bool
/= :: MessageLink -> MessageLink -> Bool
Eq, Int -> MessageLink -> ShowS
[MessageLink] -> ShowS
MessageLink -> String
(Int -> MessageLink -> ShowS)
-> (MessageLink -> String)
-> ([MessageLink] -> ShowS)
-> Show MessageLink
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageLink -> ShowS
showsPrec :: Int -> MessageLink -> ShowS
$cshow :: MessageLink -> String
show :: MessageLink -> String
$cshowList :: [MessageLink] -> ShowS
showList :: [MessageLink] -> ShowS
Show)
instance I.ShortShow MessageLink where
shortShow :: MessageLink -> String
shortShow MessageLink
{ link :: MessageLink -> Maybe Text
link = Maybe Text
link_
, is_public :: MessageLink -> Maybe Bool
is_public = Maybe Bool
is_public_
}
= String
"MessageLink"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"link" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
link_
, String
"is_public" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_public_
]
instance AT.FromJSON MessageLink where
parseJSON :: Value -> Parser MessageLink
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
"messageLink" -> Value -> Parser MessageLink
parseMessageLink Value
v
String
_ -> Parser MessageLink
forall a. Monoid a => a
mempty
where
parseMessageLink :: A.Value -> AT.Parser MessageLink
parseMessageLink :: Value -> Parser MessageLink
parseMessageLink = String
-> (Object -> Parser MessageLink) -> Value -> Parser MessageLink
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageLink" ((Object -> Parser MessageLink) -> Value -> Parser MessageLink)
-> (Object -> Parser MessageLink) -> Value -> Parser MessageLink
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
link_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"link"
Maybe Bool
is_public_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_public"
MessageLink -> Parser MessageLink
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageLink -> Parser MessageLink)
-> MessageLink -> Parser MessageLink
forall a b. (a -> b) -> a -> b
$ MessageLink
{ link :: Maybe Text
link = Maybe Text
link_
, is_public :: Maybe Bool
is_public = Maybe Bool
is_public_
}
parseJSON Value
_ = Parser MessageLink
forall a. Monoid a => a
mempty