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