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