module TD.Data.LinkPreviewOptions
( LinkPreviewOptions(..)
, defaultLinkPreviewOptions
) 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 LinkPreviewOptions
= LinkPreviewOptions
{ LinkPreviewOptions -> Maybe Bool
is_disabled :: Maybe Bool
, LinkPreviewOptions -> Maybe Text
url :: Maybe T.Text
, LinkPreviewOptions -> Maybe Bool
force_small_media :: Maybe Bool
, LinkPreviewOptions -> Maybe Bool
force_large_media :: Maybe Bool
, LinkPreviewOptions -> Maybe Bool
show_above_text :: Maybe Bool
}
deriving (LinkPreviewOptions -> LinkPreviewOptions -> Bool
(LinkPreviewOptions -> LinkPreviewOptions -> Bool)
-> (LinkPreviewOptions -> LinkPreviewOptions -> Bool)
-> Eq LinkPreviewOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LinkPreviewOptions -> LinkPreviewOptions -> Bool
== :: LinkPreviewOptions -> LinkPreviewOptions -> Bool
$c/= :: LinkPreviewOptions -> LinkPreviewOptions -> Bool
/= :: LinkPreviewOptions -> LinkPreviewOptions -> Bool
Eq, Int -> LinkPreviewOptions -> ShowS
[LinkPreviewOptions] -> ShowS
LinkPreviewOptions -> String
(Int -> LinkPreviewOptions -> ShowS)
-> (LinkPreviewOptions -> String)
-> ([LinkPreviewOptions] -> ShowS)
-> Show LinkPreviewOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LinkPreviewOptions -> ShowS
showsPrec :: Int -> LinkPreviewOptions -> ShowS
$cshow :: LinkPreviewOptions -> String
show :: LinkPreviewOptions -> String
$cshowList :: [LinkPreviewOptions] -> ShowS
showList :: [LinkPreviewOptions] -> ShowS
Show)
instance I.ShortShow LinkPreviewOptions where
shortShow :: LinkPreviewOptions -> String
shortShow LinkPreviewOptions
{ is_disabled :: LinkPreviewOptions -> Maybe Bool
is_disabled = Maybe Bool
is_disabled_
, url :: LinkPreviewOptions -> Maybe Text
url = Maybe Text
url_
, force_small_media :: LinkPreviewOptions -> Maybe Bool
force_small_media = Maybe Bool
force_small_media_
, force_large_media :: LinkPreviewOptions -> Maybe Bool
force_large_media = Maybe Bool
force_large_media_
, show_above_text :: LinkPreviewOptions -> Maybe Bool
show_above_text = Maybe Bool
show_above_text_
}
= String
"LinkPreviewOptions"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"is_disabled" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_disabled_
, String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
, String
"force_small_media" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
force_small_media_
, String
"force_large_media" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
force_large_media_
, String
"show_above_text" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
show_above_text_
]
instance AT.FromJSON LinkPreviewOptions where
parseJSON :: Value -> Parser LinkPreviewOptions
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
"linkPreviewOptions" -> Value -> Parser LinkPreviewOptions
parseLinkPreviewOptions Value
v
String
_ -> Parser LinkPreviewOptions
forall a. Monoid a => a
mempty
where
parseLinkPreviewOptions :: A.Value -> AT.Parser LinkPreviewOptions
parseLinkPreviewOptions :: Value -> Parser LinkPreviewOptions
parseLinkPreviewOptions = String
-> (Object -> Parser LinkPreviewOptions)
-> Value
-> Parser LinkPreviewOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LinkPreviewOptions" ((Object -> Parser LinkPreviewOptions)
-> Value -> Parser LinkPreviewOptions)
-> (Object -> Parser LinkPreviewOptions)
-> Value
-> Parser LinkPreviewOptions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
is_disabled_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_disabled"
Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"url"
Maybe Bool
force_small_media_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"force_small_media"
Maybe Bool
force_large_media_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"force_large_media"
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"
LinkPreviewOptions -> Parser LinkPreviewOptions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LinkPreviewOptions -> Parser LinkPreviewOptions)
-> LinkPreviewOptions -> Parser LinkPreviewOptions
forall a b. (a -> b) -> a -> b
$ LinkPreviewOptions
{ is_disabled :: Maybe Bool
is_disabled = Maybe Bool
is_disabled_
, url :: Maybe Text
url = Maybe Text
url_
, force_small_media :: Maybe Bool
force_small_media = Maybe Bool
force_small_media_
, force_large_media :: Maybe Bool
force_large_media = Maybe Bool
force_large_media_
, show_above_text :: Maybe Bool
show_above_text = Maybe Bool
show_above_text_
}
parseJSON Value
_ = Parser LinkPreviewOptions
forall a. Monoid a => a
mempty
instance AT.ToJSON LinkPreviewOptions where
toJSON :: LinkPreviewOptions -> Value
toJSON LinkPreviewOptions
{ is_disabled :: LinkPreviewOptions -> Maybe Bool
is_disabled = Maybe Bool
is_disabled_
, url :: LinkPreviewOptions -> Maybe Text
url = Maybe Text
url_
, force_small_media :: LinkPreviewOptions -> Maybe Bool
force_small_media = Maybe Bool
force_small_media_
, force_large_media :: LinkPreviewOptions -> Maybe Bool
force_large_media = Maybe Bool
force_large_media_
, show_above_text :: LinkPreviewOptions -> Maybe Bool
show_above_text = Maybe Bool
show_above_text_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"linkPreviewOptions"
, Key
"is_disabled" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_disabled_
, Key
"url" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
url_
, Key
"force_small_media" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
force_small_media_
, Key
"force_large_media" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
force_large_media_
, Key
"show_above_text" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
show_above_text_
]
defaultLinkPreviewOptions :: LinkPreviewOptions
defaultLinkPreviewOptions :: LinkPreviewOptions
defaultLinkPreviewOptions =
LinkPreviewOptions
{ is_disabled :: Maybe Bool
is_disabled = Maybe Bool
forall a. Maybe a
Nothing
, url :: Maybe Text
url = Maybe Text
forall a. Maybe a
Nothing
, force_small_media :: Maybe Bool
force_small_media = Maybe Bool
forall a. Maybe a
Nothing
, force_large_media :: Maybe Bool
force_large_media = Maybe Bool
forall a. Maybe a
Nothing
, show_above_text :: Maybe Bool
show_above_text = Maybe Bool
forall a. Maybe a
Nothing
}