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