module TD.Data.LinkPreview
(LinkPreview(..)) 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.FormattedText as FormattedText
import qualified TD.Data.LinkPreviewType as LinkPreviewType
data LinkPreview
= LinkPreview
{ LinkPreview -> Maybe Text
url :: Maybe T.Text
, LinkPreview -> Maybe Text
display_url :: Maybe T.Text
, LinkPreview -> Maybe Text
site_name :: Maybe T.Text
, LinkPreview -> Maybe Text
title :: Maybe T.Text
, LinkPreview -> Maybe FormattedText
description :: Maybe FormattedText.FormattedText
, LinkPreview -> Maybe Text
author :: Maybe T.Text
, LinkPreview -> Maybe LinkPreviewType
_type :: Maybe LinkPreviewType.LinkPreviewType
, LinkPreview -> Maybe Bool
has_large_media :: Maybe Bool
, LinkPreview -> Maybe Bool
show_large_media :: Maybe Bool
, LinkPreview -> Maybe Bool
show_media_above_description :: Maybe Bool
, LinkPreview -> Maybe Bool
skip_confirmation :: Maybe Bool
, LinkPreview -> Maybe Bool
show_above_text :: Maybe Bool
, LinkPreview -> Maybe Int
instant_view_version :: Maybe Int
}
deriving (LinkPreview -> LinkPreview -> Bool
(LinkPreview -> LinkPreview -> Bool)
-> (LinkPreview -> LinkPreview -> Bool) -> Eq LinkPreview
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LinkPreview -> LinkPreview -> Bool
== :: LinkPreview -> LinkPreview -> Bool
$c/= :: LinkPreview -> LinkPreview -> Bool
/= :: LinkPreview -> LinkPreview -> Bool
Eq, Int -> LinkPreview -> ShowS
[LinkPreview] -> ShowS
LinkPreview -> String
(Int -> LinkPreview -> ShowS)
-> (LinkPreview -> String)
-> ([LinkPreview] -> ShowS)
-> Show LinkPreview
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LinkPreview -> ShowS
showsPrec :: Int -> LinkPreview -> ShowS
$cshow :: LinkPreview -> String
show :: LinkPreview -> String
$cshowList :: [LinkPreview] -> ShowS
showList :: [LinkPreview] -> ShowS
Show)
instance I.ShortShow LinkPreview where
shortShow :: LinkPreview -> String
shortShow LinkPreview
{ url :: LinkPreview -> Maybe Text
url = Maybe Text
url_
, display_url :: LinkPreview -> Maybe Text
display_url = Maybe Text
display_url_
, site_name :: LinkPreview -> Maybe Text
site_name = Maybe Text
site_name_
, title :: LinkPreview -> Maybe Text
title = Maybe Text
title_
, description :: LinkPreview -> Maybe FormattedText
description = Maybe FormattedText
description_
, author :: LinkPreview -> Maybe Text
author = Maybe Text
author_
, _type :: LinkPreview -> Maybe LinkPreviewType
_type = Maybe LinkPreviewType
_type_
, has_large_media :: LinkPreview -> Maybe Bool
has_large_media = Maybe Bool
has_large_media_
, show_large_media :: LinkPreview -> Maybe Bool
show_large_media = Maybe Bool
show_large_media_
, show_media_above_description :: LinkPreview -> Maybe Bool
show_media_above_description = Maybe Bool
show_media_above_description_
, skip_confirmation :: LinkPreview -> Maybe Bool
skip_confirmation = Maybe Bool
skip_confirmation_
, show_above_text :: LinkPreview -> Maybe Bool
show_above_text = Maybe Bool
show_above_text_
, instant_view_version :: LinkPreview -> Maybe Int
instant_view_version = Maybe Int
instant_view_version_
}
= String
"LinkPreview"
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
"display_url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
display_url_
, String
"site_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
site_name_
, String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"description" String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
description_
, String
"author" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
author_
, String
"_type" String -> Maybe LinkPreviewType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe LinkPreviewType
_type_
, String
"has_large_media" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_large_media_
, String
"show_large_media" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
show_large_media_
, String
"show_media_above_description" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
show_media_above_description_
, String
"skip_confirmation" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
skip_confirmation_
, String
"show_above_text" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
show_above_text_
, String
"instant_view_version" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
instant_view_version_
]
instance AT.FromJSON LinkPreview where
parseJSON :: Value -> Parser LinkPreview
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
"linkPreview" -> Value -> Parser LinkPreview
parseLinkPreview Value
v
String
_ -> Parser LinkPreview
forall a. Monoid a => a
mempty
where
parseLinkPreview :: A.Value -> AT.Parser LinkPreview
parseLinkPreview :: Value -> Parser LinkPreview
parseLinkPreview = String
-> (Object -> Parser LinkPreview) -> Value -> Parser LinkPreview
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LinkPreview" ((Object -> Parser LinkPreview) -> Value -> Parser LinkPreview)
-> (Object -> Parser LinkPreview) -> Value -> Parser LinkPreview
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 Text
display_url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"display_url"
Maybe Text
site_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"site_name"
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe FormattedText
description_ <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"description"
Maybe Text
author_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"author"
Maybe LinkPreviewType
_type_ <- Object
o Object -> Key -> Parser (Maybe LinkPreviewType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
Maybe Bool
has_large_media_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_large_media"
Maybe Bool
show_large_media_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"show_large_media"
Maybe Bool
show_media_above_description_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"show_media_above_description"
Maybe Bool
skip_confirmation_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"skip_confirmation"
Maybe Bool
show_above_text_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"show_above_text"
Maybe Int
instant_view_version_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"instant_view_version"
LinkPreview -> Parser LinkPreview
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LinkPreview -> Parser LinkPreview)
-> LinkPreview -> Parser LinkPreview
forall a b. (a -> b) -> a -> b
$ LinkPreview
{ url :: Maybe Text
url = Maybe Text
url_
, display_url :: Maybe Text
display_url = Maybe Text
display_url_
, site_name :: Maybe Text
site_name = Maybe Text
site_name_
, title :: Maybe Text
title = Maybe Text
title_
, description :: Maybe FormattedText
description = Maybe FormattedText
description_
, author :: Maybe Text
author = Maybe Text
author_
, _type :: Maybe LinkPreviewType
_type = Maybe LinkPreviewType
_type_
, has_large_media :: Maybe Bool
has_large_media = Maybe Bool
has_large_media_
, show_large_media :: Maybe Bool
show_large_media = Maybe Bool
show_large_media_
, show_media_above_description :: Maybe Bool
show_media_above_description = Maybe Bool
show_media_above_description_
, skip_confirmation :: Maybe Bool
skip_confirmation = Maybe Bool
skip_confirmation_
, show_above_text :: Maybe Bool
show_above_text = Maybe Bool
show_above_text_
, instant_view_version :: Maybe Int
instant_view_version = Maybe Int
instant_view_version_
}
parseJSON Value
_ = Parser LinkPreview
forall a. Monoid a => a
mempty