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