module Text.RSS.Extensions where
import Control.Exception.Safe as Exception
import Data.Conduit
import Data.Maybe
import Data.Proxy
import Data.Singletons
import Data.Singletons.Prelude.Bool
import Data.Singletons.Prelude.Eq
import Data.Singletons.Prelude.List
import Data.Text
import Data.Vinyl.Core
import Data.Vinyl.TypeLevel
import Data.XML.Types
import Debug.Trace
import GHC.Generics
import Text.Atom.Conduit.Parse
import Text.Atom.Types
import Text.Read (readMaybe)
import Text.RSS.Types
import Text.XML.Stream.Parse
import URI.ByteString
class ParseRssExtension a where
parseRssChannelExtension :: MonadThrow m => ConduitM Event o m (RssChannelExtension a)
parseRssItemExtension :: MonadThrow m => ConduitM Event o m (RssItemExtension a)
type ParseRssExtensions (e :: [*]) = (AllConstrained ParseRssExtension e, SingI e)
class RenderRssExtension e where
renderRssChannelExtension :: Monad m => RssChannelExtension e -> Source m Event
renderRssItemExtension :: Monad m => RssItemExtension e -> Source m Event
type RenderRssExtensions (e :: [*]) = (AllConstrained RenderRssExtension e)
parseRssChannelExtensions :: ParseRssExtensions e => MonadThrow m => ConduitM Event o m (RssChannelExtensions e)
parseRssChannelExtensions = f sing where
f :: AllConstrained ParseRssExtension e => MonadThrow m
=> Sing e -> ConduitM Event o m (RssChannelExtensions e)
f SNil = return $ RssChannelExtensions RNil
f (SCons _ es) = fmap RssChannelExtensions $ getZipConduit $ (:&)
<$> ZipConduit parseRssChannelExtension
<*> ZipConduit (rssChannelExtension <$> f es)
parseRssItemExtensions :: ParseRssExtensions e => MonadThrow m => ConduitM Event o m (RssItemExtensions e)
parseRssItemExtensions = f sing where
f :: AllConstrained ParseRssExtension e => MonadThrow m
=> Sing e -> ConduitM Event o m (RssItemExtensions e)
f SNil = return $ RssItemExtensions RNil
f (SCons _ es) = fmap RssItemExtensions $ getZipConduit $ (:&)
<$> ZipConduit parseRssItemExtension
<*> ZipConduit (rssItemExtension <$> f es)
renderRssChannelExtensions :: Monad m => RenderRssExtensions e => RssChannelExtensions e -> Source m Event
renderRssChannelExtensions (RssChannelExtensions RNil) = pure ()
renderRssChannelExtensions (RssChannelExtensions (a :& t)) = do
renderRssChannelExtension a
renderRssChannelExtensions (RssChannelExtensions t)
renderRssItemExtensions :: Monad m => RenderRssExtensions e => RssItemExtensions e -> Source m Event
renderRssItemExtensions (RssItemExtensions RNil) = pure ()
renderRssItemExtensions (RssItemExtensions (a :& t)) = do
renderRssItemExtension a
renderRssItemExtensions (RssItemExtensions t)