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