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