module TD.Data.Stories
(Stories(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.Story as Story
data Stories
= Stories
{ Stories -> Maybe Int
total_count :: Maybe Int
, Stories -> Maybe [Story]
stories :: Maybe [Story.Story]
, Stories -> Maybe [Int]
pinned_story_ids :: Maybe [Int]
}
deriving (Stories -> Stories -> Bool
(Stories -> Stories -> Bool)
-> (Stories -> Stories -> Bool) -> Eq Stories
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Stories -> Stories -> Bool
== :: Stories -> Stories -> Bool
$c/= :: Stories -> Stories -> Bool
/= :: Stories -> Stories -> Bool
Eq, Int -> Stories -> ShowS
[Stories] -> ShowS
Stories -> String
(Int -> Stories -> ShowS)
-> (Stories -> String) -> ([Stories] -> ShowS) -> Show Stories
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Stories -> ShowS
showsPrec :: Int -> Stories -> ShowS
$cshow :: Stories -> String
show :: Stories -> String
$cshowList :: [Stories] -> ShowS
showList :: [Stories] -> ShowS
Show)
instance I.ShortShow Stories where
shortShow :: Stories -> String
shortShow Stories
{ total_count :: Stories -> Maybe Int
total_count = Maybe Int
total_count_
, stories :: Stories -> Maybe [Story]
stories = Maybe [Story]
stories_
, pinned_story_ids :: Stories -> Maybe [Int]
pinned_story_ids = Maybe [Int]
pinned_story_ids_
}
= String
"Stories"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"total_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
, String
"stories" String -> Maybe [Story] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Story]
stories_
, String
"pinned_story_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
pinned_story_ids_
]
instance AT.FromJSON Stories where
parseJSON :: Value -> Parser Stories
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
"stories" -> Value -> Parser Stories
parseStories Value
v
String
_ -> Parser Stories
forall a. Monoid a => a
mempty
where
parseStories :: A.Value -> AT.Parser Stories
parseStories :: Value -> Parser Stories
parseStories = String -> (Object -> Parser Stories) -> Value -> Parser Stories
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Stories" ((Object -> Parser Stories) -> Value -> Parser Stories)
-> (Object -> Parser Stories) -> Value -> Parser Stories
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
total_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"total_count"
Maybe [Story]
stories_ <- Object
o Object -> Key -> Parser (Maybe [Story])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"stories"
Maybe [Int]
pinned_story_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"pinned_story_ids"
Stories -> Parser Stories
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Stories -> Parser Stories) -> Stories -> Parser Stories
forall a b. (a -> b) -> a -> b
$ Stories
{ total_count :: Maybe Int
total_count = Maybe Int
total_count_
, stories :: Maybe [Story]
stories = Maybe [Story]
stories_
, pinned_story_ids :: Maybe [Int]
pinned_story_ids = Maybe [Int]
pinned_story_ids_
}
parseJSON Value
_ = Parser Stories
forall a. Monoid a => a
mempty