module TD.Data.SharedUser
(SharedUser(..)) 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
import qualified TD.Data.Photo as Photo
data SharedUser
= SharedUser
{ SharedUser -> Maybe Int
user_id :: Maybe Int
, SharedUser -> Maybe Text
first_name :: Maybe T.Text
, SharedUser -> Maybe Text
last_name :: Maybe T.Text
, SharedUser -> Maybe Text
username :: Maybe T.Text
, SharedUser -> Maybe Photo
photo :: Maybe Photo.Photo
}
deriving (SharedUser -> SharedUser -> Bool
(SharedUser -> SharedUser -> Bool)
-> (SharedUser -> SharedUser -> Bool) -> Eq SharedUser
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SharedUser -> SharedUser -> Bool
== :: SharedUser -> SharedUser -> Bool
$c/= :: SharedUser -> SharedUser -> Bool
/= :: SharedUser -> SharedUser -> Bool
Eq, Int -> SharedUser -> ShowS
[SharedUser] -> ShowS
SharedUser -> String
(Int -> SharedUser -> ShowS)
-> (SharedUser -> String)
-> ([SharedUser] -> ShowS)
-> Show SharedUser
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SharedUser -> ShowS
showsPrec :: Int -> SharedUser -> ShowS
$cshow :: SharedUser -> String
show :: SharedUser -> String
$cshowList :: [SharedUser] -> ShowS
showList :: [SharedUser] -> ShowS
Show)
instance I.ShortShow SharedUser where
shortShow :: SharedUser -> String
shortShow SharedUser
{ user_id :: SharedUser -> Maybe Int
user_id = Maybe Int
user_id_
, first_name :: SharedUser -> Maybe Text
first_name = Maybe Text
first_name_
, last_name :: SharedUser -> Maybe Text
last_name = Maybe Text
last_name_
, username :: SharedUser -> Maybe Text
username = Maybe Text
username_
, photo :: SharedUser -> Maybe Photo
photo = Maybe Photo
photo_
}
= String
"SharedUser"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
, String
"first_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
first_name_
, String
"last_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
last_name_
, String
"username" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
username_
, String
"photo" String -> Maybe Photo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Photo
photo_
]
instance AT.FromJSON SharedUser where
parseJSON :: Value -> Parser SharedUser
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
"sharedUser" -> Value -> Parser SharedUser
parseSharedUser Value
v
String
_ -> Parser SharedUser
forall a. Monoid a => a
mempty
where
parseSharedUser :: A.Value -> AT.Parser SharedUser
parseSharedUser :: Value -> Parser SharedUser
parseSharedUser = String
-> (Object -> Parser SharedUser) -> Value -> Parser SharedUser
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SharedUser" ((Object -> Parser SharedUser) -> Value -> Parser SharedUser)
-> (Object -> Parser SharedUser) -> Value -> Parser SharedUser
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"user_id"
Maybe Text
first_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"first_name"
Maybe Text
last_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"last_name"
Maybe Text
username_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"username"
Maybe Photo
photo_ <- Object
o Object -> Key -> Parser (Maybe Photo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"photo"
SharedUser -> Parser SharedUser
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SharedUser -> Parser SharedUser)
-> SharedUser -> Parser SharedUser
forall a b. (a -> b) -> a -> b
$ SharedUser
{ user_id :: Maybe Int
user_id = Maybe Int
user_id_
, first_name :: Maybe Text
first_name = Maybe Text
first_name_
, last_name :: Maybe Text
last_name = Maybe Text
last_name_
, username :: Maybe Text
username = Maybe Text
username_
, photo :: Maybe Photo
photo = Maybe Photo
photo_
}
parseJSON Value
_ = Parser SharedUser
forall a. Monoid a => a
mempty